Chromium Code Reviews| 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: |
|
robertphillips
2014/07/21 16:07:19
I don't think you need the 'fBlitMemory(0)' anymor
krajcevski
2014/07/21 16:42:08
Done.
I stopped reading at the explicit declarati
| |
| 28 SkBlitter() : fBlitMemory(0) { } | |
| 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 virtual void* allocBlitMemory(size_t sz) { | |
| 87 return fBlitMemory.reset(sz, SkAutoMalloc::kReuse_OnShrink); | |
| 88 } | |
| 89 | |
| 79 ///@name non-virtual helpers | 90 ///@name non-virtual helpers |
| 80 void blitMaskRegion(const SkMask& mask, const SkRegion& clip); | 91 void blitMaskRegion(const SkMask& mask, const SkRegion& clip); |
| 81 void blitRectRegion(const SkIRect& rect, const SkRegion& clip); | 92 void blitRectRegion(const SkIRect& rect, const SkRegion& clip); |
| 82 void blitRegion(const SkRegion& clip); | 93 void blitRegion(const SkRegion& clip); |
| 83 ///@} | 94 ///@} |
| 84 | 95 |
| 85 /** @name Factories | 96 /** @name Factories |
| 86 Return the correct blitter to use given the specified context. | 97 Return the correct blitter to use given the specified context. |
| 87 */ | 98 */ |
| 88 static SkBlitter* Choose(const SkBitmap& device, | 99 static SkBlitter* Choose(const SkBitmap& device, |
| 89 const SkMatrix& matrix, | 100 const SkMatrix& matrix, |
| 90 const SkPaint& paint, | 101 const SkPaint& paint, |
| 91 SkTBlitterAllocator*, | 102 SkTBlitterAllocator*, |
| 92 bool drawCoverage = false); | 103 bool drawCoverage = false); |
| 93 | 104 |
| 94 static SkBlitter* ChooseSprite(const SkBitmap& device, | 105 static SkBlitter* ChooseSprite(const SkBitmap& device, |
| 95 const SkPaint&, | 106 const SkPaint&, |
| 96 const SkBitmap& src, | 107 const SkBitmap& src, |
| 97 int left, int top, | 108 int left, int top, |
| 98 SkTBlitterAllocator*); | 109 SkTBlitterAllocator*); |
| 99 ///@} | 110 ///@} |
| 100 | 111 |
| 112 protected: | |
| 113 | |
| 114 SkAutoMalloc fBlitMemory; | |
| 115 | |
| 101 private: | 116 private: |
| 102 }; | 117 }; |
| 103 | 118 |
| 104 /** This blitter silently never draws anything. | 119 /** This blitter silently never draws anything. |
| 105 */ | 120 */ |
| 106 class SkNullBlitter : public SkBlitter { | 121 class SkNullBlitter : public SkBlitter { |
| 107 public: | 122 public: |
| 108 virtual void blitH(int x, int y, int width) SK_OVERRIDE; | 123 virtual void blitH(int x, int y, int width) SK_OVERRIDE; |
| 109 virtual void blitAntiH(int x, int y, const SkAlpha[], | 124 virtual void blitAntiH(int x, int y, const SkAlpha[], |
| 110 const int16_t runs[]) SK_OVERRIDE; | 125 const int16_t runs[]) SK_OVERRIDE; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 130 virtual void blitH(int x, int y, int width) SK_OVERRIDE; | 145 virtual void blitH(int x, int y, int width) SK_OVERRIDE; |
| 131 virtual void blitAntiH(int x, int y, const SkAlpha[], | 146 virtual void blitAntiH(int x, int y, const SkAlpha[], |
| 132 const int16_t runs[]) SK_OVERRIDE; | 147 const int16_t runs[]) SK_OVERRIDE; |
| 133 virtual void blitV(int x, int y, int height, SkAlpha alpha) SK_OVERRIDE; | 148 virtual void blitV(int x, int y, int height, SkAlpha alpha) SK_OVERRIDE; |
| 134 virtual void blitRect(int x, int y, int width, int height) SK_OVERRIDE; | 149 virtual void blitRect(int x, int y, int width, int height) SK_OVERRIDE; |
| 135 virtual void blitAntiRect(int x, int y, int width, int height, | 150 virtual void blitAntiRect(int x, int y, int width, int height, |
| 136 SkAlpha leftAlpha, SkAlpha rightAlpha) SK_OVERRIDE; | 151 SkAlpha leftAlpha, SkAlpha rightAlpha) SK_OVERRIDE; |
| 137 virtual void blitMask(const SkMask&, const SkIRect& clip) SK_OVERRIDE; | 152 virtual void blitMask(const SkMask&, const SkIRect& clip) SK_OVERRIDE; |
| 138 virtual const SkBitmap* justAnOpaqueColor(uint32_t* value) SK_OVERRIDE; | 153 virtual const SkBitmap* justAnOpaqueColor(uint32_t* value) SK_OVERRIDE; |
| 139 | 154 |
| 155 virtual void* allocBlitMemory(size_t sz) SK_OVERRIDE { | |
| 156 return fBlitter->allocBlitMemory(sz); | |
| 157 } | |
| 158 | |
| 140 private: | 159 private: |
| 141 SkBlitter* fBlitter; | 160 SkBlitter* fBlitter; |
| 142 SkIRect fClipRect; | 161 SkIRect fClipRect; |
| 143 }; | 162 }; |
| 144 | 163 |
| 145 /** Wraps another (real) blitter, and ensures that the real blitter is only | 164 /** Wraps another (real) blitter, and ensures that the real blitter is only |
| 146 called with coordinates that have been clipped by the specified clipRgn. | 165 called with coordinates that have been clipped by the specified clipRgn. |
| 147 This means the caller need not perform the clipping ahead of time. | 166 This means the caller need not perform the clipping ahead of time. |
| 148 */ | 167 */ |
| 149 class SkRgnClipBlitter : public SkBlitter { | 168 class SkRgnClipBlitter : public SkBlitter { |
| 150 public: | 169 public: |
| 151 void init(SkBlitter* blitter, const SkRegion* clipRgn) { | 170 void init(SkBlitter* blitter, const SkRegion* clipRgn) { |
| 152 SkASSERT(clipRgn && !clipRgn->isEmpty()); | 171 SkASSERT(clipRgn && !clipRgn->isEmpty()); |
| 153 fBlitter = blitter; | 172 fBlitter = blitter; |
| 154 fRgn = clipRgn; | 173 fRgn = clipRgn; |
| 155 } | 174 } |
| 156 | 175 |
| 157 virtual void blitH(int x, int y, int width) SK_OVERRIDE; | 176 virtual void blitH(int x, int y, int width) SK_OVERRIDE; |
| 158 virtual void blitAntiH(int x, int y, const SkAlpha[], | 177 virtual void blitAntiH(int x, int y, const SkAlpha[], |
| 159 const int16_t runs[]) SK_OVERRIDE; | 178 const int16_t runs[]) SK_OVERRIDE; |
| 160 virtual void blitV(int x, int y, int height, SkAlpha alpha) SK_OVERRIDE; | 179 virtual void blitV(int x, int y, int height, SkAlpha alpha) SK_OVERRIDE; |
| 161 virtual void blitRect(int x, int y, int width, int height) SK_OVERRIDE; | 180 virtual void blitRect(int x, int y, int width, int height) SK_OVERRIDE; |
| 162 virtual void blitAntiRect(int x, int y, int width, int height, | 181 virtual void blitAntiRect(int x, int y, int width, int height, |
| 163 SkAlpha leftAlpha, SkAlpha rightAlpha) SK_OVERRIDE; | 182 SkAlpha leftAlpha, SkAlpha rightAlpha) SK_OVERRIDE; |
| 164 virtual void blitMask(const SkMask&, const SkIRect& clip) SK_OVERRIDE; | 183 virtual void blitMask(const SkMask&, const SkIRect& clip) SK_OVERRIDE; |
| 165 virtual const SkBitmap* justAnOpaqueColor(uint32_t* value) SK_OVERRIDE; | 184 virtual const SkBitmap* justAnOpaqueColor(uint32_t* value) SK_OVERRIDE; |
| 166 | 185 |
| 186 virtual void* allocBlitMemory(size_t sz) SK_OVERRIDE { | |
| 187 return fBlitter->allocBlitMemory(sz); | |
| 188 } | |
| 189 | |
| 167 private: | 190 private: |
| 168 SkBlitter* fBlitter; | 191 SkBlitter* fBlitter; |
| 169 const SkRegion* fRgn; | 192 const SkRegion* fRgn; |
| 170 }; | 193 }; |
| 171 | 194 |
| 172 /** Factory to set up the appropriate most-efficient wrapper blitter | 195 /** Factory to set up the appropriate most-efficient wrapper blitter |
| 173 to apply a clip. Returns a pointer to a member, so lifetime must | 196 to apply a clip. Returns a pointer to a member, so lifetime must |
| 174 be managed carefully. | 197 be managed carefully. |
| 175 */ | 198 */ |
| 176 class SkBlitterClipper { | 199 class SkBlitterClipper { |
| 177 public: | 200 public: |
| 178 SkBlitter* apply(SkBlitter* blitter, const SkRegion* clip, | 201 SkBlitter* apply(SkBlitter* blitter, const SkRegion* clip, |
| 179 const SkIRect* bounds = NULL); | 202 const SkIRect* bounds = NULL); |
| 180 | 203 |
| 181 private: | 204 private: |
| 182 SkNullBlitter fNullBlitter; | 205 SkNullBlitter fNullBlitter; |
| 183 SkRectClipBlitter fRectBlitter; | 206 SkRectClipBlitter fRectBlitter; |
| 184 SkRgnClipBlitter fRgnBlitter; | 207 SkRgnClipBlitter fRgnBlitter; |
| 185 }; | 208 }; |
| 186 | 209 |
| 187 #endif | 210 #endif |
| OLD | NEW |