OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2010 Google Inc. | 2 * Copyright 2010 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 #include "SkGr.h" | 8 #include "SkGr.h" |
9 #include "SkColorFilter.h" | 9 #include "SkColorFilter.h" |
10 #include "SkConfig8888.h" | 10 #include "SkConfig8888.h" |
11 #include "SkData.h" | |
11 #include "SkMessageBus.h" | 12 #include "SkMessageBus.h" |
12 #include "SkPixelRef.h" | 13 #include "SkPixelRef.h" |
13 #include "GrResourceCache.h" | 14 #include "GrResourceCache.h" |
15 #include "GrGpu.h" | |
16 #include "GrDrawTargetCaps.h" | |
17 | |
18 #include "etc1.h" | |
14 | 19 |
15 /* Fill out buffer with the compressed format Ganesh expects from a colortable | 20 /* Fill out buffer with the compressed format Ganesh expects from a colortable |
16 based bitmap. [palette (colortable) + indices]. | 21 based bitmap. [palette (colortable) + indices]. |
17 | 22 |
18 At the moment Ganesh only supports 8bit version. If Ganesh allowed we others | 23 At the moment Ganesh only supports 8bit version. If Ganesh allowed we others |
19 we could detect that the colortable.count is <= 16, and then repack the | 24 we could detect that the colortable.count is <= 16, and then repack the |
20 indices as nibbles to save RAM, but it would take more time (i.e. a lot | 25 indices as nibbles to save RAM, but it would take more time (i.e. a lot |
21 slower than memcpy), so skipping that for now. | 26 slower than memcpy), so skipping that for now. |
22 | 27 |
23 Ganesh wants a full 256 palette entry, even though Skia's ctable is only as big | 28 Ganesh wants a full 256 palette entry, even though Skia's ctable is only as big |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
165 bitmap->height(), desc.fConfig, | 170 bitmap->height(), desc.fConfig, |
166 storage.get()); | 171 storage.get()); |
167 return result; | 172 return result; |
168 } | 173 } |
169 } else { | 174 } else { |
170 origBitmap.copyTo(&tmpBitmap, kN32_SkColorType); | 175 origBitmap.copyTo(&tmpBitmap, kN32_SkColorType); |
171 // now bitmap points to our temp, which has been promoted to 32bits | 176 // now bitmap points to our temp, which has been promoted to 32bits |
172 bitmap = &tmpBitmap; | 177 bitmap = &tmpBitmap; |
173 desc.fConfig = SkImageInfo2GrPixelConfig(bitmap->info()); | 178 desc.fConfig = SkImageInfo2GrPixelConfig(bitmap->info()); |
174 } | 179 } |
180 } else if (cache && ctx->getGpu()->caps()->compressedTextureSupport(kETC1_Gr CompressedFormat)) { | |
181 SkData *data = bitmap->pixelRef()->refEncodedData(); | |
robertphillips
2014/05/27 22:01:50
hmmm
| |
182 do { | |
183 // Is this even encoded data? | |
robertphillips
2014/05/27 22:01:50
NULL == data ?
krajcevski
2014/05/27 22:19:29
Done.
| |
184 if (!data) { | |
185 break; | |
186 } | |
187 | |
188 // Is this a valid PKM encoded data? | |
189 const uint8_t *bytes = data->bytes(); | |
190 if (!etc1_pkm_is_valid(bytes)) { | |
191 break; | |
192 } | |
193 | |
194 uint32_t encodedWidth = etc1_pkm_get_width(bytes); | |
195 uint32_t encodedHeight = etc1_pkm_get_height(bytes); | |
196 | |
197 // Does the data match the dimensions of the bitmap? If not, | |
198 // then we don't know how to scale the image to match it... | |
199 if (encodedWidth != static_cast<uint32_t>(bitmap->width()) || | |
200 encodedHeight != static_cast<uint32_t>(bitmap->height())) { | |
201 break; | |
202 } | |
203 | |
204 // Everything seems good... skip ahead to the data. | |
205 bytes += ETC_PKM_HEADER_SIZE; | |
206 | |
207 // This texture is likely to be used again so leave it in the cache | |
208 GrCacheID cacheID; | |
209 generate_bitmap_cache_id(origBitmap, &cacheID); | |
210 | |
211 GrResourceKey key; | |
212 GrTexture* result = | |
213 ctx->createCompressedTexture(params, desc, cacheID, | |
214 bytes, kETC1_GrCompressedFormat, &k ey); | |
215 if (NULL != result) { | |
216 add_genID_listener(key, origBitmap.pixelRef()); | |
217 } | |
218 return result; | |
219 | |
220 } while(0); | |
175 } | 221 } |
176 | 222 |
177 SkAutoLockPixels alp(*bitmap); | 223 SkAutoLockPixels alp(*bitmap); |
178 if (!bitmap->readyToDraw()) { | 224 if (!bitmap->readyToDraw()) { |
179 return NULL; | 225 return NULL; |
180 } | 226 } |
181 if (cache) { | 227 if (cache) { |
182 // This texture is likely to be used again so leave it in the cache | 228 // This texture is likely to be used again so leave it in the cache |
183 GrCacheID cacheID; | 229 GrCacheID cacheID; |
184 generate_bitmap_cache_id(origBitmap, &cacheID); | 230 generate_bitmap_cache_id(origBitmap, &cacheID); |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
432 copy.setShader(NULL); | 478 copy.setShader(NULL); |
433 // modulate the paint alpha by the shader's solid color alpha | 479 // modulate the paint alpha by the shader's solid color alpha |
434 U8CPU newA = SkMulDiv255Round(SkColorGetA(color), copy.getAlpha()); | 480 U8CPU newA = SkMulDiv255Round(SkColorGetA(color), copy.getAlpha()); |
435 copy.setColor(SkColorSetA(color, newA)); | 481 copy.setColor(SkColorSetA(color, newA)); |
436 SkPaint2GrPaintNoShader(context, copy, false, constantColor, grPaint ); | 482 SkPaint2GrPaintNoShader(context, copy, false, constantColor, grPaint ); |
437 } else { | 483 } else { |
438 SkPaint2GrPaintNoShader(context, skPaint, false, constantColor, grPa int); | 484 SkPaint2GrPaintNoShader(context, skPaint, false, constantColor, grPa int); |
439 } | 485 } |
440 } | 486 } |
441 } | 487 } |
OLD | NEW |