OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkTextureCompressor_Blitter_DEFINED | 8 #ifndef SkTextureCompressor_Blitter_DEFINED |
9 #define SkTextureCompressor_Blitter_DEFINED | 9 #define SkTextureCompressor_Blitter_DEFINED |
10 | 10 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 , fHeight(height) | 78 , fHeight(height) |
79 , fBuffer(compressedBuffer) | 79 , fBuffer(compressedBuffer) |
80 { | 80 { |
81 SkASSERT((width % BlockDim) == 0); | 81 SkASSERT((width % BlockDim) == 0); |
82 SkASSERT((height % BlockDim) == 0); | 82 SkASSERT((height % BlockDim) == 0); |
83 } | 83 } |
84 | 84 |
85 virtual ~SkTCompressedAlphaBlitter() { this->flushRuns(); } | 85 virtual ~SkTCompressedAlphaBlitter() { this->flushRuns(); } |
86 | 86 |
87 // Blit a horizontal run of one or more pixels. | 87 // Blit a horizontal run of one or more pixels. |
88 void blitH(int x, int y, int width) SK_OVERRIDE { | 88 void blitH(int x, int y, int width) override { |
89 // This function is intended to be called from any standard RGB | 89 // This function is intended to be called from any standard RGB |
90 // buffer, so we should never encounter it. However, if some code | 90 // buffer, so we should never encounter it. However, if some code |
91 // path does end up here, then this needs to be investigated. | 91 // path does end up here, then this needs to be investigated. |
92 SkFAIL("Not implemented!"); | 92 SkFAIL("Not implemented!"); |
93 } | 93 } |
94 | 94 |
95 // Blit a horizontal run of antialiased pixels; runs[] is a *sparse* | 95 // Blit a horizontal run of antialiased pixels; runs[] is a *sparse* |
96 // zero-terminated run-length encoding of spans of constant alpha values. | 96 // zero-terminated run-length encoding of spans of constant alpha values. |
97 virtual void blitAntiH(int x, int y, | 97 virtual void blitAntiH(int x, int y, |
98 const SkAlpha antialias[], | 98 const SkAlpha antialias[], |
99 const int16_t runs[]) SK_OVERRIDE { | 99 const int16_t runs[]) override { |
100 SkASSERT(0 == x); | 100 SkASSERT(0 == x); |
101 | 101 |
102 // Make sure that the new row to blit is either the first | 102 // Make sure that the new row to blit is either the first |
103 // row that we're blitting, or it's exactly the next scan row | 103 // row that we're blitting, or it's exactly the next scan row |
104 // since the last row that we blit. This is to ensure that when | 104 // since the last row that we blit. This is to ensure that when |
105 // we go to flush the runs, that they are all the same four | 105 // we go to flush the runs, that they are all the same four |
106 // runs. | 106 // runs. |
107 if (fNextRun > 0 && | 107 if (fNextRun > 0 && |
108 ((x != fBufferedRuns[fNextRun-1].fX) || | 108 ((x != fBufferedRuns[fNextRun-1].fX) || |
109 (y-1 != fBufferedRuns[fNextRun-1].fY))) { | 109 (y-1 != fBufferedRuns[fNextRun-1].fY))) { |
(...skipping 24 matching lines...) Expand all Loading... |
134 fBufferedRuns[fNextRun].fY = y; | 134 fBufferedRuns[fNextRun].fY = y; |
135 | 135 |
136 // If we've output a block of scanlines in a row that don't violate our | 136 // If we've output a block of scanlines in a row that don't violate our |
137 // assumptions, then it's time to flush them... | 137 // assumptions, then it's time to flush them... |
138 if (BlockDim == ++fNextRun) { | 138 if (BlockDim == ++fNextRun) { |
139 this->flushRuns(); | 139 this->flushRuns(); |
140 } | 140 } |
141 } | 141 } |
142 | 142 |
143 // Blit a vertical run of pixels with a constant alpha value. | 143 // Blit a vertical run of pixels with a constant alpha value. |
144 void blitV(int x, int y, int height, SkAlpha alpha) SK_OVERRIDE { | 144 void blitV(int x, int y, int height, SkAlpha alpha) override { |
145 // This function is currently not implemented. It is not explicitly | 145 // This function is currently not implemented. It is not explicitly |
146 // required by the contract, but if at some time a code path runs into | 146 // required by the contract, but if at some time a code path runs into |
147 // this function (which is entirely possible), it needs to be implemente
d. | 147 // this function (which is entirely possible), it needs to be implemente
d. |
148 // | 148 // |
149 // TODO (krajcevski): | 149 // TODO (krajcevski): |
150 // This function will be most easily implemented in one of two ways: | 150 // This function will be most easily implemented in one of two ways: |
151 // 1. Buffer each vertical column value and then construct a list | 151 // 1. Buffer each vertical column value and then construct a list |
152 // of alpha values and output all of the blocks at once. This only | 152 // of alpha values and output all of the blocks at once. This only |
153 // requires a write to the compressed buffer | 153 // requires a write to the compressed buffer |
154 // 2. Replace the indices of each block with the proper indices based | 154 // 2. Replace the indices of each block with the proper indices based |
155 // on the alpha value. This requires a read and write of the compress
ed | 155 // on the alpha value. This requires a read and write of the compress
ed |
156 // buffer, but much less overhead. | 156 // buffer, but much less overhead. |
157 SkFAIL("Not implemented!"); | 157 SkFAIL("Not implemented!"); |
158 } | 158 } |
159 | 159 |
160 // Blit a solid rectangle one or more pixels wide. It's assumed that blitRec
t | 160 // Blit a solid rectangle one or more pixels wide. It's assumed that blitRec
t |
161 // is called as a way to bracket blitAntiH where above and below the path th
e | 161 // is called as a way to bracket blitAntiH where above and below the path th
e |
162 // called path just needs a solid rectangle to fill in the mask. | 162 // called path just needs a solid rectangle to fill in the mask. |
163 #ifdef SK_DEBUG | 163 #ifdef SK_DEBUG |
164 bool fCalledOnceWithNonzeroY; | 164 bool fCalledOnceWithNonzeroY; |
165 #endif | 165 #endif |
166 void blitRect(int x, int y, int width, int height) SK_OVERRIDE { | 166 void blitRect(int x, int y, int width, int height) override { |
167 | 167 |
168 // Assumptions: | 168 // Assumptions: |
169 SkASSERT(0 == x); | 169 SkASSERT(0 == x); |
170 SkASSERT(width <= fWidth); | 170 SkASSERT(width <= fWidth); |
171 | 171 |
172 // Make sure that we're only ever bracketing calls to blitAntiH. | 172 // Make sure that we're only ever bracketing calls to blitAntiH. |
173 SkASSERT((0 == y) || (!fCalledOnceWithNonzeroY && (fCalledOnceWithNonzer
oY = true))); | 173 SkASSERT((0 == y) || (!fCalledOnceWithNonzeroY && (fCalledOnceWithNonzer
oY = true))); |
174 | 174 |
175 #if !(PEDANTIC_BLIT_RECT) | 175 #if !(PEDANTIC_BLIT_RECT) |
176 for (int i = 0; i < height; ++i) { | 176 for (int i = 0; i < height; ++i) { |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 startBlockX, endBlockX); | 272 startBlockX, endBlockX); |
273 } | 273 } |
274 } | 274 } |
275 #endif | 275 #endif |
276 } | 276 } |
277 | 277 |
278 // Blit a rectangle with one alpha-blended column on the left, | 278 // Blit a rectangle with one alpha-blended column on the left, |
279 // width (zero or more) opaque pixels, and one alpha-blended column | 279 // width (zero or more) opaque pixels, and one alpha-blended column |
280 // on the right. The result will always be at least two pixels wide. | 280 // on the right. The result will always be at least two pixels wide. |
281 virtual void blitAntiRect(int x, int y, int width, int height, | 281 virtual void blitAntiRect(int x, int y, int width, int height, |
282 SkAlpha leftAlpha, SkAlpha rightAlpha) SK_OVERRIDE
{ | 282 SkAlpha leftAlpha, SkAlpha rightAlpha) override { |
283 // This function is currently not implemented. It is not explicitly | 283 // This function is currently not implemented. It is not explicitly |
284 // required by the contract, but if at some time a code path runs into | 284 // required by the contract, but if at some time a code path runs into |
285 // this function (which is entirely possible), it needs to be implemente
d. | 285 // this function (which is entirely possible), it needs to be implemente
d. |
286 // | 286 // |
287 // TODO (krajcevski): | 287 // TODO (krajcevski): |
288 // This function will be most easily implemented as follows: | 288 // This function will be most easily implemented as follows: |
289 // 1. If width/height are smaller than a block, then update the | 289 // 1. If width/height are smaller than a block, then update the |
290 // indices of the affected blocks. | 290 // indices of the affected blocks. |
291 // 2. If width/height are larger than a block, then construct a 9-patch | 291 // 2. If width/height are larger than a block, then construct a 9-patch |
292 // of block encodings that represent the rectangle, and write them | 292 // of block encodings that represent the rectangle, and write them |
293 // to the compressed buffer as necessary. Whether or not the blocks | 293 // to the compressed buffer as necessary. Whether or not the blocks |
294 // are overwritten by zeros or just their indices are updated is up | 294 // are overwritten by zeros or just their indices are updated is up |
295 // to debate. | 295 // to debate. |
296 SkFAIL("Not implemented!"); | 296 SkFAIL("Not implemented!"); |
297 } | 297 } |
298 | 298 |
299 // Blit a pattern of pixels defined by a rectangle-clipped mask; We make an | 299 // Blit a pattern of pixels defined by a rectangle-clipped mask; We make an |
300 // assumption here that if this function gets called, then it will replace a
ll | 300 // assumption here that if this function gets called, then it will replace a
ll |
301 // of the compressed texture blocks that it touches. Hence, two separate cal
ls | 301 // of the compressed texture blocks that it touches. Hence, two separate cal
ls |
302 // to blitMask that have clips next to one another will cause artifacts. Mos
t | 302 // to blitMask that have clips next to one another will cause artifacts. Mos
t |
303 // of the time, however, this function gets called because constructing the
mask | 303 // of the time, however, this function gets called because constructing the
mask |
304 // was faster than constructing the RLE for blitAntiH, and this function wil
l | 304 // was faster than constructing the RLE for blitAntiH, and this function wil
l |
305 // only be called once. | 305 // only be called once. |
306 #ifdef SK_DEBUG | 306 #ifdef SK_DEBUG |
307 bool fBlitMaskCalled; | 307 bool fBlitMaskCalled; |
308 #endif | 308 #endif |
309 void blitMask(const SkMask& mask, const SkIRect& clip) SK_OVERRIDE { | 309 void blitMask(const SkMask& mask, const SkIRect& clip) override { |
310 | 310 |
311 // Assumptions: | 311 // Assumptions: |
312 SkASSERT(!fBlitMaskCalled); | 312 SkASSERT(!fBlitMaskCalled); |
313 SkDEBUGCODE(fBlitMaskCalled = true); | 313 SkDEBUGCODE(fBlitMaskCalled = true); |
314 SkASSERT(SkMask::kA8_Format == mask.fFormat); | 314 SkASSERT(SkMask::kA8_Format == mask.fFormat); |
315 SkASSERT(mask.fBounds.contains(clip)); | 315 SkASSERT(mask.fBounds.contains(clip)); |
316 | 316 |
317 // Start from largest block boundary less than the clip boundaries. | 317 // Start from largest block boundary less than the clip boundaries. |
318 const int startI = BlockDim * (clip.left() / BlockDim); | 318 const int startI = BlockDim * (clip.left() / BlockDim); |
319 const int startJ = BlockDim * (clip.top() / BlockDim); | 319 const int startJ = BlockDim * (clip.top() / BlockDim); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 } | 361 } |
362 | 362 |
363 dst += EncodedBlockSize; | 363 dst += EncodedBlockSize; |
364 } | 364 } |
365 } | 365 } |
366 } | 366 } |
367 | 367 |
368 // If the blitter just sets a single value for each pixel, return the | 368 // If the blitter just sets a single value for each pixel, return the |
369 // bitmap it draws into, and assign value. If not, return NULL and ignore | 369 // bitmap it draws into, and assign value. If not, return NULL and ignore |
370 // the value parameter. | 370 // the value parameter. |
371 const SkBitmap* justAnOpaqueColor(uint32_t* value) SK_OVERRIDE { | 371 const SkBitmap* justAnOpaqueColor(uint32_t* value) override { |
372 return NULL; | 372 return NULL; |
373 } | 373 } |
374 | 374 |
375 /** | 375 /** |
376 * Compressed texture blitters only really work correctly if they get | 376 * Compressed texture blitters only really work correctly if they get |
377 * BlockDim rows at a time. That being said, this blitter tries it's best | 377 * BlockDim rows at a time. That being said, this blitter tries it's best |
378 * to preserve semantics if blitAntiH doesn't get called in too many | 378 * to preserve semantics if blitAntiH doesn't get called in too many |
379 * weird ways... | 379 * weird ways... |
380 */ | 380 */ |
381 int requestRowsPreserved() const SK_OVERRIDE { return BlockDim; } | 381 int requestRowsPreserved() const override { return BlockDim; } |
382 | 382 |
383 private: | 383 private: |
384 static const int kPixelsPerBlock = BlockDim * BlockDim; | 384 static const int kPixelsPerBlock = BlockDim * BlockDim; |
385 | 385 |
386 // The longest possible run of pixels that this blitter will receive. | 386 // The longest possible run of pixels that this blitter will receive. |
387 // This is initialized in the constructor to 0x7FFE, which is one less | 387 // This is initialized in the constructor to 0x7FFE, which is one less |
388 // than the largest positive 16-bit integer. We make sure that it's one | 388 // than the largest positive 16-bit integer. We make sure that it's one |
389 // less for debugging purposes. We also don't make this variable static | 389 // less for debugging purposes. We also don't make this variable static |
390 // in order to make sure that we can construct a valid pointer to it. | 390 // in order to make sure that we can construct a valid pointer to it. |
391 const int16_t kLongestRun; | 391 const int16_t kLongestRun; |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
724 mask, BlockDim, mask); | 724 mask, BlockDim, mask); |
725 } | 725 } |
726 } | 726 } |
727 #endif // PEDANTIC_BLIT_RECT | 727 #endif // PEDANTIC_BLIT_RECT |
728 | 728 |
729 }; | 729 }; |
730 | 730 |
731 } // namespace SkTextureCompressor | 731 } // namespace SkTextureCompressor |
732 | 732 |
733 #endif // SkTextureCompressor_Blitter_DEFINED | 733 #endif // SkTextureCompressor_Blitter_DEFINED |
OLD | NEW |