Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(296)

Side by Side Diff: include/core/SkPixelSerializer.h

Issue 1373683003: change pixel-serializer to support reencoding existing data Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: removed another use of DEPRECATED discardable pixelref Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/core/SkImageEncoder.h ('k') | src/core/SkWriteBuffer.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "SkRefCnt.h" 13 #include "SkRefCnt.h"
12 14
13 class SkData;
14 struct SkImageInfo; 15 struct SkImageInfo;
15 16
16 /** 17 /**
17 * Interface for serializing pixels, e.g. SkBitmaps in an SkPicture. 18 * Interface for serializing pixels, e.g. SkBitmaps in an SkPicture.
18 */ 19 */
19 class SkPixelSerializer : public SkRefCnt { 20 class SkPixelSerializer : public SkRefCnt {
20 public: 21 public:
21 virtual ~SkPixelSerializer() {}
22
23 /** 22 /**
24 * Call to determine if the client wants to serialize the encoded data. If 23 * Call to determine if the client wants to serialize the encoded data.
25 * false, serialize another version (e.g. the result of encodePixels). 24 *
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.
26 */ 31 */
27 bool useEncodedData(const void* data, size_t len) { 32 SkData* reencodeData(SkData* encoded) {
28 return this->onUseEncodedData(data, len); 33 return encoded ? this->onReencodeData(encoded) : nullptr;
29 } 34 }
30 35
31 /** 36 /**
32 * Call to get the client's version of encoding these pixels. If it 37 * Call to get the client's version of encoding these pixels. If it
33 * returns NULL, serialize the raw pixels. 38 * returns NULL, serialize the raw pixels.
34 */ 39 */
35 SkData* encodePixels(const SkImageInfo& info, const void* pixels, size_t row Bytes) { 40 SkData* encodePixels(const SkImageInfo& info, const void* pixels, size_t row Bytes) {
36 return this->onEncodePixels(info, pixels, rowBytes); 41 return this->onEncodePixels(SkPixmap(info, pixels, rowBytes));
42 }
43
44 /**
45 * Call to get the client's version of encoding these pixels. If it
46 * returns NULL, serialize the raw pixels.
47 */
48 SkData* encodePixels(const SkPixmap& pixmap) {
49 return this->onEncodePixels(pixmap);
50 }
51
52 protected:
53 virtual SkData* onReencodeData(SkData* encoded) {
54 return SkRef(encoded);
37 } 55 }
38 56
39 protected: 57 virtual SkData* onEncodePixels(const SkPixmap&) = 0;
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;
scroggo 2015/09/28 13:34:10 We need to keep this around until we fix the chrom
45
46 /**
47 * If you want to encode these pixels, return the encoded data as an SkData
48 * Return null if you want to serialize the raw pixels.
49 */
50 virtual SkData* onEncodePixels(const SkImageInfo&, const void* pixels, size_ t rowBytes) = 0;
51 }; 58 };
52 #endif // SkPixelSerializer_DEFINED 59 #endif // SkPixelSerializer_DEFINED
OLDNEW
« no previous file with comments | « include/core/SkImageEncoder.h ('k') | src/core/SkWriteBuffer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698