OLD | NEW |
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 Loading... |
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 Loading... |
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 |
OLD | NEW |