CairoGraphicsContext.st
changeset 60 9bc47734215d
parent 57 2c9a342e1f2a
child 62 a1280a796155
--- a/CairoGraphicsContext.st	Thu Mar 03 12:08:14 2016 +0000
+++ b/CairoGraphicsContext.st	Thu Mar 03 23:57:57 2016 +0000
@@ -4,25 +4,12 @@
 
 DeviceGraphicsContext subclass:#CairoGraphicsContext
 	instanceVariableNames:'cr'
-	classVariableNames:'Lobby'
+	classVariableNames:''
 	poolDictionaries:'Cairo::FontSlant Cairo::FontWeight Cairo::Format Cairo::Status
 		Cairo::Antialias'
 	category:'Cairo-Compatibility'
 !
 
-
-!CairoGraphicsContext class methodsFor:'initialization'!
-
-initialize
-    "Invoked at system start or when the class is dynamically loaded."
-
-    "/ please change as required (and remove this comment)
-
-    Lobby := Registry new.
-
-    "Modified: / 18-02-2016 / 22:51:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-! !
-
 !CairoGraphicsContext class methodsFor:'instance creation'!
 
 onDeviceGraphicsContext: dGC
@@ -785,26 +772,10 @@
 !CairoGraphicsContext methodsFor:'finalization'!
 
 executor
-    ^ super executor
-    "/^ self shallowCopy
+    ^ CairoGraphicsContextHandle basicNew setDevice:device id:drawableId gcId:gcId parentId: parentId type: drawableType cr: cr
 
     "Created: / 12-02-2016 / 17:04:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-finalization
-    self destroy
-
-    "Created: / 09-01-2015 / 10:20:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-finalizationLobby
-    "answer a Registry used for finalization.
-     Use a generic Registry for any object.
-     Subclasses using their own Registry should redefine this"
-
-    ^ Lobby
-
-    "Created: / 09-01-2015 / 10:20:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 04-03-2016 / 00:09:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !CairoGraphicsContext methodsFor:'initialization & release'!
@@ -823,10 +794,30 @@
      Since we do not need a gc-object for the drawable until something is
      really drawn, none is created up to the first draw.
      This method is sent, when the first drawing happens"      
-    super createGC.
-    self createCR
+
+    "/ Here, we cannot simply do
+    "/ 
+    "/   super createGC.
+    "/   self createCR.
+    "/ 
+    "/ As we need to tell the finalization lobby to register change
+    "/ after we create Cairo context. Of course, we could just call
+    "/ 
+    "/   Lobby registerChange: self
+    "/ 
+    "/ in createCR, but then we'd call it twice which is not what we want.
+    "/ Therefore this ugly code duplication...sigh.
+
+    drawableType == #window ifTrue:[
+        gcId := device gcFor:drawableId.
+    ] ifFalse:[
+        gcId := device gcForBitmap:drawableId.
+    ].
+    self createCR.
+    Lobby registerChange:self.
 
     "Created: / 12-02-2016 / 16:58:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 03-03-2016 / 23:28:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 destroyCR
@@ -850,10 +841,14 @@
 !
 
 destroyGC
+    drawableId notNil ifTrue:[
+        Logger debug: 'Destroying GC/CR for drawable %1' with: drawableId.
+    ].
     self destroyCR.
     super destroyGC
 
     "Created: / 12-02-2016 / 17:01:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 03-03-2016 / 23:52:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 initCR
@@ -861,6 +856,7 @@
 
     cr isNil ifTrue:[ 
         self createCR.
+        Lobby registerChange: self.
     ].
     cr antialias: CAIRO_ANTIALIAS_NONE.
     cr lineWidth: (lineWidth == 0 ifTrue:[ 1 ] ifFalse:[ lineWidth ]).
@@ -876,7 +872,7 @@
     self basicFont: f.
 
     "Created: / 18-02-2016 / 22:48:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 01-03-2016 / 13:12:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 03-03-2016 / 23:28:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 initGC
@@ -925,7 +921,4 @@
 
 version_HG
     ^ '$Changeset: <not expanded> $'
-! !
-
-
-CairoGraphicsContext initialize!
+! !
\ No newline at end of file