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

Side by Side Diff: src/image/SkImage.cpp

Issue 1507123002: default SkPixelSerializer (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-12-10 (Thursday) 13:15:57 EST Created 5 years 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 | « include/core/SkImageEncoder.h ('k') | src/images/SkImageEncoder.cpp » ('j') | 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 2012 Google Inc. 2 * Copyright 2012 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 "SkCanvas.h" 10 #include "SkCanvas.h"
11 #include "SkData.h" 11 #include "SkData.h"
12 #include "SkImageEncoder.h"
12 #include "SkImageGenerator.h" 13 #include "SkImageGenerator.h"
13 #include "SkImagePriv.h" 14 #include "SkImagePriv.h"
14 #include "SkImageShader.h" 15 #include "SkImageShader.h"
15 #include "SkImage_Base.h" 16 #include "SkImage_Base.h"
16 #include "SkNextID.h" 17 #include "SkNextID.h"
17 #include "SkPixelRef.h" 18 #include "SkPixelRef.h"
18 #include "SkPixelSerializer.h" 19 #include "SkPixelSerializer.h"
19 #include "SkReadPixelsRec.h" 20 #include "SkReadPixelsRec.h"
20 #include "SkString.h" 21 #include "SkString.h"
21 #include "SkSurface.h" 22 #include "SkSurface.h"
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 } 172 }
172 173
173 SkData* SkImage::encode(SkImageEncoder::Type type, int quality) const { 174 SkData* SkImage::encode(SkImageEncoder::Type type, int quality) const {
174 SkBitmap bm; 175 SkBitmap bm;
175 if (as_IB(this)->getROPixels(&bm)) { 176 if (as_IB(this)->getROPixels(&bm)) {
176 return SkImageEncoder::EncodeData(bm, type, quality); 177 return SkImageEncoder::EncodeData(bm, type, quality);
177 } 178 }
178 return nullptr; 179 return nullptr;
179 } 180 }
180 181
181 namespace { 182 SkData* SkImage::encode(SkPixelSerializer* serializer) const {
182 183 SkAutoTUnref<SkPixelSerializer> defaultSerializer;
183 class DefaultSerializer : public SkPixelSerializer { 184 SkPixelSerializer* effectiveSerializer = serializer;
184 protected: 185 if (!effectiveSerializer) {
185 bool onUseEncodedData(const void *data, size_t len) override { 186 defaultSerializer.reset(SkImageEncoder::CreatePixelSerializer());
186 return true; 187 SkASSERT(defaultSerializer.get());
188 effectiveSerializer = defaultSerializer.get();
187 } 189 }
188 SkData* onEncode(const SkPixmap& pixmap) override {
189 SkBitmap bm;
190 if (!bm.installPixels(pixmap.info(),
191 const_cast<void*>(pixmap.addr()),
192 pixmap.rowBytes(),
193 pixmap.ctable(),
194 nullptr, nullptr)) {
195 return nullptr;
196 }
197 return SkImageEncoder::EncodeData(bm, SkImageEncoder::kPNG_Type, 100);
198 }
199 };
200
201 } // anonymous namespace
202
203 SkData* SkImage::encode(SkPixelSerializer* serializer) const {
204 DefaultSerializer defaultSerializer;
205 SkPixelSerializer* effectiveSerializer = serializer ? serializer : &defaultS erializer;
206
207 SkAutoTUnref<SkData> encoded(this->refEncoded()); 190 SkAutoTUnref<SkData> encoded(this->refEncoded());
208 if (encoded && effectiveSerializer->useEncodedData(encoded->data(), encoded- >size())) { 191 if (encoded && effectiveSerializer->useEncodedData(encoded->data(), encoded- >size())) {
209 return encoded.detach(); 192 return encoded.detach();
210 } 193 }
211 194
212 SkBitmap bm; 195 SkBitmap bm;
213 SkAutoPixmapUnlock apu; 196 SkAutoPixmapUnlock apu;
214 if (as_IB(this)->getROPixels(&bm) && bm.requestLock(&apu)) { 197 if (as_IB(this)->getROPixels(&bm) && bm.requestLock(&apu)) {
215 return effectiveSerializer->encode(apu.pixmap()); 198 return effectiveSerializer->encode(apu.pixmap());
216 } 199 }
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 406
424 SkImage* SkImage::NewFromAdoptedTexture(GrContext*, const GrBackendTextureDesc&, SkAlphaType) { 407 SkImage* SkImage::NewFromAdoptedTexture(GrContext*, const GrBackendTextureDesc&, SkAlphaType) {
425 return nullptr; 408 return nullptr;
426 } 409 }
427 410
428 SkImage* SkImage::NewFromTextureCopy(GrContext*, const GrBackendTextureDesc&, Sk AlphaType) { 411 SkImage* SkImage::NewFromTextureCopy(GrContext*, const GrBackendTextureDesc&, Sk AlphaType) {
429 return nullptr; 412 return nullptr;
430 } 413 }
431 414
432 #endif 415 #endif
OLDNEW
« no previous file with comments | « include/core/SkImageEncoder.h ('k') | src/images/SkImageEncoder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698