blob: cd10384084de11fc8913d6afbf36023111aaefe3 [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"
reed@google.comdde09562011-05-23 12:21:05 +000022#include "SkFlattenable.h"
reed@google.combb6992a2011-04-26 17:41:56 +000023
24class SkCanvas;
25
26class SkGPipeReader {
27public:
28 SkGPipeReader(SkCanvas* target);
29 ~SkGPipeReader();
30
31 enum Status {
32 kDone_Status, //!< no more data expected from reader
33 kEOF_Status, //!< need more data from reader
yangsu@google.com1bce0a52011-06-16 21:08:19 +000034 kError_Status, //!< encountered error
35 kReadAtom_Status//!< finished reading an atom
reed@google.combb6992a2011-04-26 17:41:56 +000036 };
37
reed@google.comacd471f2011-05-03 21:26:46 +000038 // data must be 4-byte aligned
39 // length must be a multiple of 4
yangsu@google.com1bce0a52011-06-16 21:08:19 +000040 Status playback(const void* data, size_t length, size_t* bytesRead = NULL,
41 bool readAtom = false);
reed@google.combb6992a2011-04-26 17:41:56 +000042private:
43 SkCanvas* fCanvas;
44 class SkGPipeState* fState;
45};
46
47///////////////////////////////////////////////////////////////////////////////
48
reed@google.comacd471f2011-05-03 21:26:46 +000049class SkGPipeController {
reed@google.comf3166342011-04-26 20:06:08 +000050public:
reed@google.comacd471f2011-05-03 21:26:46 +000051 /**
52 * Called periodically by the writer, to get a working buffer of RAM to
53 * write into. The actual size of the block is also returned, and must be
54 * actual >= minRequest. If NULL is returned, then actual is ignored and
55 * writing will stop.
56 *
57 * The returned block must be 4-byte aligned, and actual must be a
58 * multiple of 4.
59 * minRequest will always be a multiple of 4.
60 */
61 virtual void* requestBlock(size_t minRequest, size_t* actual) = 0;
reed@google.comf3166342011-04-26 20:06:08 +000062
63 /**
reed@google.comacd471f2011-05-03 21:26:46 +000064 * This is called each time some atomic portion of the data has been
65 * written to the block (most recently returned by requestBlock()).
66 * If bytes == 0, then the writer has finished.
reed@google.comf3166342011-04-26 20:06:08 +000067 *
reed@google.comacd471f2011-05-03 21:26:46 +000068 * bytes will always be a multiple of 4.
reed@google.comf3166342011-04-26 20:06:08 +000069 */
reed@google.comacd471f2011-05-03 21:26:46 +000070 virtual void notifyWritten(size_t bytes) = 0;
reed@google.comf3166342011-04-26 20:06:08 +000071};
72
reed@google.combb6992a2011-04-26 17:41:56 +000073class SkGPipeWriter {
74public:
75 SkGPipeWriter();
76 ~SkGPipeWriter();
77
78 bool isRecording() const { return NULL != fCanvas; }
reed@google.comdde09562011-05-23 12:21:05 +000079
80 enum Flags {
81 kCrossProcess_Flag = 1 << 0,
82 };
83
84 SkCanvas* startRecording(SkGPipeController*, uint32_t flags = 0);
reed@google.combb6992a2011-04-26 17:41:56 +000085
reed@google.comacd471f2011-05-03 21:26:46 +000086 // called in destructor, but can be called sooner once you know there
87 // should be no more drawing calls made into the recording canvas.
88 void endRecording();
reed@google.combb6992a2011-04-26 17:41:56 +000089
90private:
91 class SkGPipeCanvas* fCanvas;
reed@google.comacd471f2011-05-03 21:26:46 +000092 SkGPipeController* fController;
reed@google.comdde09562011-05-23 12:21:05 +000093 SkFactorySet fFactorySet;
reed@google.combb6992a2011-04-26 17:41:56 +000094 SkWriter32 fWriter;
95};
96
97#endif