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 #ifndef SkPixelSerializer_DEFINED | 8 #ifndef SkPixelSerializer_DEFINED |
9 #define SkPixelSerializer_DEFINED | 9 #define SkPixelSerializer_DEFINED |
10 | 10 |
11 #include "SkData.h" | |
12 #include "SkPixmap.h" | |
13 #include "SkRefCnt.h" | 11 #include "SkRefCnt.h" |
14 | 12 |
| 13 class SkData; |
15 struct SkImageInfo; | 14 struct SkImageInfo; |
16 | 15 |
17 /** | 16 /** |
18 * Interface for serializing pixels, e.g. SkBitmaps in an SkPicture. | 17 * Interface for serializing pixels, e.g. SkBitmaps in an SkPicture. |
19 */ | 18 */ |
20 class SkPixelSerializer : public SkRefCnt { | 19 class SkPixelSerializer : public SkRefCnt { |
21 public: | 20 public: |
| 21 virtual ~SkPixelSerializer() {} |
| 22 |
22 /** | 23 /** |
23 * Call to determine if the client wants to serialize the encoded data. | 24 * Call to determine if the client wants to serialize the encoded data. If |
24 * | 25 * false, serialize another version (e.g. the result of encodePixels). |
25 * If the encoded data is can be re-encoded (or taken as is), this returns
a ref to a data | |
26 * with the result, which the caller must unref() when they are through. Th
e returned | |
27 * data may be the same as the input, or it may be different, but either wa
y the caller is | |
28 * responsible for calling unref() on it. | |
29 * | |
30 * If the encoded data is not acceptable to this pixel serializer, this ret
urns NULL. | |
31 */ | 26 */ |
32 SkData* reencodeData(SkData* encoded); | 27 bool useEncodedData(const void* data, size_t len) { |
| 28 return this->onUseEncodedData(data, len); |
| 29 } |
33 | 30 |
34 /** | 31 /** |
35 * Call to get the client's version of encoding these pixels. If it | 32 * Call to get the client's version of encoding these pixels. If it |
36 * returns NULL, serialize the raw pixels. | 33 * returns NULL, serialize the raw pixels. |
37 */ | 34 */ |
38 SkData* encodePixels(const SkImageInfo& info, const void* pixels, size_t row
Bytes); | 35 SkData* encodePixels(const SkImageInfo& info, const void* pixels, size_t row
Bytes) { |
| 36 return this->onEncodePixels(info, pixels, rowBytes); |
| 37 } |
| 38 |
| 39 protected: |
| 40 /** |
| 41 * Return true if you want to serialize the encoded data, false if you want |
| 42 * another version serialized (e.g. the result of encodePixels). |
| 43 */ |
| 44 virtual bool onUseEncodedData(const void* data, size_t len) = 0; |
39 | 45 |
40 /** | 46 /** |
41 * Call to get the client's version of encoding these pixels. If it | 47 * If you want to encode these pixels, return the encoded data as an SkData |
42 * returns NULL, serialize the raw pixels. | 48 * Return null if you want to serialize the raw pixels. |
43 */ | 49 */ |
44 SkData* encodePixels(const SkPixmap& pixmap); | |
45 | |
46 protected: | |
47 // DEPRECATED -- this is no longer called, so remove from your subclasses! | |
48 virtual bool onUseEncodedData(const void*, size_t) { return true; } | |
49 | |
50 virtual SkData* onReencodeData(SkData* encoded) { | |
51 return SkRef(encoded); | |
52 } | |
53 | |
54 virtual SkData* onEncodePixels(const SkImageInfo&, const void* pixels, size_
t rowBytes) = 0; | 50 virtual SkData* onEncodePixels(const SkImageInfo&, const void* pixels, size_
t rowBytes) = 0; |
55 }; | 51 }; |
56 #endif // SkPixelSerializer_DEFINED | 52 #endif // SkPixelSerializer_DEFINED |
OLD | NEW |