blob: d6210ac8c825c12a185c030c3e52c6ab34bbe768 [file] [log] [blame]
reed@google.combb6992a2011-04-26 17:41:56 +00001/*
2 Copyright 2011 Google Inc.
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16
17
18#ifndef SkGPipe_DEFINED
19#define SkGPipe_DEFINED
20
21#include "SkWriter32.h"
22
23class SkCanvas;
24
25class SkGPipeReader {
26public:
27 SkGPipeReader(SkCanvas* target);
28 ~SkGPipeReader();
29
30 enum Status {
31 kDone_Status, //!< no more data expected from reader
32 kEOF_Status, //!< need more data from reader
33 kError_Status //!< encountered error
34 };
35
36 Status playback(const void* data, size_t length);
37
38private:
39 SkCanvas* fCanvas;
40 class SkGPipeState* fState;
41};
42
43///////////////////////////////////////////////////////////////////////////////
44
reed@google.comf3166342011-04-26 20:06:08 +000045class SkGPipeControler {
46public:
47 struct Block {
48 void* fAddr;
49 size_t fSize;
50 };
51
52 enum Status {
53 kSuccess_Status,
54 kFailure_Status
55 };
56
57 /**
58 * To record drawing commands, we request blocks from the controller for
59 * subsequent writes, and we want to send/flush blocks of commands we have
60 * already written.
61 *
62 * For each call to handleBlock, the send block will contain the block
63 * (previously returned in a request parameter) that we have written, and
64 * if there is more to be recorded, the request block will receive the
65 * new block of memory to write into. When the writer detects that there
66 * are no more drawing commands expected, it will call handleBlock with
67 * NULL for the request parameter.
68 *
69 * If handleBlock ever returns kFailure_Status, the writer will cease to
70 * call handleBlock.
71 */
72 virtual Status handleBlock(const Block& send, Block* request) = 0;
73};
74
reed@google.combb6992a2011-04-26 17:41:56 +000075class SkGPipeWriter {
76public:
77 SkGPipeWriter();
78 ~SkGPipeWriter();
79
80 bool isRecording() const { return NULL != fCanvas; }
reed@google.comf3166342011-04-26 20:06:08 +000081 SkCanvas* startRecording(SkGPipeControler*);
reed@google.combb6992a2011-04-26 17:41:56 +000082 void endRecording();
83
84 size_t flatten(void* buffer);
85
86private:
87 class SkGPipeCanvas* fCanvas;
reed@google.comf3166342011-04-26 20:06:08 +000088 SkGPipeControler* fControler;
reed@google.combb6992a2011-04-26 17:41:56 +000089 SkWriter32 fWriter;
90};
91
92#endif