| 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 #if SK_SUPPORT_ETC1 | 18 #ifndef SK_IGNORE_ETC1_SUPPORT |
| 19 # include "etc1.h" | 19 # include "etc1.h" |
| 20 #endif | 20 #endif |
| 21 | 21 |
| 22 /* Fill out buffer with the compressed format Ganesh expects from a colortable | 22 /* Fill out buffer with the compressed format Ganesh expects from a colortable |
| 23 based bitmap. [palette (colortable) + indices]. | 23 based bitmap. [palette (colortable) + indices]. |
| 24 | 24 |
| 25 At the moment Ganesh only supports 8bit version. If Ganesh allowed we others | 25 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 | 26 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 | 27 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. | 28 slower than memcpy), so skipping that for now. |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 } | 124 } |
| 125 }; | 125 }; |
| 126 | 126 |
| 127 } // namespace | 127 } // namespace |
| 128 | 128 |
| 129 static void add_genID_listener(GrResourceKey key, SkPixelRef* pixelRef) { | 129 static void add_genID_listener(GrResourceKey key, SkPixelRef* pixelRef) { |
| 130 SkASSERT(NULL != pixelRef); | 130 SkASSERT(NULL != pixelRef); |
| 131 pixelRef->addGenIDChangeListener(SkNEW_ARGS(GrResourceInvalidator, (key))); | 131 pixelRef->addGenIDChangeListener(SkNEW_ARGS(GrResourceInvalidator, (key))); |
| 132 } | 132 } |
| 133 | 133 |
| 134 #if SK_SUPPORT_ETC1 | 134 #ifndef SK_IGNORE_ETC1_SUPPORT |
| 135 static GrTexture *load_etc1_texture(GrContext* ctx, | 135 static GrTexture *load_etc1_texture(GrContext* ctx, |
| 136 const GrTextureParams* params, | 136 const GrTextureParams* params, |
| 137 const SkBitmap &bm, GrTextureDesc desc) { | 137 const SkBitmap &bm, GrTextureDesc desc) { |
| 138 SkData *data = bm.pixelRef()->refEncodedData(); | 138 SkData *data = bm.pixelRef()->refEncodedData(); |
| 139 | 139 |
| 140 // Is this even encoded data? | 140 // Is this even encoded data? |
| 141 if (NULL == data) { | 141 if (NULL == data) { |
| 142 return NULL; | 142 return NULL; |
| 143 } | 143 } |
| 144 | 144 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 166 GrCacheID cacheID; | 166 GrCacheID cacheID; |
| 167 generate_bitmap_cache_id(bm, &cacheID); | 167 generate_bitmap_cache_id(bm, &cacheID); |
| 168 | 168 |
| 169 GrResourceKey key; | 169 GrResourceKey key; |
| 170 GrTexture* result = ctx->createTexture(params, desc, cacheID, bytes, 0, &key
); | 170 GrTexture* result = ctx->createTexture(params, desc, cacheID, bytes, 0, &key
); |
| 171 if (NULL != result) { | 171 if (NULL != result) { |
| 172 add_genID_listener(key, bm.pixelRef()); | 172 add_genID_listener(key, bm.pixelRef()); |
| 173 } | 173 } |
| 174 return result; | 174 return result; |
| 175 } | 175 } |
| 176 #endif // SK_SUPPORT_ETC1 | 176 #endif // SK_IGNORE_ETC1_SUPPORT |
| 177 | 177 |
| 178 static GrTexture* sk_gr_create_bitmap_texture(GrContext* ctx, | 178 static GrTexture* sk_gr_create_bitmap_texture(GrContext* ctx, |
| 179 bool cache, | 179 bool cache, |
| 180 const GrTextureParams* params, | 180 const GrTextureParams* params, |
| 181 const SkBitmap& origBitmap) { | 181 const SkBitmap& origBitmap) { |
| 182 SkBitmap tmpBitmap; | 182 SkBitmap tmpBitmap; |
| 183 | 183 |
| 184 const SkBitmap* bitmap = &origBitmap; | 184 const SkBitmap* bitmap = &origBitmap; |
| 185 | 185 |
| 186 GrTextureDesc desc; | 186 GrTextureDesc desc; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 } | 219 } |
| 220 } else { | 220 } else { |
| 221 origBitmap.copyTo(&tmpBitmap, kN32_SkColorType); | 221 origBitmap.copyTo(&tmpBitmap, kN32_SkColorType); |
| 222 // now bitmap points to our temp, which has been promoted to 32bits | 222 // now bitmap points to our temp, which has been promoted to 32bits |
| 223 bitmap = &tmpBitmap; | 223 bitmap = &tmpBitmap; |
| 224 desc.fConfig = SkImageInfo2GrPixelConfig(bitmap->info()); | 224 desc.fConfig = SkImageInfo2GrPixelConfig(bitmap->info()); |
| 225 } | 225 } |
| 226 } | 226 } |
| 227 | 227 |
| 228 // Is this an ETC1 encoded texture? | 228 // Is this an ETC1 encoded texture? |
| 229 #if SK_SUPPORT_ETC1 | 229 #ifndef SK_IGNORE_ETC1_SUPPORT |
| 230 else if (cache && ctx->getGpu()->caps()->isConfigTexturable(kETC1_GrPixelCon
fig)) { | 230 else if (cache && ctx->getGpu()->caps()->isConfigTexturable(kETC1_GrPixelCon
fig)) { |
| 231 GrTexture *texture = load_etc1_texture(ctx, params, *bitmap, desc); | 231 GrTexture *texture = load_etc1_texture(ctx, params, *bitmap, desc); |
| 232 if (NULL != texture) { | 232 if (NULL != texture) { |
| 233 return texture; | 233 return texture; |
| 234 } | 234 } |
| 235 } | 235 } |
| 236 #endif // SK_SUPPORT_ETC1 | 236 #endif // SK_IGNORE_ETC1_SUPPORT |
| 237 | 237 |
| 238 SkAutoLockPixels alp(*bitmap); | 238 SkAutoLockPixels alp(*bitmap); |
| 239 if (!bitmap->readyToDraw()) { | 239 if (!bitmap->readyToDraw()) { |
| 240 return NULL; | 240 return NULL; |
| 241 } | 241 } |
| 242 if (cache) { | 242 if (cache) { |
| 243 // This texture is likely to be used again so leave it in the cache | 243 // This texture is likely to be used again so leave it in the cache |
| 244 GrCacheID cacheID; | 244 GrCacheID cacheID; |
| 245 generate_bitmap_cache_id(origBitmap, &cacheID); | 245 generate_bitmap_cache_id(origBitmap, &cacheID); |
| 246 | 246 |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 copy.setShader(NULL); | 493 copy.setShader(NULL); |
| 494 // modulate the paint alpha by the shader's solid color alpha | 494 // modulate the paint alpha by the shader's solid color alpha |
| 495 U8CPU newA = SkMulDiv255Round(SkColorGetA(color), copy.getAlpha()); | 495 U8CPU newA = SkMulDiv255Round(SkColorGetA(color), copy.getAlpha()); |
| 496 copy.setColor(SkColorSetA(color, newA)); | 496 copy.setColor(SkColorSetA(color, newA)); |
| 497 SkPaint2GrPaintNoShader(context, copy, false, constantColor, grPaint
); | 497 SkPaint2GrPaintNoShader(context, copy, false, constantColor, grPaint
); |
| 498 } else { | 498 } else { |
| 499 SkPaint2GrPaintNoShader(context, skPaint, false, constantColor, grPa
int); | 499 SkPaint2GrPaintNoShader(context, skPaint, false, constantColor, grPa
int); |
| 500 } | 500 } |
| 501 } | 501 } |
| 502 } | 502 } |
| OLD | NEW |