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

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

Issue 1334033004: formalize generate->bitmap (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
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 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 "SkImageGenerator.h" 8 #include "SkImageGenerator.h"
9 #include "SkNextID.h" 9 #include "SkNextID.h"
10 10
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 return nullptr; 118 return nullptr;
119 } 119 }
120 120
121 bool SkImageGenerator::onGetPixels(const SkImageInfo& info, void* dst, size_t rb , 121 bool SkImageGenerator::onGetPixels(const SkImageInfo& info, void* dst, size_t rb ,
122 SkPMColor* colors, int* colorCount) { 122 SkPMColor* colors, int* colorCount) {
123 return false; 123 return false;
124 } 124 }
125 125
126 //////////////////////////////////////////////////////////////////////////////// /////////////////// 126 //////////////////////////////////////////////////////////////////////////////// ///////////////////
127 127
128 #include "SkBitmap.h"
129 #include "SkColorTable.h"
130
131 static void release_malloc_proc(void* pixels, void* ctx) {
132 sk_free(pixels);
133 }
134
135 bool SkImageGenerator::tryGenerateBitmap(SkBitmap* bitmap, const SkImageInfo* in foPtr) {
136 const SkImageInfo info = infoPtr ? *infoPtr : this->getInfo();
137 const size_t rowBytes = info.minRowBytes();
138 const size_t pixelSize = info.getSafeSize(rowBytes);
139 if (0 == pixelSize) {
140 return false;
141 }
142
143 SkAutoFree pixelStorage(sk_malloc_flags(pixelSize, 0));
144 void* pixels = pixelStorage.get();
145 if (!pixels) {
146 return false;
147 }
148
149 SkPMColor ctStorage[256];
150 int ctCount = 0;
151
152 if (!this->getPixels(info, pixels, rowBytes, ctStorage, &ctCount)) {
153 return false;
154 }
155
156 SkAutoTUnref<SkColorTable> ctable;
157 if (ctCount > 0) {
158 SkASSERT(kIndex_8_SkColorType == info.colorType());
159 ctable.reset(new SkColorTable(ctStorage, ctCount));
160 } else {
161 SkASSERT(kIndex_8_SkColorType != info.colorType());
162 }
163
164 return bitmap->installPixels(info, pixelStorage.detach(), rowBytes, ctable,
165 release_malloc_proc, nullptr);
166 }
167
128 #include "SkGraphics.h" 168 #include "SkGraphics.h"
129 169
130 static SkGraphics::ImageGeneratorFromEncodedFactory gFactory; 170 static SkGraphics::ImageGeneratorFromEncodedFactory gFactory;
131 171
132 SkGraphics::ImageGeneratorFromEncodedFactory 172 SkGraphics::ImageGeneratorFromEncodedFactory
133 SkGraphics::SetImageGeneratorFromEncodedFactory(ImageGeneratorFromEncodedFactory factory) 173 SkGraphics::SetImageGeneratorFromEncodedFactory(ImageGeneratorFromEncodedFactory factory)
134 { 174 {
135 ImageGeneratorFromEncodedFactory prev = gFactory; 175 ImageGeneratorFromEncodedFactory prev = gFactory;
136 gFactory = factory; 176 gFactory = factory;
137 return prev; 177 return prev;
138 } 178 }
139 179
140 SkImageGenerator* SkImageGenerator::NewFromEncoded(SkData* data) { 180 SkImageGenerator* SkImageGenerator::NewFromEncoded(SkData* data) {
141 if (nullptr == data) { 181 if (nullptr == data) {
142 return nullptr; 182 return nullptr;
143 } 183 }
144 if (gFactory) { 184 if (gFactory) {
145 if (SkImageGenerator* generator = gFactory(data)) { 185 if (SkImageGenerator* generator = gFactory(data)) {
146 return generator; 186 return generator;
147 } 187 }
148 } 188 }
149 return SkImageGenerator::NewFromEncodedImpl(data); 189 return SkImageGenerator::NewFromEncodedImpl(data);
150 } 190 }
OLDNEW
« no previous file with comments | « src/core/SkImageCacherator.cpp ('k') | tools/Resources.cpp » ('j') | tools/Resources.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698