OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "SkColorPriv.h" | 8 #include "SkColorPriv.h" |
9 #include "SkImageDecoder.h" | 9 #include "SkImageDecoder.h" |
10 #include "SkPixelRef.h" | 10 #include "SkPixelRef.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 // | 29 // |
30 // This decoder is meant to be used with an SkDiscardablePixelRef so that GPU ba
ckends | 30 // This decoder is meant to be used with an SkDiscardablePixelRef so that GPU ba
ckends |
31 // can sniff the data before creating a texture. If they encounter a compressed
format | 31 // can sniff the data before creating a texture. If they encounter a compressed
format |
32 // that they understand, they can then upload the data directly to the GPU. Othe
rwise, | 32 // that they understand, they can then upload the data directly to the GPU. Othe
rwise, |
33 // they will decode the data into a format that Skia supports. | 33 // they will decode the data into a format that Skia supports. |
34 | 34 |
35 class SkKTXImageDecoder : public SkImageDecoder { | 35 class SkKTXImageDecoder : public SkImageDecoder { |
36 public: | 36 public: |
37 SkKTXImageDecoder() { } | 37 SkKTXImageDecoder() { } |
38 | 38 |
39 Format getFormat() const SK_OVERRIDE { | 39 Format getFormat() const override { |
40 return kKTX_Format; | 40 return kKTX_Format; |
41 } | 41 } |
42 | 42 |
43 protected: | 43 protected: |
44 Result onDecode(SkStream* stream, SkBitmap* bm, Mode) SK_OVERRIDE; | 44 Result onDecode(SkStream* stream, SkBitmap* bm, Mode) override; |
45 | 45 |
46 private: | 46 private: |
47 typedef SkImageDecoder INHERITED; | 47 typedef SkImageDecoder INHERITED; |
48 }; | 48 }; |
49 | 49 |
50 SkImageDecoder::Result SkKTXImageDecoder::onDecode(SkStream* stream, SkBitmap* b
m, Mode mode) { | 50 SkImageDecoder::Result SkKTXImageDecoder::onDecode(SkStream* stream, SkBitmap* b
m, Mode mode) { |
51 // TODO: Implement SkStream::copyToData() that's cheap for memory and file s
treams | 51 // TODO: Implement SkStream::copyToData() that's cheap for memory and file s
treams |
52 SkAutoDataUnref data(SkCopyStreamToData(stream)); | 52 SkAutoDataUnref data(SkCopyStreamToData(stream)); |
53 if (NULL == data) { | 53 if (NULL == data) { |
54 return kFailure; | 54 return kFailure; |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 // there is an installed discardable pixel ref with existing PKM data, then we | 244 // there is an installed discardable pixel ref with existing PKM data, then we |
245 // will repurpose the existing ETC1 data into a KTX file. If the data contains | 245 // will repurpose the existing ETC1 data into a KTX file. If the data contains |
246 // KTX data, then we simply return a copy of the same data. For all other files, | 246 // KTX data, then we simply return a copy of the same data. For all other files, |
247 // the underlying KTX library tries to do its best to encode the appropriate | 247 // the underlying KTX library tries to do its best to encode the appropriate |
248 // data specified by the bitmap based on the config. (i.e. kAlpha8_Config will | 248 // data specified by the bitmap based on the config. (i.e. kAlpha8_Config will |
249 // be represented as a full resolution 8-bit image dump with the appropriate | 249 // be represented as a full resolution 8-bit image dump with the appropriate |
250 // OpenGL defines in the header). | 250 // OpenGL defines in the header). |
251 | 251 |
252 class SkKTXImageEncoder : public SkImageEncoder { | 252 class SkKTXImageEncoder : public SkImageEncoder { |
253 protected: | 253 protected: |
254 bool onEncode(SkWStream* stream, const SkBitmap& bm, int quality) SK_OVERRID
E; | 254 bool onEncode(SkWStream* stream, const SkBitmap& bm, int quality) override; |
255 | 255 |
256 private: | 256 private: |
257 virtual bool encodePKM(SkWStream* stream, const SkData *data); | 257 virtual bool encodePKM(SkWStream* stream, const SkData *data); |
258 typedef SkImageEncoder INHERITED; | 258 typedef SkImageEncoder INHERITED; |
259 }; | 259 }; |
260 | 260 |
261 bool SkKTXImageEncoder::onEncode(SkWStream* stream, const SkBitmap& bitmap, int)
{ | 261 bool SkKTXImageEncoder::onEncode(SkWStream* stream, const SkBitmap& bitmap, int)
{ |
262 if (!bitmap.pixelRef()) { | 262 if (!bitmap.pixelRef()) { |
263 return false; | 263 return false; |
264 } | 264 } |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 return SkImageDecoder::kUnknown_Format; | 321 return SkImageDecoder::kUnknown_Format; |
322 } | 322 } |
323 | 323 |
324 SkImageEncoder* sk_libktx_efactory(SkImageEncoder::Type t) { | 324 SkImageEncoder* sk_libktx_efactory(SkImageEncoder::Type t) { |
325 return (SkImageEncoder::kKTX_Type == t) ? SkNEW(SkKTXImageEncoder) : NULL; | 325 return (SkImageEncoder::kKTX_Type == t) ? SkNEW(SkKTXImageEncoder) : NULL; |
326 } | 326 } |
327 | 327 |
328 static SkImageDecoder_DecodeReg gReg(sk_libktx_dfactory); | 328 static SkImageDecoder_DecodeReg gReg(sk_libktx_dfactory); |
329 static SkImageDecoder_FormatReg gFormatReg(get_format_ktx); | 329 static SkImageDecoder_FormatReg gFormatReg(get_format_ktx); |
330 static SkImageEncoder_EncodeReg gEReg(sk_libktx_efactory); | 330 static SkImageEncoder_EncodeReg gEReg(sk_libktx_efactory); |
OLD | NEW |