vfs: check userland buffers before reading them.
[haiku.git] / src / servers / app / drawing / AlphaMask.h
blob9156c235824547c6f59ea35be0fad5e2b33ad3e2
1 /*
2 * Copyright 2014-2015, Haiku, Inc.
3 * Distributed under the terms of the MIT License.
4 */
6 #ifndef ALPHA_MASK_H
7 #define ALPHA_MASK_H
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"
16 #include "IntRect.h"
18 #include <Locker.h>
21 class BShape;
22 class ServerBitmap;
23 class ServerPicture;
24 class shape_data;
25 class UtilityBitmap;
28 // #pragma mark - AlphaMask
31 class AlphaMask : public BReferenceable {
32 public:
33 AlphaMask(AlphaMask* previousMask,
34 bool inverse);
35 AlphaMask(AlphaMask* previousMask,
36 AlphaMask* other);
37 AlphaMask(uint8 backgroundOpacity);
38 virtual ~AlphaMask();
40 IntPoint SetCanvasGeometry(IntPoint origin,
41 IntRect bounds);
43 scanline_unpacked_masked_type* Scanline()
44 { return &fScanline; }
46 agg::clipped_alpha_mask* Mask()
47 { return &fMask; }
49 size_t BitmapSize() const;
51 protected:
52 ServerBitmap* _CreateTemporaryBitmap(BRect bounds) const;
53 void _Generate();
54 void _SetNoClipping();
55 const IntRect& _PreviousMaskBounds() const;
56 virtual void _AddToCache() = 0;
58 private:
59 virtual ServerBitmap* _RenderSource(const IntRect& canvasBounds) = 0;
60 virtual IntPoint _Offset() = 0;
62 void _AttachMaskToBuffer();
64 protected:
65 BReference<AlphaMask> fPreviousMask;
66 IntRect fBounds;
67 bool fClippedToCanvas;
68 BLocker fLock;
70 private:
71 friend class AlphaMaskCache;
73 IntPoint fCanvasOrigin;
74 IntRect fCanvasBounds;
75 const bool fInverse;
76 uint8 fBackgroundOpacity;
78 int32 fNextMaskCount;
79 bool fInCache;
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
86 UtilityBitmap* fBits;
87 agg::rendering_buffer fBuffer;
88 agg::clipped_alpha_mask fMask;
89 scanline_unpacked_masked_type fScanline;
93 class UniformAlphaMask : public AlphaMask {
94 public:
95 UniformAlphaMask(uint8 opacity);
97 private:
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 {
109 public:
110 VectorAlphaMask(AlphaMask* previousMask,
111 BPoint where, bool inverse);
112 VectorAlphaMask(AlphaMask* previousMask,
113 VectorAlphaMask* other);
115 private:
116 virtual ServerBitmap* _RenderSource(const IntRect& canvasBounds);
117 virtual IntPoint _Offset();
119 protected:
120 BPoint fWhere;
124 // #pragma mark - PictureAlphaMask
127 class PictureAlphaMask : public VectorAlphaMask<PictureAlphaMask> {
128 public:
129 PictureAlphaMask(AlphaMask* previousMask,
130 ServerPicture* picture,
131 const DrawState& drawState, BPoint where,
132 bool inverse);
133 virtual ~PictureAlphaMask();
135 void DrawVectors(Canvas* canvas);
136 BRect DetermineBoundingBox() const;
137 const DrawState& GetDrawState() const;
139 private:
140 virtual void _AddToCache();
142 private:
143 BReference<ServerPicture> fPicture;
144 DrawState* fDrawState;
148 // #pragma mark - ShapeAlphaMask
151 class ShapeAlphaMask : public VectorAlphaMask<ShapeAlphaMask> {
152 private:
153 ShapeAlphaMask(AlphaMask* previousMask,
154 const shape_data& shape,
155 BPoint where, bool inverse);
156 ShapeAlphaMask(AlphaMask* previousMask,
157 ShapeAlphaMask* other);
159 public:
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;
170 private:
171 virtual void _AddToCache();
173 private:
174 friend class AlphaMaskCache;
176 shape_data* fShape;
177 BRect fShapeBounds;
178 static DrawState* fDrawState;
182 #endif // ALPHA_MASK_H