blob: e9f850260efbdccbc3f1f2ea095f6775a97529d6 [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
reed@google.comacd471f2011-05-03 21:26:46 +000036 // data must be 4-byte aligned
37 // length must be a multiple of 4
reed@google.combb6992a2011-04-26 17:41:56 +000038 Status playback(const void* data, size_t length);
39
40private:
41 SkCanvas* fCanvas;
42 class SkGPipeState* fState;
43};
44
45///////////////////////////////////////////////////////////////////////////////
46
reed@google.comacd471f2011-05-03 21:26:46 +000047class SkGPipeController {
reed@google.comf3166342011-04-26 20:06:08 +000048public:
reed@google.comacd471f2011-05-03 21:26:46 +000049 /**
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;
reed@google.comf3166342011-04-26 20:06:08 +000060
61 /**
reed@google.comacd471f2011-05-03 21:26:46 +000062 * 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.
reed@google.comf3166342011-04-26 20:06:08 +000065 *
reed@google.comacd471f2011-05-03 21:26:46 +000066 * bytes will always be a multiple of 4.
reed@google.comf3166342011-04-26 20:06:08 +000067 */
reed@google.comacd471f2011-05-03 21:26:46 +000068 virtual void notifyWritten(size_t bytes) = 0;
reed@google.comf3166342011-04-26 20:06:08 +000069};
70
reed@google.combb6992a2011-04-26 17:41:56 +000071class SkGPipeWriter {
72public:
73 SkGPipeWriter();
74 ~SkGPipeWriter();
75
76 bool isRecording() const { return NULL != fCanvas; }
reed@google.comacd471f2011-05-03 21:26:46 +000077 SkCanvas* startRecording(SkGPipeController*);
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.combb6992a2011-04-26 17:41:56 +000086 SkWriter32 fWriter;
87};
88
89#endif