blob: 2bac7f838b7e0fb134775d6be56ad12a578e82af [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@google.combb6992a2011-04-26 17:41:56 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * 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.
reed@google.combb6992a2011-04-26 17:41:56 +00007 */
8
9
epoger@google.comec3ed6a2011-07-28 14:26:00 +000010
reed@google.combb6992a2011-04-26 17:41:56 +000011#ifndef SkGPipe_DEFINED
12#define SkGPipe_DEFINED
13
14#include "SkWriter32.h"
reed@google.comdde09562011-05-23 12:21:05 +000015#include "SkFlattenable.h"
reed@google.combb6992a2011-04-26 17:41:56 +000016
17class SkCanvas;
18
19class SkGPipeReader {
20public:
21 SkGPipeReader(SkCanvas* target);
22 ~SkGPipeReader();
23
24 enum Status {
25 kDone_Status, //!< no more data expected from reader
26 kEOF_Status, //!< need more data from reader
yangsu@google.com1bce0a52011-06-16 21:08:19 +000027 kError_Status, //!< encountered error
28 kReadAtom_Status//!< finished reading an atom
reed@google.combb6992a2011-04-26 17:41:56 +000029 };
30
reed@google.comacd471f2011-05-03 21:26:46 +000031 // data must be 4-byte aligned
32 // length must be a multiple of 4
yangsu@google.com1bce0a52011-06-16 21:08:19 +000033 Status playback(const void* data, size_t length, size_t* bytesRead = NULL,
34 bool readAtom = false);
reed@google.combb6992a2011-04-26 17:41:56 +000035private:
36 SkCanvas* fCanvas;
37 class SkGPipeState* fState;
38};
39
40///////////////////////////////////////////////////////////////////////////////
41
reed@google.comacd471f2011-05-03 21:26:46 +000042class SkGPipeController {
reed@google.comf3166342011-04-26 20:06:08 +000043public:
reed@google.comacd471f2011-05-03 21:26:46 +000044 /**
45 * Called periodically by the writer, to get a working buffer of RAM to
46 * write into. The actual size of the block is also returned, and must be
47 * actual >= minRequest. If NULL is returned, then actual is ignored and
48 * writing will stop.
49 *
50 * The returned block must be 4-byte aligned, and actual must be a
51 * multiple of 4.
52 * minRequest will always be a multiple of 4.
53 */
54 virtual void* requestBlock(size_t minRequest, size_t* actual) = 0;
reed@google.comf3166342011-04-26 20:06:08 +000055
56 /**
reed@google.comacd471f2011-05-03 21:26:46 +000057 * This is called each time some atomic portion of the data has been
58 * written to the block (most recently returned by requestBlock()).
59 * If bytes == 0, then the writer has finished.
reed@google.comf3166342011-04-26 20:06:08 +000060 *
reed@google.comacd471f2011-05-03 21:26:46 +000061 * bytes will always be a multiple of 4.
reed@google.comf3166342011-04-26 20:06:08 +000062 */
reed@google.comacd471f2011-05-03 21:26:46 +000063 virtual void notifyWritten(size_t bytes) = 0;
reed@google.comf3166342011-04-26 20:06:08 +000064};
65
reed@google.combb6992a2011-04-26 17:41:56 +000066class SkGPipeWriter {
67public:
68 SkGPipeWriter();
69 ~SkGPipeWriter();
70
71 bool isRecording() const { return NULL != fCanvas; }
reed@google.comdde09562011-05-23 12:21:05 +000072
73 enum Flags {
74 kCrossProcess_Flag = 1 << 0,
75 };
76
77 SkCanvas* startRecording(SkGPipeController*, uint32_t flags = 0);
reed@google.combb6992a2011-04-26 17:41:56 +000078
reed@google.comacd471f2011-05-03 21:26:46 +000079 // called in destructor, but can be called sooner once you know there
80 // should be no more drawing calls made into the recording canvas.
81 void endRecording();
reed@google.combb6992a2011-04-26 17:41:56 +000082
83private:
84 class SkGPipeCanvas* fCanvas;
reed@google.comacd471f2011-05-03 21:26:46 +000085 SkGPipeController* fController;
reed@google.comdde09562011-05-23 12:21:05 +000086 SkFactorySet fFactorySet;
reed@google.combb6992a2011-04-26 17:41:56 +000087 SkWriter32 fWriter;
88};
89
90#endif