blob: 28d5f5d2e6c5710957a498848686d680aab39b17 [file] [log] [blame]
scroggo895c43b2014-12-11 10:53:58 -08001/*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef SkPixelSerializer_DEFINED
9#define SkPixelSerializer_DEFINED
10
Mike Reed6409f842017-07-11 16:03:13 -040011#include "SkData.h"
halcanary6b280172015-12-07 12:42:24 -080012#include "SkPixmap.h"
Mike Reed6409f842017-07-11 16:03:13 -040013#include "SkRefCnt.h"
scroggo895c43b2014-12-11 10:53:58 -080014
15/**
16 * Interface for serializing pixels, e.g. SkBitmaps in an SkPicture.
17 */
18class SkPixelSerializer : public SkRefCnt {
19public:
reedc9e190d2015-09-28 09:58:41 -070020 virtual ~SkPixelSerializer() {}
scroggo895c43b2014-12-11 10:53:58 -080021
22 /**
reedc9e190d2015-09-28 09:58:41 -070023 * Call to determine if the client wants to serialize the encoded data. If
24 * false, serialize another version (e.g. the result of encodePixels).
scroggo895c43b2014-12-11 10:53:58 -080025 */
reedc9e190d2015-09-28 09:58:41 -070026 bool useEncodedData(const void* data, size_t len) {
27 return this->onUseEncodedData(data, len);
scroggo895c43b2014-12-11 10:53:58 -080028 }
29
reedc9e190d2015-09-28 09:58:41 -070030 /**
31 * Call to get the client's version of encoding these pixels. If it
32 * returns NULL, serialize the raw pixels.
33 */
Mike Reed6409f842017-07-11 16:03:13 -040034 sk_sp<SkData> encodeToData(const SkPixmap& pixmap) {
35 return sk_sp<SkData>(this->onEncode(pixmap));
36 }
37
reedc9e190d2015-09-28 09:58:41 -070038protected:
39 /**
40 * Return true if you want to serialize the encoded data, false if you want
halcanary99073712015-12-10 09:30:57 -080041 * another version serialized (e.g. the result of this->encode()).
reedc9e190d2015-09-28 09:58:41 -070042 */
43 virtual bool onUseEncodedData(const void* data, size_t len) = 0;
44
45 /**
46 * If you want to encode these pixels, return the encoded data as an SkData
47 * Return null if you want to serialize the raw pixels.
48 */
halcanary99073712015-12-10 09:30:57 -080049 virtual SkData* onEncode(const SkPixmap&) = 0;
scroggo895c43b2014-12-11 10:53:58 -080050};
51#endif // SkPixelSerializer_DEFINED