2011-07-28 14:26:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
2011-04-26 17:41:56 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2011-07-28 14:26:00 +00:00
|
|
|
|
2011-04-26 17:41:56 +00:00
|
|
|
#ifndef SkGPipe_DEFINED
|
|
|
|
#define SkGPipe_DEFINED
|
|
|
|
|
2011-05-23 12:21:05 +00:00
|
|
|
#include "SkFlattenable.h"
|
2013-04-30 02:32:41 +00:00
|
|
|
#include "SkPicture.h"
|
|
|
|
#include "SkWriter32.h"
|
2011-04-26 17:41:56 +00:00
|
|
|
|
|
|
|
class SkCanvas;
|
|
|
|
|
2011-08-12 14:49:55 +00:00
|
|
|
// XLib.h might have defined Status already (ugh)
|
|
|
|
#ifdef Status
|
|
|
|
#undef Status
|
|
|
|
#endif
|
|
|
|
|
2011-04-26 17:41:56 +00:00
|
|
|
class SkGPipeReader {
|
|
|
|
public:
|
2012-06-06 21:07:10 +00:00
|
|
|
SkGPipeReader();
|
2011-04-26 17:41:56 +00:00
|
|
|
SkGPipeReader(SkCanvas* target);
|
|
|
|
~SkGPipeReader();
|
|
|
|
|
|
|
|
enum Status {
|
|
|
|
kDone_Status, //!< no more data expected from reader
|
|
|
|
kEOF_Status, //!< need more data from reader
|
2011-06-16 21:08:19 +00:00
|
|
|
kError_Status, //!< encountered error
|
|
|
|
kReadAtom_Status//!< finished reading an atom
|
2011-04-26 17:41:56 +00:00
|
|
|
};
|
|
|
|
|
2012-09-20 19:35:43 +00:00
|
|
|
enum PlaybackFlags {
|
|
|
|
kReadAtom_PlaybackFlag = 0x1, //!< playback a single command from the stream
|
|
|
|
kSilent_PlaybackFlag = 0x2, //!< playback without drawing
|
|
|
|
};
|
|
|
|
|
2012-06-06 21:07:10 +00:00
|
|
|
void setCanvas(SkCanvas*);
|
2013-04-30 02:32:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a function for decoding bitmaps that have encoded data.
|
|
|
|
*/
|
|
|
|
void setBitmapDecoder(SkPicture::InstallPixelRefProc proc) { fProc = proc; }
|
|
|
|
|
2011-05-03 21:26:46 +00:00
|
|
|
// data must be 4-byte aligned
|
|
|
|
// length must be a multiple of 4
|
2012-09-20 19:35:43 +00:00
|
|
|
Status playback(const void* data, size_t length, uint32_t playbackFlags = 0,
|
|
|
|
size_t* bytesRead = NULL);
|
2011-04-26 17:41:56 +00:00
|
|
|
private:
|
2013-04-30 02:32:41 +00:00
|
|
|
SkCanvas* fCanvas;
|
|
|
|
class SkGPipeState* fState;
|
|
|
|
SkPicture::InstallPixelRefProc fProc;
|
2011-04-26 17:41:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-07-27 20:39:19 +00:00
|
|
|
class SkGPipeCanvas;
|
|
|
|
|
2011-05-03 21:26:46 +00:00
|
|
|
class SkGPipeController {
|
2011-04-26 20:06:08 +00:00
|
|
|
public:
|
2012-07-27 20:39:19 +00:00
|
|
|
SkGPipeController() : fCanvas(NULL) {}
|
|
|
|
virtual ~SkGPipeController();
|
|
|
|
|
2011-04-26 20:06:08 +00:00
|
|
|
/**
|
2011-05-03 21:26:46 +00:00
|
|
|
* Called periodically by the writer, to get a working buffer of RAM to
|
|
|
|
* write into. The actual size of the block is also returned, and must be
|
|
|
|
* actual >= minRequest. If NULL is returned, then actual is ignored and
|
|
|
|
* writing will stop.
|
2011-04-26 20:06:08 +00:00
|
|
|
*
|
2011-05-03 21:26:46 +00:00
|
|
|
* The returned block must be 4-byte aligned, and actual must be a
|
|
|
|
* multiple of 4.
|
|
|
|
* minRequest will always be a multiple of 4.
|
|
|
|
*/
|
|
|
|
virtual void* requestBlock(size_t minRequest, size_t* actual) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is called each time some atomic portion of the data has been
|
|
|
|
* written to the block (most recently returned by requestBlock()).
|
|
|
|
* If bytes == 0, then the writer has finished.
|
2011-04-26 20:06:08 +00:00
|
|
|
*
|
2011-05-03 21:26:46 +00:00
|
|
|
* bytes will always be a multiple of 4.
|
2011-04-26 20:06:08 +00:00
|
|
|
*/
|
2011-05-03 21:26:46 +00:00
|
|
|
virtual void notifyWritten(size_t bytes) = 0;
|
2012-07-17 16:10:34 +00:00
|
|
|
virtual int numberOfReaders() const { return 1; }
|
2012-07-27 20:39:19 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
friend class SkGPipeWriter;
|
|
|
|
void setCanvas(SkGPipeCanvas*);
|
|
|
|
|
|
|
|
SkGPipeCanvas* fCanvas;
|
2011-04-26 20:06:08 +00:00
|
|
|
};
|
|
|
|
|
2011-04-26 17:41:56 +00:00
|
|
|
class SkGPipeWriter {
|
|
|
|
public:
|
|
|
|
SkGPipeWriter();
|
|
|
|
~SkGPipeWriter();
|
|
|
|
|
|
|
|
bool isRecording() const { return NULL != fCanvas; }
|
2011-05-23 12:21:05 +00:00
|
|
|
|
|
|
|
enum Flags {
|
2012-06-28 15:41:32 +00:00
|
|
|
/**
|
|
|
|
* Tells the writer that the reader will be in a different process, so
|
|
|
|
* (for example) we cannot put function pointers in the stream.
|
|
|
|
*/
|
|
|
|
kCrossProcess_Flag = 1 << 0,
|
2012-08-31 16:15:22 +00:00
|
|
|
|
2012-06-28 15:41:32 +00:00
|
|
|
/**
|
|
|
|
* Only meaningful if kCrossProcess_Flag is set. Tells the writer that
|
|
|
|
* in spite of being cross process, it will have shared address space
|
2012-08-31 16:15:22 +00:00
|
|
|
* with the reader, so the two can share large objects (like SkBitmaps).
|
|
|
|
*/
|
|
|
|
kSharedAddressSpace_Flag = 1 << 1,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tells the writer that there will be multiple threads reading the stream
|
|
|
|
* simultaneously.
|
2012-06-28 15:41:32 +00:00
|
|
|
*/
|
2012-08-31 16:15:22 +00:00
|
|
|
kSimultaneousReaders_Flag = 1 << 2,
|
2011-05-23 12:21:05 +00:00
|
|
|
};
|
|
|
|
|
2012-08-15 19:49:22 +00:00
|
|
|
SkCanvas* startRecording(SkGPipeController*, uint32_t flags = 0,
|
|
|
|
uint32_t width = kDefaultRecordingCanvasSize,
|
|
|
|
uint32_t height = kDefaultRecordingCanvasSize);
|
2011-04-26 17:41:56 +00:00
|
|
|
|
2011-05-03 21:26:46 +00:00
|
|
|
// called in destructor, but can be called sooner once you know there
|
|
|
|
// should be no more drawing calls made into the recording canvas.
|
|
|
|
void endRecording();
|
2011-04-26 17:41:56 +00:00
|
|
|
|
2012-07-18 17:54:45 +00:00
|
|
|
/**
|
|
|
|
* Tells the writer to commit all recorded draw commands to the
|
|
|
|
* controller immediately.
|
|
|
|
* @param detachCurrentBlock Set to true to request that the next draw
|
|
|
|
* command be recorded in a new block.
|
|
|
|
*/
|
|
|
|
void flushRecording(bool detachCurrentBlock);
|
|
|
|
|
2012-07-26 20:03:32 +00:00
|
|
|
/**
|
|
|
|
* Return the amount of bytes being used for recording. Note that this
|
|
|
|
* does not include the amount of storage written to the stream, which is
|
|
|
|
* controlled by the SkGPipeController.
|
|
|
|
* Currently only returns the amount used for SkBitmaps, since they are
|
|
|
|
* potentially unbounded (if the client is not calling playback).
|
|
|
|
*/
|
2012-08-07 14:26:57 +00:00
|
|
|
size_t storageAllocatedForRecording() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Attempt to reduce the storage allocated for recording by evicting
|
|
|
|
* cache resources.
|
|
|
|
* @param bytesToFree minimum number of bytes that should be attempted to
|
|
|
|
* be freed.
|
|
|
|
* @return number of bytes actually freed.
|
|
|
|
*/
|
|
|
|
size_t freeMemoryIfPossible(size_t bytesToFree);
|
2012-07-26 20:03:32 +00:00
|
|
|
|
2011-04-26 17:41:56 +00:00
|
|
|
private:
|
2012-08-15 19:49:22 +00:00
|
|
|
enum {
|
|
|
|
kDefaultRecordingCanvasSize = 32767,
|
|
|
|
};
|
|
|
|
|
2012-07-27 20:39:19 +00:00
|
|
|
SkGPipeCanvas* fCanvas;
|
|
|
|
SkWriter32 fWriter;
|
2011-04-26 17:41:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|