2 * Copyright 2014-2015, Haiku, Inc.
3 * Distributed under the terms of the MIT License.
9 #include <Referenceable.h>
11 #include "agg_clipped_alpha_mask.h"
12 #include "ServerPicture.h"
14 #include "DrawState.h"
15 #include "drawing/Painter/defines.h"
28 // #pragma mark - AlphaMask
31 class AlphaMask
: public BReferenceable
{
33 AlphaMask(AlphaMask
* previousMask
,
35 AlphaMask(AlphaMask
* previousMask
,
37 AlphaMask(uint8 backgroundOpacity
);
40 IntPoint
SetCanvasGeometry(IntPoint origin
,
43 scanline_unpacked_masked_type
* Scanline()
44 { return &fScanline
; }
46 agg::clipped_alpha_mask
* Mask()
49 size_t BitmapSize() const;
52 ServerBitmap
* _CreateTemporaryBitmap(BRect bounds
) const;
54 void _SetNoClipping();
55 const IntRect
& _PreviousMaskBounds() const;
56 virtual void _AddToCache() = 0;
59 virtual ServerBitmap
* _RenderSource(const IntRect
& canvasBounds
) = 0;
60 virtual IntPoint
_Offset() = 0;
62 void _AttachMaskToBuffer();
65 BReference
<AlphaMask
> fPreviousMask
;
67 bool fClippedToCanvas
;
71 friend class AlphaMaskCache
;
73 IntPoint fCanvasOrigin
;
74 IntRect fCanvasBounds
;
76 uint8 fBackgroundOpacity
;
80 uint32 fIndirectCacheReferences
;
81 // number of times this mask has been
82 // seen as "previous mask" of another
83 // one in the cache, without being
84 // in the cache itself
87 agg::rendering_buffer fBuffer
;
88 agg::clipped_alpha_mask fMask
;
89 scanline_unpacked_masked_type fScanline
;
93 class UniformAlphaMask
: public AlphaMask
{
95 UniformAlphaMask(uint8 opacity
);
98 virtual ServerBitmap
* _RenderSource(const IntRect
& canvasBounds
);
99 virtual IntPoint
_Offset();
100 virtual void _AddToCache();
104 // #pragma mark - VectorAlphaMask
107 template<class VectorMaskType
>
108 class VectorAlphaMask
: public AlphaMask
{
110 VectorAlphaMask(AlphaMask
* previousMask
,
111 BPoint where
, bool inverse
);
112 VectorAlphaMask(AlphaMask
* previousMask
,
113 VectorAlphaMask
* other
);
116 virtual ServerBitmap
* _RenderSource(const IntRect
& canvasBounds
);
117 virtual IntPoint
_Offset();
124 // #pragma mark - PictureAlphaMask
127 class PictureAlphaMask
: public VectorAlphaMask
<PictureAlphaMask
> {
129 PictureAlphaMask(AlphaMask
* previousMask
,
130 ServerPicture
* picture
,
131 const DrawState
& drawState
, BPoint where
,
133 virtual ~PictureAlphaMask();
135 void DrawVectors(Canvas
* canvas
);
136 BRect
DetermineBoundingBox() const;
137 const DrawState
& GetDrawState() const;
140 virtual void _AddToCache();
143 BReference
<ServerPicture
> fPicture
;
144 DrawState
* fDrawState
;
148 // #pragma mark - ShapeAlphaMask
151 class ShapeAlphaMask
: public VectorAlphaMask
<ShapeAlphaMask
> {
153 ShapeAlphaMask(AlphaMask
* previousMask
,
154 const shape_data
& shape
,
155 BPoint where
, bool inverse
);
156 ShapeAlphaMask(AlphaMask
* previousMask
,
157 ShapeAlphaMask
* other
);
160 virtual ~ShapeAlphaMask();
162 static ShapeAlphaMask
* Create(AlphaMask
* previousMask
,
163 const shape_data
& shape
,
164 BPoint where
, bool inverse
);
166 void DrawVectors(Canvas
* canvas
);
167 BRect
DetermineBoundingBox() const;
168 const DrawState
& GetDrawState() const;
171 virtual void _AddToCache();
174 friend class AlphaMaskCache
;
178 static DrawState
* fDrawState
;
182 #endif // ALPHA_MASK_H