1 2/* 3 * Copyright 2011 Google Inc. 4 * 5 * Use of this source code is governed by a BSD-style license that can be 6 * found in the LICENSE file. 7 */ 8 9 10 11#ifndef SkGPipe_DEFINED 12#define SkGPipe_DEFINED 13 14#include "SkWriter32.h" 15#include "SkFlattenable.h" 16 17class SkCanvas; 18 19// XLib.h might have defined Status already (ugh) 20#ifdef Status 21 #undef Status 22#endif 23 24class SkGPipeReader { 25public: 26 SkGPipeReader(SkCanvas* target); 27 ~SkGPipeReader(); 28 29 enum Status { 30 kDone_Status, //!< no more data expected from reader 31 kEOF_Status, //!< need more data from reader 32 kError_Status, //!< encountered error 33 kReadAtom_Status//!< finished reading an atom 34 }; 35 36 // data must be 4-byte aligned 37 // length must be a multiple of 4 38 Status playback(const void* data, size_t length, size_t* bytesRead = NULL, 39 bool readAtom = false); 40private: 41 SkCanvas* fCanvas; 42 class SkGPipeState* fState; 43}; 44 45/////////////////////////////////////////////////////////////////////////////// 46 47class SkGPipeController { 48public: 49 /** 50 * Called periodically by the writer, to get a working buffer of RAM to 51 * write into. The actual size of the block is also returned, and must be 52 * actual >= minRequest. If NULL is returned, then actual is ignored and 53 * writing will stop. 54 * 55 * The returned block must be 4-byte aligned, and actual must be a 56 * multiple of 4. 57 * minRequest will always be a multiple of 4. 58 */ 59 virtual void* requestBlock(size_t minRequest, size_t* actual) = 0; 60 61 /** 62 * This is called each time some atomic portion of the data has been 63 * written to the block (most recently returned by requestBlock()). 64 * If bytes == 0, then the writer has finished. 65 * 66 * bytes will always be a multiple of 4. 67 */ 68 virtual void notifyWritten(size_t bytes) = 0; 69}; 70 71class SkGPipeWriter { 72public: 73 SkGPipeWriter(); 74 ~SkGPipeWriter(); 75 76 bool isRecording() const { return NULL != fCanvas; } 77 78 enum Flags { 79 kCrossProcess_Flag = 1 << 0, 80 }; 81 82 SkCanvas* startRecording(SkGPipeController*, uint32_t flags = 0); 83 84 // called in destructor, but can be called sooner once you know there 85 // should be no more drawing calls made into the recording canvas. 86 void endRecording(); 87 88private: 89 class SkGPipeCanvas* fCanvas; 90 SkGPipeController* fController; 91 SkFactorySet fFactorySet; 92 SkWriter32 fWriter; 93}; 94 95#endif 96