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

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

Issue 1371983003: Revert of change pixel-serializer to support reencoding existing data (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 2 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') | src/images/SkImageDecoder_ktx.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"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 } 67 }
68 } 68 }
69 69
70 SkShader* SkImage::newShader(SkShader::TileMode tileX, 70 SkShader* SkImage::newShader(SkShader::TileMode tileX,
71 SkShader::TileMode tileY, 71 SkShader::TileMode tileY,
72 const SkMatrix* localMatrix) const { 72 const SkMatrix* localMatrix) const {
73 return SkImageShader::Create(this, tileX, tileY, localMatrix); 73 return SkImageShader::Create(this, tileX, tileY, localMatrix);
74 } 74 }
75 75
76 SkData* SkImage::encode(SkImageEncoder::Type type, int quality) const { 76 SkData* SkImage::encode(SkImageEncoder::Type type, int quality) const {
77 SkAutoDataUnref encoded(this->refEncoded());
78 if (encoded) {
79 SkAutoDataUnref reencoded(SkImageEncoder::ReencodeData(encoded, type));
80 if (reencoded) {
81 return reencoded.detach();
82 }
83 }
84
85 SkBitmap bm; 77 SkBitmap bm;
86 if (as_IB(this)->getROPixels(&bm)) { 78 if (as_IB(this)->getROPixels(&bm)) {
87 return SkImageEncoder::EncodeData(bm, type, quality); 79 return SkImageEncoder::EncodeData(bm, type, quality);
88 } 80 }
89 return nullptr; 81 return nullptr;
90 } 82 }
91 83
92 namespace { 84 namespace {
93 85
94 class DefaultSerializer : public SkPixelSerializer { 86 class DefaultSerializer : public SkPixelSerializer {
95 protected: 87 protected:
88 bool onUseEncodedData(const void *data, size_t len) override {
89 return true;
90 }
91
96 SkData* onEncodePixels(const SkImageInfo& info, const void* pixels, size_t r owBytes) override { 92 SkData* onEncodePixels(const SkImageInfo& info, const void* pixels, size_t r owBytes) override {
97 return SkImageEncoder::EncodeData(info, pixels, rowBytes, SkImageEncoder ::kPNG_Type, 100); 93 return SkImageEncoder::EncodeData(info, pixels, rowBytes, SkImageEncoder ::kPNG_Type, 100);
98 } 94 }
99 }; 95 };
100 96
101 } // anonymous namespace 97 } // anonymous namespace
102 98
103 SkData* SkImage::encode(SkPixelSerializer* serializer) const { 99 SkData* SkImage::encode(SkPixelSerializer* serializer) const {
104 DefaultSerializer defaultSerializer; 100 DefaultSerializer defaultSerializer;
105 SkPixelSerializer* effectiveSerializer = serializer ? serializer : &defaultS erializer; 101 SkPixelSerializer* effectiveSerializer = serializer ? serializer : &defaultS erializer;
106 102
107 SkAutoTUnref<SkData> encoded(this->refEncoded()); 103 SkAutoTUnref<SkData> encoded(this->refEncoded());
108 if (encoded) { 104 if (encoded && effectiveSerializer->useEncodedData(encoded->data(), encoded- >size())) {
109 encoded.reset(effectiveSerializer->reencodeData(encoded)); 105 return encoded.detach();
110 if (encoded) {
111 return encoded.detach();
112 }
113 } 106 }
114 107
115 SkBitmap bm; 108 SkBitmap bm;
116 SkAutoPixmapUnlock apu; 109 SkAutoPixmapUnlock apu;
117 if (as_IB(this)->getROPixels(&bm) && bm.requestLock(&apu)) { 110 if (as_IB(this)->getROPixels(&bm) && bm.requestLock(&apu)) {
118 return effectiveSerializer->encodePixels(apu.pixmap()); 111 const SkPixmap& pmap = apu.pixmap();
112 return effectiveSerializer->encodePixels(pmap.info(), pmap.addr(), pmap. rowBytes());
119 } 113 }
120 114
121 return nullptr; 115 return nullptr;
122 } 116 }
123 117
124 SkData* SkImage::refEncoded() const { 118 SkData* SkImage::refEncoded() const {
125 return as_IB(this)->onRefEncoded(); 119 return as_IB(this)->onRefEncoded();
126 } 120 }
127 121
128 SkImage* SkImage::NewFromEncoded(SkData* encoded, const SkIRect* subset) { 122 SkImage* SkImage::NewFromEncoded(SkData* encoded, const SkIRect* subset) {
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 325
332 SkImage* SkImage::NewFromAdoptedTexture(GrContext*, const GrBackendTextureDesc&, SkAlphaType) { 326 SkImage* SkImage::NewFromAdoptedTexture(GrContext*, const GrBackendTextureDesc&, SkAlphaType) {
333 return nullptr; 327 return nullptr;
334 } 328 }
335 329
336 SkImage* SkImage::NewFromTextureCopy(GrContext*, const GrBackendTextureDesc&, Sk AlphaType) { 330 SkImage* SkImage::NewFromTextureCopy(GrContext*, const GrBackendTextureDesc&, Sk AlphaType) {
337 return nullptr; 331 return nullptr;
338 } 332 }
339 333
340 #endif 334 #endif
OLDNEW
« no previous file with comments | « src/core/SkWriteBuffer.cpp ('k') | src/images/SkImageDecoder_ktx.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698