Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(326)

Side by Side Diff: src/core/SkImageCacherator.cpp

Issue 1339753002: support colortables in cacherator (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gm/image_pict.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 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 "SkBitmap.h" 8 #include "SkBitmap.h"
9 #include "SkBitmapCache.h" 9 #include "SkBitmapCache.h"
10 #include "SkImageCacherator.h" 10 #include "SkImageCacherator.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 return generator->refEncodedData(); 63 return generator->refEncodedData();
64 } 64 }
65 65
66 static bool check_output_bitmap(const SkBitmap& bitmap, uint32_t expectedID) { 66 static bool check_output_bitmap(const SkBitmap& bitmap, uint32_t expectedID) {
67 SkASSERT(bitmap.getGenerationID() == expectedID); 67 SkASSERT(bitmap.getGenerationID() == expectedID);
68 SkASSERT(bitmap.isImmutable()); 68 SkASSERT(bitmap.isImmutable());
69 SkASSERT(bitmap.getPixels()); 69 SkASSERT(bitmap.getPixels());
70 return true; 70 return true;
71 } 71 }
72 72
73 bool SkImageCacherator::generateBitmap(SkBitmap* bitmap) { 73 static void release_malloc_proc(void* pixels, void* ctx) {
74 const size_t rowBytes = fInfo.minRowBytes(); 74 sk_free(pixels);
75 if (!bitmap->tryAllocPixels(fInfo, rowBytes)) { 75 }
76
77 static bool generate_a_bitmap(SkBitmap* bitmap, SkImageGenerator* gen, const SkI mageInfo& info) {
78 const size_t rowBytes = info.minRowBytes();
79 const size_t pixelSize = info.getSafeSize(rowBytes);
80 if (0 == pixelSize) {
76 return false; 81 return false;
77 } 82 }
78 SkASSERT(bitmap->rowBytes() == rowBytes);
79 83
84 SkAutoFree pixelStorage(sk_malloc_flags(pixelSize, 0));
85 void* pixels = pixelStorage.get();
86 if (!pixels) {
87 return false;
88 }
89
90 SkPMColor ctStorage[256];
91 int ctCount = 0;
92
93 if (!gen->getPixels(info, pixels, rowBytes, ctStorage, &ctCount)) {
94 return false;
95 }
96
97 SkAutoTUnref<SkColorTable> ctable;
98 if (ctCount > 0) {
99 SkASSERT(kIndex_8_SkColorType == info.colorType());
100 ctable.reset(new SkColorTable(ctStorage, ctCount));
101 } else {
102 SkASSERT(kIndex_8_SkColorType != info.colorType());
103 }
104
105 return bitmap->installPixels(info, pixelStorage.detach(), rowBytes, ctable,
106 release_malloc_proc, nullptr);
107 }
108
109 bool SkImageCacherator::generateBitmap(SkBitmap* bitmap) {
80 ScopedGenerator generator(this); 110 ScopedGenerator generator(this);
81 const SkImageInfo& genInfo = generator->getInfo(); 111 const SkImageInfo& genInfo = generator->getInfo();
82 if (fInfo.dimensions() == genInfo.dimensions()) { 112 if (fInfo.dimensions() == genInfo.dimensions()) {
83 SkASSERT(fOrigin.x() == 0 && fOrigin.y() == 0); 113 SkASSERT(fOrigin.x() == 0 && fOrigin.y() == 0);
84 // fast-case, no copy needed 114 // fast-case, no copy needed
85 if (!generator->getPixels(bitmap->info(), bitmap->getPixels(), rowBytes) ) { 115 return generate_a_bitmap(bitmap, generator, fInfo);
86 bitmap->reset(); 116 } else {
117 // need to handle subsetting, so we first generate the full size version , and then
118 // "read" from it to get our subset. See skbug.com/4213
119
120 SkBitmap full;
121 if (!generate_a_bitmap(&full, generator, genInfo)) {
87 return false; 122 return false;
88 } 123 }
89 } else { 124 if (!bitmap->tryAllocPixels(fInfo, nullptr, full.getColorTable())) {
90 // need to handle subsetting
91 SkBitmap full;
92 if (!full.tryAllocPixels(genInfo)) {
93 return false; 125 return false;
94 } 126 }
95 if (!generator->getPixels(full.info(), full.getPixels(), full.rowBytes() )) { 127 return full.readPixels(bitmap->info(), bitmap->getPixels(), bitmap->rowB ytes(),
96 bitmap->reset(); 128 fOrigin.x(), fOrigin.y());
97 return false;
98 }
99 full.readPixels(bitmap->info(), bitmap->getPixels(), bitmap->rowBytes(),
100 fOrigin.x(), fOrigin.y());
101 } 129 }
102 return true;
103 } 130 }
104 131
105 //////////////////////////////////////////////////////////////////////////////// ////////////////// 132 //////////////////////////////////////////////////////////////////////////////// //////////////////
106 133
107 bool SkImageCacherator::tryLockAsBitmap(SkBitmap* bitmap) { 134 bool SkImageCacherator::tryLockAsBitmap(SkBitmap* bitmap) {
108 if (SkBitmapCache::Find(fUniqueID, bitmap)) { 135 if (SkBitmapCache::Find(fUniqueID, bitmap)) {
109 return check_output_bitmap(*bitmap, fUniqueID); 136 return check_output_bitmap(*bitmap, fUniqueID);
110 } 137 }
111 138
112 if (!this->generateBitmap(bitmap)) { 139 if (!this->generateBitmap(bitmap)) {
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 // 5. Ask the generator to return RGB(A) data, which the GPU can convert 293 // 5. Ask the generator to return RGB(A) data, which the GPU can convert
267 SkBitmap bitmap; 294 SkBitmap bitmap;
268 if (this->generateBitmap(&bitmap)) { 295 if (this->generateBitmap(&bitmap)) {
269 return GrRefCachedBitmapTexture(ctx, bitmap, usage); 296 return GrRefCachedBitmapTexture(ctx, bitmap, usage);
270 } 297 }
271 #endif 298 #endif
272 299
273 return nullptr; 300 return nullptr;
274 } 301 }
275 302
OLDNEW
« no previous file with comments | « gm/image_pict.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698