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 | |
| 19 | class SkGPipeReader { |
| 20 | public: |
| 21 | SkGPipeReader(SkCanvas* target); |
| 22 | ~SkGPipeReader(); |
| 23 | |
| 24 | enum Status { |
| 25 | kDone_Status, //!< no more data expected from reader |
| 26 | kEOF_Status, //!< need more data from reader |
yangsu@google.com | 1bce0a5 | 2011-06-16 21:08:19 +0000 | [diff] [blame] | 27 | kError_Status, //!< encountered error |
| 28 | kReadAtom_Status//!< finished reading an atom |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 29 | }; |
| 30 | |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 31 | // data must be 4-byte aligned |
| 32 | // length must be a multiple of 4 |
yangsu@google.com | 1bce0a5 | 2011-06-16 21:08:19 +0000 | [diff] [blame] | 33 | Status playback(const void* data, size_t length, size_t* bytesRead = NULL, |
| 34 | bool readAtom = false); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 35 | private: |
| 36 | SkCanvas* fCanvas; |
| 37 | class SkGPipeState* fState; |
| 38 | }; |
| 39 | |
| 40 | /////////////////////////////////////////////////////////////////////////////// |
| 41 | |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 42 | class SkGPipeController { |
reed@google.com | f316634 | 2011-04-26 20:06:08 +0000 | [diff] [blame] | 43 | public: |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 44 | /** |
| 45 | * Called periodically by the writer, to get a working buffer of RAM to |
| 46 | * write into. The actual size of the block is also returned, and must be |
| 47 | * actual >= minRequest. If NULL is returned, then actual is ignored and |
| 48 | * writing will stop. |
| 49 | * |
| 50 | * The returned block must be 4-byte aligned, and actual must be a |
| 51 | * multiple of 4. |
| 52 | * minRequest will always be a multiple of 4. |
| 53 | */ |
| 54 | virtual void* requestBlock(size_t minRequest, size_t* actual) = 0; |
reed@google.com | f316634 | 2011-04-26 20:06:08 +0000 | [diff] [blame] | 55 | |
| 56 | /** |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 57 | * This is called each time some atomic portion of the data has been |
| 58 | * written to the block (most recently returned by requestBlock()). |
| 59 | * If bytes == 0, then the writer has finished. |
reed@google.com | f316634 | 2011-04-26 20:06:08 +0000 | [diff] [blame] | 60 | * |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 61 | * bytes will always be a multiple of 4. |
reed@google.com | f316634 | 2011-04-26 20:06:08 +0000 | [diff] [blame] | 62 | */ |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 63 | virtual void notifyWritten(size_t bytes) = 0; |
reed@google.com | f316634 | 2011-04-26 20:06:08 +0000 | [diff] [blame] | 64 | }; |
| 65 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 66 | class SkGPipeWriter { |
| 67 | public: |
| 68 | SkGPipeWriter(); |
| 69 | ~SkGPipeWriter(); |
| 70 | |
| 71 | bool isRecording() const { return NULL != fCanvas; } |
reed@google.com | dde0956 | 2011-05-23 12:21:05 +0000 | [diff] [blame] | 72 | |
| 73 | enum Flags { |
| 74 | kCrossProcess_Flag = 1 << 0, |
| 75 | }; |
| 76 | |
| 77 | SkCanvas* startRecording(SkGPipeController*, uint32_t flags = 0); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 78 | |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 79 | // 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.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 82 | |
| 83 | private: |
| 84 | class SkGPipeCanvas* fCanvas; |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 85 | SkGPipeController* fController; |
reed@google.com | dde0956 | 2011-05-23 12:21:05 +0000 | [diff] [blame] | 86 | SkFactorySet fFactorySet; |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 87 | SkWriter32 fWriter; |
| 88 | }; |
| 89 | |
| 90 | #endif |