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

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

Issue 1501303002: SkPixelSerializer: support indexed pixels (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-12-07 (Monday) 10:44:44 EST Created 5 years 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
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 "SkRefCnt.h" 11 #include "SkRefCnt.h"
12 #include "SkPixmap.h"
12 13
13 class SkData; 14 class SkData;
14 struct SkImageInfo;
15 15
16 /** 16 /**
17 * Interface for serializing pixels, e.g. SkBitmaps in an SkPicture. 17 * Interface for serializing pixels, e.g. SkBitmaps in an SkPicture.
18 */ 18 */
19 class SkPixelSerializer : public SkRefCnt { 19 class SkPixelSerializer : public SkRefCnt {
20 public: 20 public:
21 virtual ~SkPixelSerializer() {} 21 virtual ~SkPixelSerializer() {}
22 22
23 /** 23 /**
24 * Call to determine if the client wants to serialize the encoded data. If 24 * Call to determine if the client wants to serialize the encoded data. If
25 * false, serialize another version (e.g. the result of encodePixels). 25 * false, serialize another version (e.g. the result of encodePixels).
26 */ 26 */
27 bool useEncodedData(const void* data, size_t len) { 27 bool useEncodedData(const void* data, size_t len) {
28 return this->onUseEncodedData(data, len); 28 return this->onUseEncodedData(data, len);
29 } 29 }
30 30
31 /** 31 /**
32 * 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
33 * returns NULL, serialize the raw pixels. 33 * returns NULL, serialize the raw pixels.
34 */ 34 */
35 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) {
scroggo 2015/12/07 15:57:07 Does anyone call this other than SkWriteBuffer? Or
hal.canary 2015/12/07 20:25:01 done
36 return this->onEncodePixels(info, pixels, rowBytes); 36 return this->encode(SkPixmap(info, pixels, rowBytes, nullptr));
37 }
38
39 /**
40 * Call to get the client's version of encoding these pixels. If it
41 * returns NULL, serialize the raw pixels.
42 */
43 SkData* encode(const SkPixmap& pixmap) {
44 SkData* data = this->onEncode(pixmap);
45 return data ? data : this->onEncodePixels(
46 pixmap.info(), pixmap.addr(), pixmap.rowBytes());
37 } 47 }
38 48
39 protected: 49 protected:
40 /** 50 /**
41 * Return true if you want to serialize the encoded data, false if you want 51 * Return true if you want to serialize the encoded data, false if you want
42 * another version serialized (e.g. the result of encodePixels). 52 * another version serialized (e.g. the result of encodePixels).
43 */ 53 */
44 virtual bool onUseEncodedData(const void* data, size_t len) = 0; 54 virtual bool onUseEncodedData(const void* data, size_t len) = 0;
45 55
46 /** 56 /**
47 * If you want to encode these pixels, return the encoded data as an SkData 57 * 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. 58 * Return null if you want to serialize the raw pixels.
49 */ 59 */
50 virtual SkData* onEncodePixels(const SkImageInfo&, const void* pixels, size_ t rowBytes) = 0; 60 // NOTE: onEncodePixels() is deprecated and removed in a later CL.
scroggo 2015/12/07 15:57:07 Does Chrome override this? Should we use a macro t
hal.canary 2015/12/07 20:25:01 Chrome and only Chrome overrides this. Macros are
61 // Subclasses should implement onEncode() instead. Subclasses
62 // should implement at least one of onEncodePixels() or
63 // onUseEncodedData().
64 virtual SkData* onEncodePixels(const SkImageInfo&,
65 const void* /*pixels*/,
66 size_t /*rowBytes*/) {
67 return nullptr;
68 }
69 virtual SkData* onEncode(const SkPixmap&) { return nullptr; }
51 }; 70 };
52 #endif // SkPixelSerializer_DEFINED 71 #endif // SkPixelSerializer_DEFINED
OLDNEW
« no previous file with comments | « include/core/SkImage.h ('k') | src/core/SkWriteBuffer.cpp » ('j') | src/image/SkImage.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698