blob: 29b058eb2d096b11348398af50f76408664f2d5b [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
reed@google.combc754832011-08-12 14:49:55 +000019// XLib.h might have defined Status already (ugh)
20#ifdef Status
21 #undef Status
22#endif
23
reed@google.combb6992a2011-04-26 17:41:56 +000024class 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
yangsu@google.com1bce0a52011-06-16 21:08:19 +000032 kError_Status, //!< encountered error
33 kReadAtom_Status//!< finished reading an atom
reed@google.combb6992a2011-04-26 17:41:56 +000034 };
35
reed@google.comacd471f2011-05-03 21:26:46 +000036 // data must be 4-byte aligned
37 // length must be a multiple of 4
yangsu@google.com1bce0a52011-06-16 21:08:19 +000038 Status playback(const void* data, size_t length, size_t* bytesRead = NULL,
39 bool readAtom = false);
reed@google.combb6992a2011-04-26 17:41:56 +000040private:
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.comdde09562011-05-23 12:21:05 +000077
78 enum Flags {
79 kCrossProcess_Flag = 1 << 0,
80 };
81
82 SkCanvas* startRecording(SkGPipeController*, uint32_t flags = 0);
reed@google.combb6992a2011-04-26 17:41:56 +000083
reed@google.comacd471f2011-05-03 21:26:46 +000084 // 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();
reed@google.combb6992a2011-04-26 17:41:56 +000087
88private:
89 class SkGPipeCanvas* fCanvas;
reed@google.comacd471f2011-05-03 21:26:46 +000090 SkGPipeController* fController;
reed@google.comdde09562011-05-23 12:21:05 +000091 SkFactorySet fFactorySet;
reed@google.combb6992a2011-04-26 17:41:56 +000092 SkWriter32 fWriter;
93};
94
95#endif