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 "SkData.h" |
12 #include "SkMessageBus.h" | 12 #include "SkMessageBus.h" |
13 #include "SkPixelRef.h" | 13 #include "SkPixelRef.h" |
14 #include "GrResourceCache.h" | 14 #include "GrResourceCache.h" |
15 #include "GrGpu.h" | 15 #include "GrGpu.h" |
16 #include "GrDrawTargetCaps.h" | 16 #include "GrDrawTargetCaps.h" |
17 | 17 |
18 #ifndef SK_IGNORE_ETC1_SUPPORT | 18 #ifndef SK_IGNORE_ETC1_SUPPORT |
| 19 # include "ktx.h" |
19 # include "etc1.h" | 20 # include "etc1.h" |
20 #endif | 21 #endif |
21 | 22 |
22 /* Fill out buffer with the compressed format Ganesh expects from a colortable | 23 /* Fill out buffer with the compressed format Ganesh expects from a colortable |
23 based bitmap. [palette (colortable) + indices]. | 24 based bitmap. [palette (colortable) + indices]. |
24 | 25 |
25 At the moment Ganesh only supports 8bit version. If Ganesh allowed we others | 26 At the moment Ganesh only supports 8bit version. If Ganesh allowed we others |
26 we could detect that the colortable.count is <= 16, and then repack the | 27 we could detect that the colortable.count is <= 16, and then repack the |
27 indices as nibbles to save RAM, but it would take more time (i.e. a lot | 28 indices as nibbles to save RAM, but it would take more time (i.e. a lot |
28 slower than memcpy), so skipping that for now. | 29 slower than memcpy), so skipping that for now. |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 | 129 |
129 static void add_genID_listener(GrResourceKey key, SkPixelRef* pixelRef) { | 130 static void add_genID_listener(GrResourceKey key, SkPixelRef* pixelRef) { |
130 SkASSERT(NULL != pixelRef); | 131 SkASSERT(NULL != pixelRef); |
131 pixelRef->addGenIDChangeListener(SkNEW_ARGS(GrResourceInvalidator, (key))); | 132 pixelRef->addGenIDChangeListener(SkNEW_ARGS(GrResourceInvalidator, (key))); |
132 } | 133 } |
133 | 134 |
134 #ifndef SK_IGNORE_ETC1_SUPPORT | 135 #ifndef SK_IGNORE_ETC1_SUPPORT |
135 static GrTexture *load_etc1_texture(GrContext* ctx, | 136 static GrTexture *load_etc1_texture(GrContext* ctx, |
136 const GrTextureParams* params, | 137 const GrTextureParams* params, |
137 const SkBitmap &bm, GrTextureDesc desc) { | 138 const SkBitmap &bm, GrTextureDesc desc) { |
138 SkData *data = bm.pixelRef()->refEncodedData(); | 139 SkAutoTUnref<SkData> data(bm.pixelRef()->refEncodedData()); |
139 | 140 |
140 // Is this even encoded data? | 141 // Is this even encoded data? |
141 if (NULL == data) { | 142 if (NULL == data) { |
142 return NULL; | 143 return NULL; |
143 } | 144 } |
144 | 145 |
145 // Is this a valid PKM encoded data? | 146 // Is this a valid PKM encoded data? |
146 const uint8_t *bytes = data->bytes(); | 147 const uint8_t *bytes = data->bytes(); |
147 if (!etc1_pkm_is_valid(bytes)) { | 148 if (etc1_pkm_is_valid(bytes)) { |
| 149 uint32_t encodedWidth = etc1_pkm_get_width(bytes); |
| 150 uint32_t encodedHeight = etc1_pkm_get_height(bytes); |
| 151 |
| 152 // Does the data match the dimensions of the bitmap? If not, |
| 153 // then we don't know how to scale the image to match it... |
| 154 if (encodedWidth != static_cast<uint32_t>(bm.width()) || |
| 155 encodedHeight != static_cast<uint32_t>(bm.height())) { |
| 156 return NULL; |
| 157 } |
| 158 |
| 159 // Everything seems good... skip ahead to the data. |
| 160 bytes += ETC_PKM_HEADER_SIZE; |
| 161 desc.fConfig = kETC1_GrPixelConfig; |
| 162 } else if (SkKTXFile::is_ktx(bytes)) { |
| 163 SkKTXFile ktx(data); |
| 164 |
| 165 // Is it actually an ETC1 texture? |
| 166 if (!ktx.isETC1()) { |
| 167 return NULL; |
| 168 } |
| 169 |
| 170 // Does the data match the dimensions of the bitmap? If not, |
| 171 // then we don't know how to scale the image to match it... |
| 172 if (ktx.width() != bm.width() || ktx.height() != bm.height()) { |
| 173 return NULL; |
| 174 } |
| 175 |
| 176 bytes = ktx.pixelData(); |
| 177 desc.fConfig = kETC1_GrPixelConfig; |
| 178 } else { |
148 return NULL; | 179 return NULL; |
149 } | 180 } |
150 | 181 |
151 uint32_t encodedWidth = etc1_pkm_get_width(bytes); | |
152 uint32_t encodedHeight = etc1_pkm_get_height(bytes); | |
153 | |
154 // Does the data match the dimensions of the bitmap? If not, | |
155 // then we don't know how to scale the image to match it... | |
156 if (encodedWidth != static_cast<uint32_t>(bm.width()) || | |
157 encodedHeight != static_cast<uint32_t>(bm.height())) { | |
158 return NULL; | |
159 } | |
160 | |
161 // Everything seems good... skip ahead to the data. | |
162 bytes += ETC_PKM_HEADER_SIZE; | |
163 desc.fConfig = kETC1_GrPixelConfig; | |
164 | |
165 // This texture is likely to be used again so leave it in the cache | 182 // This texture is likely to be used again so leave it in the cache |
166 GrCacheID cacheID; | 183 GrCacheID cacheID; |
167 generate_bitmap_cache_id(bm, &cacheID); | 184 generate_bitmap_cache_id(bm, &cacheID); |
168 | 185 |
169 GrResourceKey key; | 186 GrResourceKey key; |
170 GrTexture* result = ctx->createTexture(params, desc, cacheID, bytes, 0, &key
); | 187 GrTexture* result = ctx->createTexture(params, desc, cacheID, bytes, 0, &key
); |
171 if (NULL != result) { | 188 if (NULL != result) { |
172 add_genID_listener(key, bm.pixelRef()); | 189 add_genID_listener(key, bm.pixelRef()); |
173 } | 190 } |
174 return result; | 191 return result; |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 copy.setShader(NULL); | 510 copy.setShader(NULL); |
494 // modulate the paint alpha by the shader's solid color alpha | 511 // modulate the paint alpha by the shader's solid color alpha |
495 U8CPU newA = SkMulDiv255Round(SkColorGetA(color), copy.getAlpha()); | 512 U8CPU newA = SkMulDiv255Round(SkColorGetA(color), copy.getAlpha()); |
496 copy.setColor(SkColorSetA(color, newA)); | 513 copy.setColor(SkColorSetA(color, newA)); |
497 SkPaint2GrPaintNoShader(context, copy, false, constantColor, grPaint
); | 514 SkPaint2GrPaintNoShader(context, copy, false, constantColor, grPaint
); |
498 } else { | 515 } else { |
499 SkPaint2GrPaintNoShader(context, skPaint, false, constantColor, grPa
int); | 516 SkPaint2GrPaintNoShader(context, skPaint, false, constantColor, grPa
int); |
500 } | 517 } |
501 } | 518 } |
502 } | 519 } |
OLD | NEW |