Dillo v3.1.1-98-g318d1f14
Loading...
Searching...
No Matches
dw_imgbuf_mem_test.cc
Go to the documentation of this file.
1/*
2 * Dillo Widget
3 *
4 * Copyright 2005-2007 Sebastian Geerken <sgeerken@dillo.org>
5 * Copyright 2023 Rodrigo Arias Mallo <rodarima@gmail.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include "dw/core.hh"
22#include "dw/fltkcore.hh"
23
24using namespace lout::signal;
25using namespace dw::core;
26using namespace dw::fltk;
27
28void solution1 ()
29{
32
33 Imgbuf *rootbuf = layout->createImgbuf (Imgbuf::RGB, 100, 100, 1);
34 rootbuf->ref (); // Extra reference by the dicache.
35 printf ("=== Can be deleted? %s.\n",
36 rootbuf->lastReference () ? "Yes" : "No");
37 Imgbuf *scaledbuf = rootbuf->getScaledBuf (50, 50);
38 printf ("=== Can be deleted? %s.\n",
39 rootbuf->lastReference () ? "Yes" : "No");
40 rootbuf->unref ();
41 printf ("=== Can be deleted? %s.\n",
42 rootbuf->lastReference () ? "Yes" : "No");
43 scaledbuf->unref ();
44 printf ("=== Can be deleted? %s.\n",
45 rootbuf->lastReference () ? "Yes" : "No");
46 rootbuf->unref (); // Extra reference by the dicache.
47
48 delete layout;
49}
50
51void solution2 ()
52{
55
56 Imgbuf *rootbuf = layout->createImgbuf (Imgbuf::RGB, 100, 100, 1);
57 rootbuf->setDeleteOnUnref (false);
58 printf ("=== Can be deleted? %s.\n",
59 !rootbuf->isReferred () ? "Yes" : "No");
60 Imgbuf *scaledbuf = rootbuf->getScaledBuf (50, 50);
61 printf ("=== Can be deleted? %s.\n",
62 !rootbuf->isReferred () ? "Yes" : "No");
63 rootbuf->unref ();
64 printf ("=== Can be deleted? %s.\n",
65 !rootbuf->isReferred () ? "Yes" : "No");
66 scaledbuf->unref ();
67 printf ("=== Can be deleted? %s.\n",
68 !rootbuf->isReferred () ? "Yes" : "No");
69 delete rootbuf;
70
71 delete layout;
72}
73
74class RootbufDeletionReceiver: public ObservedObject::DeletionReceiver
75{
76 void deleted (ObservedObject *object);
77};
78
79void RootbufDeletionReceiver::deleted (ObservedObject *object)
80{
81 printf ("=== Is deleted now.\n");
82 delete this;
83}
84
85void solution3 ()
86{
89
90 Imgbuf *rootbuf = layout->createImgbuf (Imgbuf::RGB, 100, 100, 1);
91 rootbuf->connectDeletion (new RootbufDeletionReceiver ());
92 Imgbuf *scaledbuf = rootbuf->getScaledBuf (50, 50);
93 rootbuf->unref ();
94 scaledbuf->unref ();
95
96 delete layout;
97}
98
99int main (int argc, char **argv)
100{
101 printf ("========== SOLUTION 1 ==========\n");
102 solution1 ();
103 printf ("========== SOLUTION 2 ==========\n");
104 solution2 ();
105 printf ("========== SOLUTION 3 ==========\n");
106 solution3 ();
107
108 return 0;
109}
int main(void)
Definition bookmarks.c:1613
The platform independent interface for image buffers.
Definition imgbuf.hh:162
virtual void ref()=0
virtual Imgbuf * getScaledBuf(int width, int height)=0
virtual void setDeleteOnUnref(bool deleteOnUnref)=0
virtual void unref()=0
virtual bool isReferred()=0
virtual bool lastReference()=0
The central class for managing and drawing a widget tree.
Definition layout.hh:17
Imgbuf * createImgbuf(Imgbuf::Type type, int width, int height, double gamma)
Definition layout.hh:410
virtual void deleted(ObservedObject *object)=0
An observed object has a signal emitter, which tells the receivers, when the object is deleted.
Definition signal.hh:275
void connectDeletion(DeletionReceiver *receiver)
Definition signal.hh:302
static Layout * layout
static FltkPlatform * platform
void solution2()
void solution3()
void solution1()
The core of Dw is defined in this namespace.
Definition core.hh:23
This namespace contains FLTK implementations of Dw interfaces.
This namespace provides base classes to define signals.
Definition signal.cc:25