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" |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 return nullptr; | 178 return nullptr; |
179 } | 179 } |
180 | 180 |
181 namespace { | 181 namespace { |
182 | 182 |
183 class DefaultSerializer : public SkPixelSerializer { | 183 class DefaultSerializer : public SkPixelSerializer { |
184 protected: | 184 protected: |
185 bool onUseEncodedData(const void *data, size_t len) override { | 185 bool onUseEncodedData(const void *data, size_t len) override { |
186 return true; | 186 return true; |
187 } | 187 } |
188 | 188 SkData* onEncode(const SkPixmap& pixmap) override { |
189 SkData* onEncodePixels(const SkImageInfo& info, const void* pixels, size_t r
owBytes) override { | 189 SkBitmap bm; |
190 return SkImageEncoder::EncodeData(info, pixels, rowBytes, SkImageEncoder
::kPNG_Type, 100); | 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); |
191 } | 198 } |
192 }; | 199 }; |
193 | 200 |
194 } // anonymous namespace | 201 } // anonymous namespace |
195 | 202 |
196 SkData* SkImage::encode(SkPixelSerializer* serializer) const { | 203 SkData* SkImage::encode(SkPixelSerializer* serializer) const { |
197 DefaultSerializer defaultSerializer; | 204 DefaultSerializer defaultSerializer; |
198 SkPixelSerializer* effectiveSerializer = serializer ? serializer : &defaultS
erializer; | 205 SkPixelSerializer* effectiveSerializer = serializer ? serializer : &defaultS
erializer; |
199 | 206 |
200 SkAutoTUnref<SkData> encoded(this->refEncoded()); | 207 SkAutoTUnref<SkData> encoded(this->refEncoded()); |
201 if (encoded && effectiveSerializer->useEncodedData(encoded->data(), encoded-
>size())) { | 208 if (encoded && effectiveSerializer->useEncodedData(encoded->data(), encoded-
>size())) { |
202 return encoded.detach(); | 209 return encoded.detach(); |
203 } | 210 } |
204 | 211 |
205 SkBitmap bm; | 212 SkBitmap bm; |
206 SkAutoPixmapUnlock apu; | 213 SkAutoPixmapUnlock apu; |
207 if (as_IB(this)->getROPixels(&bm) && bm.requestLock(&apu)) { | 214 if (as_IB(this)->getROPixels(&bm) && bm.requestLock(&apu)) { |
208 const SkPixmap& pmap = apu.pixmap(); | 215 return effectiveSerializer->encode(apu.pixmap()); |
209 return effectiveSerializer->encodePixels(pmap.info(), pmap.addr(), pmap.
rowBytes()); | |
210 } | 216 } |
211 | 217 |
212 return nullptr; | 218 return nullptr; |
213 } | 219 } |
214 | 220 |
215 SkData* SkImage::refEncoded() const { | 221 SkData* SkImage::refEncoded() const { |
216 return as_IB(this)->onRefEncoded(); | 222 return as_IB(this)->onRefEncoded(); |
217 } | 223 } |
218 | 224 |
219 SkImage* SkImage::NewFromEncoded(SkData* encoded, const SkIRect* subset) { | 225 SkImage* SkImage::NewFromEncoded(SkData* encoded, const SkIRect* subset) { |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 | 423 |
418 SkImage* SkImage::NewFromAdoptedTexture(GrContext*, const GrBackendTextureDesc&,
SkAlphaType) { | 424 SkImage* SkImage::NewFromAdoptedTexture(GrContext*, const GrBackendTextureDesc&,
SkAlphaType) { |
419 return nullptr; | 425 return nullptr; |
420 } | 426 } |
421 | 427 |
422 SkImage* SkImage::NewFromTextureCopy(GrContext*, const GrBackendTextureDesc&, Sk
AlphaType) { | 428 SkImage* SkImage::NewFromTextureCopy(GrContext*, const GrBackendTextureDesc&, Sk
AlphaType) { |
423 return nullptr; | 429 return nullptr; |
424 } | 430 } |
425 | 431 |
426 #endif | 432 #endif |
OLD | NEW |