OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #ifndef SkBlitter_DEFINED | 10 #ifndef SkBlitter_DEFINED |
11 #define SkBlitter_DEFINED | 11 #define SkBlitter_DEFINED |
12 | 12 |
13 #include "SkBitmap.h" | 13 #include "SkBitmap.h" |
14 #include "SkBitmapProcShader.h" | 14 #include "SkBitmapProcShader.h" |
15 #include "SkMask.h" | 15 #include "SkMask.h" |
16 #include "SkMatrix.h" | 16 #include "SkMatrix.h" |
17 #include "SkPaint.h" | 17 #include "SkPaint.h" |
18 #include "SkRefCnt.h" | 18 #include "SkRefCnt.h" |
19 #include "SkRegion.h" | 19 #include "SkRegion.h" |
20 #include "SkShader.h" | 20 #include "SkShader.h" |
21 #include "SkSmallAllocator.h" | 21 #include "SkSmallAllocator.h" |
22 | 22 |
23 /** SkBlitter and its subclasses are responsible for actually writing pixels | 23 /** SkBlitter and its subclasses are responsible for actually writing pixels |
24 into memory. Besides efficiency, they handle clipping and antialiasing. | 24 into memory. Besides efficiency, they handle clipping and antialiasing. |
25 */ | 25 */ |
26 class SkBlitter { | 26 class SkBlitter { |
27 public: | 27 public: |
| 28 SkBlitter() : fBlitMemory(NULL) { } |
28 virtual ~SkBlitter(); | 29 virtual ~SkBlitter(); |
29 | 30 |
30 /// Blit a horizontal run of one or more pixels. | 31 /// Blit a horizontal run of one or more pixels. |
31 virtual void blitH(int x, int y, int width); | 32 virtual void blitH(int x, int y, int width); |
32 /// Blit a horizontal run of antialiased pixels; runs[] is a *sparse* | 33 /// Blit a horizontal run of antialiased pixels; runs[] is a *sparse* |
33 /// zero-terminated run-length encoding of spans of constant alpha values. | 34 /// zero-terminated run-length encoding of spans of constant alpha values. |
34 virtual void blitAntiH(int x, int y, const SkAlpha antialias[], | 35 virtual void blitAntiH(int x, int y, const SkAlpha antialias[], |
35 const int16_t runs[]); | 36 const int16_t runs[]); |
36 | 37 |
37 /// Blit a vertical run of pixels with a constant alpha value. | 38 /// Blit a vertical run of pixels with a constant alpha value. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 virtual SkShader::Context* getShaderContext() const; | 70 virtual SkShader::Context* getShaderContext() const; |
70 | 71 |
71 /** | 72 /** |
72 * Special methods for blitters that can blit more than one row at a time. | 73 * Special methods for blitters that can blit more than one row at a time. |
73 * This function returns the number of rows that this blitter could optimall
y | 74 * This function returns the number of rows that this blitter could optimall
y |
74 * process at a time. It is still required to support blitting one scanline | 75 * process at a time. It is still required to support blitting one scanline |
75 * at a time. | 76 * at a time. |
76 */ | 77 */ |
77 virtual int requestRowsPreserved() const { return 1; } | 78 virtual int requestRowsPreserved() const { return 1; } |
78 | 79 |
| 80 /** |
| 81 * This function allocates memory for the blitter that the blitter then owns
. |
| 82 * The memory can be used by the calling function at will, but it will be |
| 83 * released when the blitter's destructor is called. This function returns |
| 84 * NULL if no persistent memory is needed by the blitter. |
| 85 */ |
| 86 void* allocBlitMemory(size_t); |
| 87 |
79 ///@name non-virtual helpers | 88 ///@name non-virtual helpers |
80 void blitMaskRegion(const SkMask& mask, const SkRegion& clip); | 89 void blitMaskRegion(const SkMask& mask, const SkRegion& clip); |
81 void blitRectRegion(const SkIRect& rect, const SkRegion& clip); | 90 void blitRectRegion(const SkIRect& rect, const SkRegion& clip); |
82 void blitRegion(const SkRegion& clip); | 91 void blitRegion(const SkRegion& clip); |
83 ///@} | 92 ///@} |
84 | 93 |
85 /** @name Factories | 94 /** @name Factories |
86 Return the correct blitter to use given the specified context. | 95 Return the correct blitter to use given the specified context. |
87 */ | 96 */ |
88 static SkBlitter* Choose(const SkBitmap& device, | 97 static SkBlitter* Choose(const SkBitmap& device, |
89 const SkMatrix& matrix, | 98 const SkMatrix& matrix, |
90 const SkPaint& paint, | 99 const SkPaint& paint, |
91 SkTBlitterAllocator*, | 100 SkTBlitterAllocator*, |
92 bool drawCoverage = false); | 101 bool drawCoverage = false); |
93 | 102 |
94 static SkBlitter* ChooseSprite(const SkBitmap& device, | 103 static SkBlitter* ChooseSprite(const SkBitmap& device, |
95 const SkPaint&, | 104 const SkPaint&, |
96 const SkBitmap& src, | 105 const SkBitmap& src, |
97 int left, int top, | 106 int left, int top, |
98 SkTBlitterAllocator*); | 107 SkTBlitterAllocator*); |
99 ///@} | 108 ///@} |
100 | 109 |
| 110 protected: |
| 111 |
| 112 void* fBlitMemory; |
| 113 |
101 private: | 114 private: |
102 }; | 115 }; |
103 | 116 |
104 /** This blitter silently never draws anything. | 117 /** This blitter silently never draws anything. |
105 */ | 118 */ |
106 class SkNullBlitter : public SkBlitter { | 119 class SkNullBlitter : public SkBlitter { |
107 public: | 120 public: |
108 virtual void blitH(int x, int y, int width) SK_OVERRIDE; | 121 virtual void blitH(int x, int y, int width) SK_OVERRIDE; |
109 virtual void blitAntiH(int x, int y, const SkAlpha[], | 122 virtual void blitAntiH(int x, int y, const SkAlpha[], |
110 const int16_t runs[]) SK_OVERRIDE; | 123 const int16_t runs[]) SK_OVERRIDE; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 SkBlitter* apply(SkBlitter* blitter, const SkRegion* clip, | 191 SkBlitter* apply(SkBlitter* blitter, const SkRegion* clip, |
179 const SkIRect* bounds = NULL); | 192 const SkIRect* bounds = NULL); |
180 | 193 |
181 private: | 194 private: |
182 SkNullBlitter fNullBlitter; | 195 SkNullBlitter fNullBlitter; |
183 SkRectClipBlitter fRectBlitter; | 196 SkRectClipBlitter fRectBlitter; |
184 SkRgnClipBlitter fRgnBlitter; | 197 SkRgnClipBlitter fRgnBlitter; |
185 }; | 198 }; |
186 | 199 |
187 #endif | 200 #endif |
OLD | NEW |