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

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

Issue 1511183002: Revert of default SkPixelSerializer (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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"
13 #include "SkImageGenerator.h" 12 #include "SkImageGenerator.h"
14 #include "SkImagePriv.h" 13 #include "SkImagePriv.h"
15 #include "SkImageShader.h" 14 #include "SkImageShader.h"
16 #include "SkImage_Base.h" 15 #include "SkImage_Base.h"
17 #include "SkNextID.h" 16 #include "SkNextID.h"
18 #include "SkPixelRef.h" 17 #include "SkPixelRef.h"
19 #include "SkPixelSerializer.h" 18 #include "SkPixelSerializer.h"
20 #include "SkReadPixelsRec.h" 19 #include "SkReadPixelsRec.h"
21 #include "SkString.h" 20 #include "SkString.h"
22 #include "SkSurface.h" 21 #include "SkSurface.h"
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 } 171 }
173 172
174 SkData* SkImage::encode(SkImageEncoder::Type type, int quality) const { 173 SkData* SkImage::encode(SkImageEncoder::Type type, int quality) const {
175 SkBitmap bm; 174 SkBitmap bm;
176 if (as_IB(this)->getROPixels(&bm)) { 175 if (as_IB(this)->getROPixels(&bm)) {
177 return SkImageEncoder::EncodeData(bm, type, quality); 176 return SkImageEncoder::EncodeData(bm, type, quality);
178 } 177 }
179 return nullptr; 178 return nullptr;
180 } 179 }
181 180
181 namespace {
182
183 class DefaultSerializer : public SkPixelSerializer {
184 protected:
185 bool onUseEncodedData(const void *data, size_t len) override {
186 return true;
187 }
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
182 SkData* SkImage::encode(SkPixelSerializer* serializer) const { 203 SkData* SkImage::encode(SkPixelSerializer* serializer) const {
183 SkAutoTUnref<SkPixelSerializer> defaultSerializer; 204 DefaultSerializer defaultSerializer;
184 SkPixelSerializer* effectiveSerializer = serializer; 205 SkPixelSerializer* effectiveSerializer = serializer ? serializer : &defaultS erializer;
185 if (!effectiveSerializer) { 206
186 defaultSerializer.reset(SkImageEncoder::CreatePixelSerializer());
187 SkASSERT(defaultSerializer.get());
188 effectiveSerializer = defaultSerializer.get();
189 }
190 SkAutoTUnref<SkData> encoded(this->refEncoded()); 207 SkAutoTUnref<SkData> encoded(this->refEncoded());
191 if (encoded && effectiveSerializer->useEncodedData(encoded->data(), encoded- >size())) { 208 if (encoded && effectiveSerializer->useEncodedData(encoded->data(), encoded- >size())) {
192 return encoded.detach(); 209 return encoded.detach();
193 } 210 }
194 211
195 SkBitmap bm; 212 SkBitmap bm;
196 SkAutoPixmapUnlock apu; 213 SkAutoPixmapUnlock apu;
197 if (as_IB(this)->getROPixels(&bm) && bm.requestLock(&apu)) { 214 if (as_IB(this)->getROPixels(&bm) && bm.requestLock(&apu)) {
198 return effectiveSerializer->encode(apu.pixmap()); 215 return effectiveSerializer->encode(apu.pixmap());
199 } 216 }
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 423
407 SkImage* SkImage::NewFromAdoptedTexture(GrContext*, const GrBackendTextureDesc&, SkAlphaType) { 424 SkImage* SkImage::NewFromAdoptedTexture(GrContext*, const GrBackendTextureDesc&, SkAlphaType) {
408 return nullptr; 425 return nullptr;
409 } 426 }
410 427
411 SkImage* SkImage::NewFromTextureCopy(GrContext*, const GrBackendTextureDesc&, Sk AlphaType) { 428 SkImage* SkImage::NewFromTextureCopy(GrContext*, const GrBackendTextureDesc&, Sk AlphaType) {
412 return nullptr; 429 return nullptr;
413 } 430 }
414 431
415 #endif 432 #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