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

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

Issue 1310633006: Add a SkPixelSerializer SkImage encode variant (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: moar comment tweaks 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 | « src/core/SkWriteBuffer.cpp ('k') | tests/ImageTest.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 "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkData.h" 10 #include "SkData.h"
11 #include "SkImageGenerator.h" 11 #include "SkImageGenerator.h"
12 #include "SkImagePriv.h" 12 #include "SkImagePriv.h"
13 #include "SkImage_Base.h" 13 #include "SkImage_Base.h"
14 #include "SkNextID.h" 14 #include "SkNextID.h"
15 #include "SkPixelRef.h" 15 #include "SkPixelRef.h"
16 #include "SkPixelSerializer.h"
16 #include "SkReadPixelsRec.h" 17 #include "SkReadPixelsRec.h"
17 #include "SkString.h" 18 #include "SkString.h"
18 #include "SkSurface.h" 19 #include "SkSurface.h"
19 20
20 #if SK_SUPPORT_GPU 21 #if SK_SUPPORT_GPU
21 #include "GrTexture.h" 22 #include "GrTexture.h"
22 #include "GrContext.h" 23 #include "GrContext.h"
23 #include "SkImage_Gpu.h" 24 #include "SkImage_Gpu.h"
24 #endif 25 #endif
25 26
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 } 65 }
65 66
66 SkData* SkImage::encode(SkImageEncoder::Type type, int quality) const { 67 SkData* SkImage::encode(SkImageEncoder::Type type, int quality) const {
67 SkBitmap bm; 68 SkBitmap bm;
68 if (as_IB(this)->getROPixels(&bm)) { 69 if (as_IB(this)->getROPixels(&bm)) {
69 return SkImageEncoder::EncodeData(bm, type, quality); 70 return SkImageEncoder::EncodeData(bm, type, quality);
70 } 71 }
71 return nullptr; 72 return nullptr;
72 } 73 }
73 74
75 namespace {
76
77 class DefaultSerializer : public SkPixelSerializer {
78 protected:
79 bool onUseEncodedData(const void *data, size_t len) override {
80 return true;
81 }
82
83 SkData* onEncodePixels(const SkImageInfo& info, const void* pixels, size_t r owBytes) override {
84 return SkImageEncoder::EncodeData(info, pixels, rowBytes, SkImageEncoder ::kPNG_Type, 100);
85 }
86 };
87
88 } // anonymous namespace
89
90 SkData* SkImage::encode(SkPixelSerializer* serializer) const {
91 DefaultSerializer defaultSerializer;
92 SkPixelSerializer* effectiveSerializer = serializer ? serializer : &defaultS erializer;
93
94 SkAutoTUnref<SkData> encoded(this->refEncoded());
95 if (encoded && effectiveSerializer->useEncodedData(encoded->data(), encoded- >size())) {
96 return encoded.detach();
97 }
98
99 SkBitmap bm;
100 SkAutoPixmapUnlock apu;
101 if (as_IB(this)->getROPixels(&bm) && bm.requestLock(&apu)) {
102 const SkPixmap& pmap = apu.pixmap();
103 return effectiveSerializer->encodePixels(pmap.info(), pmap.addr(), pmap. rowBytes());
104 }
105
106 return nullptr;
107 }
108
74 SkData* SkImage::refEncoded() const { 109 SkData* SkImage::refEncoded() const {
75 return as_IB(this)->onRefEncoded(); 110 return as_IB(this)->onRefEncoded();
76 } 111 }
77 112
78 SkImage* SkImage::NewFromEncoded(SkData* encoded, const SkIRect* subset) { 113 SkImage* SkImage::NewFromEncoded(SkData* encoded, const SkIRect* subset) {
79 if (nullptr == encoded || 0 == encoded->size()) { 114 if (nullptr == encoded || 0 == encoded->size()) {
80 return nullptr; 115 return nullptr;
81 } 116 }
82 SkImageGenerator* generator = SkImageGenerator::NewFromEncoded(encoded); 117 SkImageGenerator* generator = SkImageGenerator::NewFromEncoded(encoded);
83 return generator ? SkImage::NewFromGenerator(generator, subset) : nullptr; 118 return generator ? SkImage::NewFromGenerator(generator, subset) : nullptr;
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 341
307 SkImage* SkImage::NewFromAdoptedTexture(GrContext*, const GrBackendTextureDesc&, SkAlphaType) { 342 SkImage* SkImage::NewFromAdoptedTexture(GrContext*, const GrBackendTextureDesc&, SkAlphaType) {
308 return nullptr; 343 return nullptr;
309 } 344 }
310 345
311 SkImage* SkImage::NewFromTextureCopy(GrContext*, const GrBackendTextureDesc&, Sk AlphaType) { 346 SkImage* SkImage::NewFromTextureCopy(GrContext*, const GrBackendTextureDesc&, Sk AlphaType) {
312 return nullptr; 347 return nullptr;
313 } 348 }
314 349
315 #endif 350 #endif
OLDNEW
« no previous file with comments | « src/core/SkWriteBuffer.cpp ('k') | tests/ImageTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698