epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * 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.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 10 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 11 | #ifndef SkGPipe_DEFINED |
| 12 | #define SkGPipe_DEFINED |
| 13 | |
| 14 | #include "SkWriter32.h" |
reed@google.com | dde0956 | 2011-05-23 12:21:05 +0000 | [diff] [blame] | 15 | #include "SkFlattenable.h" |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 16 | |
| 17 | class SkCanvas; |
| 18 | |
reed@google.com | bc75483 | 2011-08-12 14:49:55 +0000 | [diff] [blame] | 19 | // XLib.h might have defined Status already (ugh) |
| 20 | #ifdef Status |
| 21 | #undef Status |
| 22 | #endif |
| 23 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 24 | class SkGPipeReader { |
| 25 | public: |
| 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.com | 1bce0a5 | 2011-06-16 21:08:19 +0000 | [diff] [blame] | 32 | kError_Status, //!< encountered error |
| 33 | kReadAtom_Status//!< finished reading an atom |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 34 | }; |
| 35 | |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 36 | // data must be 4-byte aligned |
| 37 | // length must be a multiple of 4 |
yangsu@google.com | 1bce0a5 | 2011-06-16 21:08:19 +0000 | [diff] [blame] | 38 | Status playback(const void* data, size_t length, size_t* bytesRead = NULL, |
| 39 | bool readAtom = false); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 40 | private: |
| 41 | SkCanvas* fCanvas; |
| 42 | class SkGPipeState* fState; |
| 43 | }; |
| 44 | |
| 45 | /////////////////////////////////////////////////////////////////////////////// |
| 46 | |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 47 | class SkGPipeController { |
reed@google.com | f316634 | 2011-04-26 20:06:08 +0000 | [diff] [blame] | 48 | public: |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 49 | /** |
| 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.com | f316634 | 2011-04-26 20:06:08 +0000 | [diff] [blame] | 60 | |
| 61 | /** |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 62 | * 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.com | f316634 | 2011-04-26 20:06:08 +0000 | [diff] [blame] | 65 | * |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 66 | * bytes will always be a multiple of 4. |
reed@google.com | f316634 | 2011-04-26 20:06:08 +0000 | [diff] [blame] | 67 | */ |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 68 | virtual void notifyWritten(size_t bytes) = 0; |
reed@google.com | f316634 | 2011-04-26 20:06:08 +0000 | [diff] [blame] | 69 | }; |
| 70 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 71 | class SkGPipeWriter { |
| 72 | public: |
| 73 | SkGPipeWriter(); |
| 74 | ~SkGPipeWriter(); |
| 75 | |
| 76 | bool isRecording() const { return NULL != fCanvas; } |
reed@google.com | dde0956 | 2011-05-23 12:21:05 +0000 | [diff] [blame] | 77 | |
| 78 | enum Flags { |
| 79 | kCrossProcess_Flag = 1 << 0, |
| 80 | }; |
| 81 | |
| 82 | SkCanvas* startRecording(SkGPipeController*, uint32_t flags = 0); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 83 | |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 84 | // 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.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 87 | |
| 88 | private: |
| 89 | class SkGPipeCanvas* fCanvas; |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 90 | SkGPipeController* fController; |
reed@google.com | dde0956 | 2011-05-23 12:21:05 +0000 | [diff] [blame] | 91 | SkFactorySet fFactorySet; |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 92 | SkWriter32 fWriter; |
| 93 | }; |
| 94 | |
| 95 | #endif |