2014-12-11 18:53:58 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SkPixelSerializer_DEFINED
|
|
|
|
#define SkPixelSerializer_DEFINED
|
|
|
|
|
|
|
|
#include "SkRefCnt.h"
|
2015-12-07 20:42:24 +00:00
|
|
|
#include "SkPixmap.h"
|
2014-12-11 18:53:58 +00:00
|
|
|
|
2015-09-28 16:58:41 +00:00
|
|
|
class SkData;
|
2014-12-11 18:53:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Interface for serializing pixels, e.g. SkBitmaps in an SkPicture.
|
|
|
|
*/
|
|
|
|
class SkPixelSerializer : public SkRefCnt {
|
|
|
|
public:
|
2015-09-28 16:58:41 +00:00
|
|
|
virtual ~SkPixelSerializer() {}
|
|
|
|
|
2014-12-11 18:53:58 +00:00
|
|
|
/**
|
2015-09-28 16:58:41 +00:00
|
|
|
* Call to determine if the client wants to serialize the encoded data. If
|
|
|
|
* false, serialize another version (e.g. the result of encodePixels).
|
2014-12-11 18:53:58 +00:00
|
|
|
*/
|
2015-09-28 16:58:41 +00:00
|
|
|
bool useEncodedData(const void* data, size_t len) {
|
|
|
|
return this->onUseEncodedData(data, len);
|
|
|
|
}
|
2014-12-11 18:53:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Call to get the client's version of encoding these pixels. If it
|
|
|
|
* returns NULL, serialize the raw pixels.
|
|
|
|
*/
|
2015-12-10 17:30:57 +00:00
|
|
|
SkData* encode(const SkPixmap& pixmap) { return this->onEncode(pixmap); }
|
2014-12-11 18:53:58 +00:00
|
|
|
|
2015-09-28 16:58:41 +00:00
|
|
|
protected:
|
2014-12-11 18:53:58 +00:00
|
|
|
/**
|
2015-09-28 16:58:41 +00:00
|
|
|
* Return true if you want to serialize the encoded data, false if you want
|
2015-12-10 17:30:57 +00:00
|
|
|
* another version serialized (e.g. the result of this->encode()).
|
2014-12-11 18:53:58 +00:00
|
|
|
*/
|
2015-09-28 16:58:41 +00:00
|
|
|
virtual bool onUseEncodedData(const void* data, size_t len) = 0;
|
2014-12-11 18:53:58 +00:00
|
|
|
|
2015-09-28 16:58:41 +00:00
|
|
|
/**
|
|
|
|
* If you want to encode these pixels, return the encoded data as an SkData
|
|
|
|
* Return null if you want to serialize the raw pixels.
|
|
|
|
*/
|
2015-12-10 17:30:57 +00:00
|
|
|
virtual SkData* onEncode(const SkPixmap&) = 0;
|
2014-12-11 18:53:58 +00:00
|
|
|
};
|
|
|
|
#endif // SkPixelSerializer_DEFINED
|