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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
148 // 1. If width/height are smaller than a block, then update the | 148 // 1. If width/height are smaller than a block, then update the |
149 // indices of the affected blocks. | 149 // indices of the affected blocks. |
150 // 2. If width/height are larger than a block, then construct a 9-patch | 150 // 2. If width/height are larger than a block, then construct a 9-patch |
151 // of block encodings that represent the rectangle, and write them | 151 // of block encodings that represent the rectangle, and write them |
152 // to the compressed buffer as necessary. Whether or not the blocks | 152 // to the compressed buffer as necessary. Whether or not the blocks |
153 // are overwritten by zeros or just their indices are updated is up | 153 // are overwritten by zeros or just their indices are updated is up |
154 // to debate. | 154 // to debate. |
155 SkFAIL("Not implemented!"); | 155 SkFAIL("Not implemented!"); |
156 } | 156 } |
157 | 157 |
158 // Blit a pattern of pixels defined by a rectangle-clipped mask; | 158 // Blit a pattern of pixels defined by a rectangle-clipped mask; We make an |
159 // typically used for text. | 159 // assumption here that if this function gets called, then it will replace a ll |
160 virtual void blitMask(const SkMask&, const SkIRect& clip) SK_OVERRIDE { | 160 // of the compressed texture blocks that it touches. Hence, two separate cal ls |
161 // This function is currently not implemented. It is not explicitly | 161 // to blitMask that have clips next to one another will cause artifacts. Mos t |
162 // required by the contract, but if at some time a code path runs into | 162 // of the time, however, this function gets called because constructing the mask |
163 // this function (which is entirely possible), it needs to be implemente d. | 163 // was faster than constructing the RLE for blitAntiH, and this function wil l |
164 // | 164 // only be called once. |
165 // TODO (krajcevski): | 165 virtual void blitMask(const SkMask& mask, const SkIRect& clip) SK_OVERRIDE { |
reed1
2014/08/08 13:54:52
I vote to move any impl this big into a .cpp file.
robertphillips
2014/08/08 13:57:20
We would have to switch from a template to a class
| |
166 // This function will be most easily implemented in the same way as | 166 |
167 // blitAntiRect above. | 167 // Assumptions: |
168 SkFAIL("Not implemented!"); | 168 SkASSERT(SkMask::kA8_Format == mask.fFormat); |
169 SkASSERT(mask.fBounds.contains(clip)); | |
170 | |
171 // Start from largest block boundary less than the clip boundaries. | |
172 const int startI = BlockDim * (clip.left() / BlockDim); | |
173 const int startJ = BlockDim * (clip.top() / BlockDim); | |
174 | |
175 for (int j = startJ; j < clip.bottom(); j += BlockDim) { | |
176 | |
177 // Get the destination for this block row | |
178 uint8_t* dst = this->getBlock(startI, j); | |
179 for (int i = startI; i < clip.right(); i += BlockDim) { | |
180 | |
181 // At this point, the block should intersect the clip. | |
182 SkASSERT(SkIRect::IntersectsNoEmptyCheck( | |
183 SkIRect::MakeXYWH(i, j, BlockDim, BlockDim), clip)) ; | |
184 | |
185 // Do we need to pad it? | |
186 if (i < clip.left() || j < clip.top() || | |
187 i + BlockDim > clip.right() || j + BlockDim > clip.bottom()) { | |
188 | |
189 uint8_t block[BlockDim*BlockDim]; | |
190 memset(block, 0, sizeof(block)); | |
191 | |
192 const int startX = SkMax32(i, clip.left()); | |
193 const int startY = SkMax32(j, clip.top()); | |
194 | |
195 const int endX = SkMin32(i + BlockDim, clip.right()); | |
196 const int endY = SkMin32(j + BlockDim, clip.bottom()); | |
197 | |
198 for (int y = startY; y < endY; ++y) { | |
199 const int col = startX - i; | |
200 const int row = y - j; | |
201 const int valsWide = endX - startX; | |
202 SkASSERT(valsWide <= BlockDim); | |
203 SkASSERT(0 <= col && col < BlockDim); | |
204 SkASSERT(0 <= row && row < BlockDim); | |
205 memcpy(block + row*BlockDim + col, | |
206 mask.getAddr8(startX, j + row), valsWide); | |
207 } | |
208 | |
209 CompressorType::CompressA8Horizontal(dst, block, BlockDim); | |
210 } else { | |
211 // Otherwise, just compress it. | |
212 uint8_t*const src = mask.getAddr8(i, j); | |
213 const uint32_t rb = mask.fRowBytes; | |
214 CompressorType::CompressA8Horizontal(dst, src, rb); | |
215 } | |
216 | |
217 dst += EncodedBlockSize; | |
218 } | |
219 } | |
169 } | 220 } |
170 | 221 |
171 // If the blitter just sets a single value for each pixel, return the | 222 // If the blitter just sets a single value for each pixel, return the |
172 // bitmap it draws into, and assign value. If not, return NULL and ignore | 223 // bitmap it draws into, and assign value. If not, return NULL and ignore |
173 // the value parameter. | 224 // the value parameter. |
174 virtual const SkBitmap* justAnOpaqueColor(uint32_t* value) SK_OVERRIDE { | 225 virtual const SkBitmap* justAnOpaqueColor(uint32_t* value) SK_OVERRIDE { |
175 return NULL; | 226 return NULL; |
176 } | 227 } |
177 | 228 |
178 /** | 229 /** |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
410 CompressorType::CompressA8Vertical(outPtr, reinterpret_cast<uint8_t* >(block)); | 461 CompressorType::CompressA8Vertical(outPtr, reinterpret_cast<uint8_t* >(block)); |
411 } | 462 } |
412 | 463 |
413 fNextRun = 0; | 464 fNextRun = 0; |
414 } | 465 } |
415 }; | 466 }; |
416 | 467 |
417 } // namespace SkTextureCompressor | 468 } // namespace SkTextureCompressor |
418 | 469 |
419 #endif // SkTextureCompressor_Blitter_DEFINED | 470 #endif // SkTextureCompressor_Blitter_DEFINED |
OLD | NEW |