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