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" |
(...skipping 16 matching lines...) Expand all Loading... |
27 based bitmap. [palette (colortable) + indices]. | 27 based bitmap. [palette (colortable) + indices]. |
28 | 28 |
29 At the moment Ganesh only supports 8bit version. If Ganesh allowed we others | 29 At the moment Ganesh only supports 8bit version. If Ganesh allowed we others |
30 we could detect that the colortable.count is <= 16, and then repack the | 30 we could detect that the colortable.count is <= 16, and then repack the |
31 indices as nibbles to save RAM, but it would take more time (i.e. a lot | 31 indices as nibbles to save RAM, but it would take more time (i.e. a lot |
32 slower than memcpy), so skipping that for now. | 32 slower than memcpy), so skipping that for now. |
33 | 33 |
34 Ganesh wants a full 256 palette entry, even though Skia's ctable is only as big | 34 Ganesh wants a full 256 palette entry, even though Skia's ctable is only as big |
35 as the colortable.count says it is. | 35 as the colortable.count says it is. |
36 */ | 36 */ |
37 static void build_compressed_data(void* buffer, const SkBitmap& bitmap) { | 37 static void build_index8_data(void* buffer, const SkBitmap& bitmap) { |
38 SkASSERT(kIndex_8_SkColorType == bitmap.colorType()); | 38 SkASSERT(kIndex_8_SkColorType == bitmap.colorType()); |
39 | 39 |
40 SkAutoLockPixels alp(bitmap); | 40 SkAutoLockPixels alp(bitmap); |
41 if (!bitmap.readyToDraw()) { | 41 if (!bitmap.readyToDraw()) { |
42 SkDEBUGFAIL("bitmap not ready to draw!"); | 42 SkDEBUGFAIL("bitmap not ready to draw!"); |
43 return; | 43 return; |
44 } | 44 } |
45 | 45 |
46 SkColorTable* ctable = bitmap.getColorTable(); | 46 SkColorTable* ctable = bitmap.getColorTable(); |
47 char* dst = (char*)buffer; | 47 char* dst = (char*)buffer; |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 SkBitmap tmpBitmap; | 301 SkBitmap tmpBitmap; |
302 | 302 |
303 const SkBitmap* bitmap = &origBitmap; | 303 const SkBitmap* bitmap = &origBitmap; |
304 | 304 |
305 GrTextureDesc desc; | 305 GrTextureDesc desc; |
306 generate_bitmap_texture_desc(*bitmap, &desc); | 306 generate_bitmap_texture_desc(*bitmap, &desc); |
307 | 307 |
308 if (kIndex_8_SkColorType == bitmap->colorType()) { | 308 if (kIndex_8_SkColorType == bitmap->colorType()) { |
309 // build_compressed_data doesn't do npot->pot expansion | 309 // build_compressed_data doesn't do npot->pot expansion |
310 // and paletted textures can't be sub-updated | 310 // and paletted textures can't be sub-updated |
311 if (ctx->supportsIndex8PixelConfig(params, bitmap->width(), bitmap->heig
ht())) { | 311 if (cache && ctx->supportsIndex8PixelConfig(params, bitmap->width(), bit
map->height())) { |
312 size_t imageSize = GrCompressedFormatDataSize(kIndex_8_GrPixelConfig
, | 312 size_t imageSize = GrCompressedFormatDataSize(kIndex_8_GrPixelConfig
, |
313 bitmap->width(), bitma
p->height()); | 313 bitmap->width(), bitma
p->height()); |
314 SkAutoMalloc storage(imageSize); | 314 SkAutoMalloc storage(imageSize); |
315 | 315 build_index8_data(storage.get(), origBitmap); |
316 build_compressed_data(storage.get(), origBitmap); | |
317 | 316 |
318 // our compressed data will be trimmed, so pass width() for its | 317 // our compressed data will be trimmed, so pass width() for its |
319 // "rowBytes", since they are the same now. | 318 // "rowBytes", since they are the same now. |
320 return sk_gr_allocate_texture(ctx, cache, params, origBitmap, | 319 return sk_gr_allocate_texture(ctx, cache, params, origBitmap, |
321 desc, storage.get(), bitmap->width()); | 320 desc, storage.get(), bitmap->width()); |
322 } else { | 321 } else { |
323 origBitmap.copyTo(&tmpBitmap, kN32_SkColorType); | 322 origBitmap.copyTo(&tmpBitmap, kN32_SkColorType); |
324 // now bitmap points to our temp, which has been promoted to 32bits | 323 // now bitmap points to our temp, which has been promoted to 32bits |
325 bitmap = &tmpBitmap; | 324 bitmap = &tmpBitmap; |
326 desc.fConfig = SkImageInfo2GrPixelConfig(bitmap->info()); | 325 desc.fConfig = SkImageInfo2GrPixelConfig(bitmap->info()); |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 if (shader->asFragmentProcessor(context, skPaint, NULL, &paintColor, &fp
) && fp) { | 574 if (shader->asFragmentProcessor(context, skPaint, NULL, &paintColor, &fp
) && fp) { |
576 grPaint->addColorProcessor(fp)->unref(); | 575 grPaint->addColorProcessor(fp)->unref(); |
577 constantColor = false; | 576 constantColor = false; |
578 } | 577 } |
579 } | 578 } |
580 | 579 |
581 // The grcolor is automatically set when calling asFragmentProcessor. | 580 // The grcolor is automatically set when calling asFragmentProcessor. |
582 // If the shader can be seen as an effect it returns true and adds its effec
t to the grpaint. | 581 // If the shader can be seen as an effect it returns true and adds its effec
t to the grpaint. |
583 SkPaint2GrPaintNoShader(context, skPaint, paintColor, constantColor, grPaint
); | 582 SkPaint2GrPaintNoShader(context, skPaint, paintColor, constantColor, grPaint
); |
584 } | 583 } |
OLD | NEW |