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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |
77 SkBitmap bm; | 85 SkBitmap bm; |
78 if (as_IB(this)->getROPixels(&bm)) { | 86 if (as_IB(this)->getROPixels(&bm)) { |
79 return SkImageEncoder::EncodeData(bm, type, quality); | 87 return SkImageEncoder::EncodeData(bm, type, quality); |
80 } | 88 } |
81 return nullptr; | 89 return nullptr; |
82 } | 90 } |
83 | 91 |
84 namespace { | 92 namespace { |
85 | 93 |
86 class DefaultSerializer : public SkPixelSerializer { | 94 class DefaultSerializer : public SkPixelSerializer { |
87 protected: | 95 protected: |
88 bool onUseEncodedData(const void *data, size_t len) override { | |
89 return true; | |
90 } | |
91 | |
92 SkData* onEncodePixels(const SkImageInfo& info, const void* pixels, size_t r
owBytes) override { | 96 SkData* onEncodePixels(const SkImageInfo& info, const void* pixels, size_t r
owBytes) override { |
93 return SkImageEncoder::EncodeData(info, pixels, rowBytes, SkImageEncoder
::kPNG_Type, 100); | 97 return SkImageEncoder::EncodeData(info, pixels, rowBytes, SkImageEncoder
::kPNG_Type, 100); |
94 } | 98 } |
95 }; | 99 }; |
96 | 100 |
97 } // anonymous namespace | 101 } // anonymous namespace |
98 | 102 |
99 SkData* SkImage::encode(SkPixelSerializer* serializer) const { | 103 SkData* SkImage::encode(SkPixelSerializer* serializer) const { |
100 DefaultSerializer defaultSerializer; | 104 DefaultSerializer defaultSerializer; |
101 SkPixelSerializer* effectiveSerializer = serializer ? serializer : &defaultS
erializer; | 105 SkPixelSerializer* effectiveSerializer = serializer ? serializer : &defaultS
erializer; |
102 | 106 |
103 SkAutoTUnref<SkData> encoded(this->refEncoded()); | 107 SkAutoTUnref<SkData> encoded(this->refEncoded()); |
104 if (encoded && effectiveSerializer->useEncodedData(encoded->data(), encoded-
>size())) { | 108 if (encoded) { |
105 return encoded.detach(); | 109 encoded.reset(effectiveSerializer->reencodeData(encoded)); |
| 110 if (encoded) { |
| 111 return encoded.detach(); |
| 112 } |
106 } | 113 } |
107 | 114 |
108 SkBitmap bm; | 115 SkBitmap bm; |
109 SkAutoPixmapUnlock apu; | 116 SkAutoPixmapUnlock apu; |
110 if (as_IB(this)->getROPixels(&bm) && bm.requestLock(&apu)) { | 117 if (as_IB(this)->getROPixels(&bm) && bm.requestLock(&apu)) { |
111 const SkPixmap& pmap = apu.pixmap(); | 118 return effectiveSerializer->encodePixels(apu.pixmap()); |
112 return effectiveSerializer->encodePixels(pmap.info(), pmap.addr(), pmap.
rowBytes()); | |
113 } | 119 } |
114 | 120 |
115 return nullptr; | 121 return nullptr; |
116 } | 122 } |
117 | 123 |
118 SkData* SkImage::refEncoded() const { | 124 SkData* SkImage::refEncoded() const { |
119 return as_IB(this)->onRefEncoded(); | 125 return as_IB(this)->onRefEncoded(); |
120 } | 126 } |
121 | 127 |
122 SkImage* SkImage::NewFromEncoded(SkData* encoded, const SkIRect* subset) { | 128 SkImage* SkImage::NewFromEncoded(SkData* encoded, const SkIRect* subset) { |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 | 331 |
326 SkImage* SkImage::NewFromAdoptedTexture(GrContext*, const GrBackendTextureDesc&,
SkAlphaType) { | 332 SkImage* SkImage::NewFromAdoptedTexture(GrContext*, const GrBackendTextureDesc&,
SkAlphaType) { |
327 return nullptr; | 333 return nullptr; |
328 } | 334 } |
329 | 335 |
330 SkImage* SkImage::NewFromTextureCopy(GrContext*, const GrBackendTextureDesc&, Sk
AlphaType) { | 336 SkImage* SkImage::NewFromTextureCopy(GrContext*, const GrBackendTextureDesc&, Sk
AlphaType) { |
331 return nullptr; | 337 return nullptr; |
332 } | 338 } |
333 | 339 |
334 #endif | 340 #endif |
OLD | NEW |