Skip to content

Commit

Permalink
Adding a cache for paints and another for stroke paints.
Browse files Browse the repository at this point in the history
  • Loading branch information
tesonep committed Sep 1, 2019
1 parent c289f1c commit 8166b74
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
35 changes: 33 additions & 2 deletions src/Athens-Core/AthensCanvas.class.st
Expand Up @@ -17,9 +17,20 @@ Class {
'fontRenderer',
'paintMode'
],
#classVars : [
'PaintCache',
'StrokePaintCache'
],
#category : #'Athens-Core-Base'
}

{ #category : #private }
AthensCanvas class >> initialize [

self reset.
SessionManager default registerGuiClassNamed: self name atPriority: 20
]

{ #category : #private }
AthensCanvas class >> new [
"use #on: instead"
Expand All @@ -31,6 +42,26 @@ AthensCanvas class >> on: aSurface [
^ self basicNew initializeWithSurface: aSurface
]

{ #category : #private }
AthensCanvas class >> reset [

StrokePaintCache := LRUCache new maximumWeight: 100.
PaintCache := LRUCache new maximumWeight: 100.

]

{ #category : #private }
AthensCanvas class >> shutDown: isImageQuitting [

self reset
]

{ #category : #private }
AthensCanvas class >> startUp: isImageStarting [

self reset
]

{ #category : #caching }
AthensCanvas >> cacheAt: anObject ifAbsentPut: aBlock [

Expand Down Expand Up @@ -176,7 +207,7 @@ AthensCanvas >> setFont: aFont [
AthensCanvas >> setPaint: aPaint [
"set the current paint of receiver"
paint = aPaint ifTrue:[ ^ paint ].
paint := aPaint asAthensPaintOn: self.
paint := PaintCache at: aPaint ifAbsentPut: [ aPaint asAthensPaintOn: self ].
^ paint.
]

Expand All @@ -189,7 +220,7 @@ AthensCanvas >> setShape: anObject [
{ #category : #paint }
AthensCanvas >> setStrokePaint: aPaint [
"use paint as stroke paint, note conversion to #asStrokePaintOn:"
paint := (aPaint asAthensPaintOn: self) asStrokePaintOn: self.
paint := StrokePaintCache at: aPaint ifAbsentPut: [ (aPaint asAthensPaintOn: self) asStrokePaintOn: self ].
^ paint
]

Expand Down
8 changes: 8 additions & 0 deletions src/BaselineOfAthens/BaselineOfAthens.class.st
Expand Up @@ -16,6 +16,8 @@ BaselineOfAthens >> baseline: spec [
spec
for: #common
do: [
spec postLoadDoIt: #'postload:package:'.

"Inter packages dependencies are now added but it is missing some dependencies on other projects such as Morphic for Athens-Morphic"
"Dependencies"
self
Expand Down Expand Up @@ -45,6 +47,12 @@ BaselineOfAthens >> display: spec [
spec baseline: 'Display' with: [ spec repository: self repository ]
]

{ #category : #baseline }
BaselineOfAthens >> postload: loader package: packageSpec [

AthensCanvas initialize.
]

{ #category : #accessing }
BaselineOfAthens >> repository [
^ self packageRepositoryURL
Expand Down

0 comments on commit 8166b74

Please sign in to comment.