reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1 | /* |
| 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.com | dde0956 | 2011-05-23 12:21:05 +0000 | [diff] [blame] | 22 | #include "SkFlattenable.h" |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 23 | |
| 24 | class SkCanvas; |
| 25 | |
| 26 | class SkGPipeReader { |
| 27 | public: |
| 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 |
| 34 | kError_Status //!< encountered error |
| 35 | }; |
| 36 | |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 37 | // data must be 4-byte aligned |
| 38 | // length must be a multiple of 4 |
reed@google.com | 80b09de | 2011-05-23 13:54:24 +0000 | [diff] [blame] | 39 | Status playback(const void* data, size_t length, size_t* bytesRead = NULL); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 40 | |
| 41 | private: |
| 42 | SkCanvas* fCanvas; |
| 43 | class SkGPipeState* fState; |
| 44 | }; |
| 45 | |
| 46 | /////////////////////////////////////////////////////////////////////////////// |
| 47 | |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 48 | class SkGPipeController { |
reed@google.com | f316634 | 2011-04-26 20:06:08 +0000 | [diff] [blame] | 49 | public: |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 50 | /** |
| 51 | * Called periodically by the writer, to get a working buffer of RAM to |
| 52 | * write into. The actual size of the block is also returned, and must be |
| 53 | * actual >= minRequest. If NULL is returned, then actual is ignored and |
| 54 | * writing will stop. |
| 55 | * |
| 56 | * The returned block must be 4-byte aligned, and actual must be a |
| 57 | * multiple of 4. |
| 58 | * minRequest will always be a multiple of 4. |
| 59 | */ |
| 60 | virtual void* requestBlock(size_t minRequest, size_t* actual) = 0; |
reed@google.com | f316634 | 2011-04-26 20:06:08 +0000 | [diff] [blame] | 61 | |
| 62 | /** |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 63 | * This is called each time some atomic portion of the data has been |
| 64 | * written to the block (most recently returned by requestBlock()). |
| 65 | * If bytes == 0, then the writer has finished. |
reed@google.com | f316634 | 2011-04-26 20:06:08 +0000 | [diff] [blame] | 66 | * |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 67 | * bytes will always be a multiple of 4. |
reed@google.com | f316634 | 2011-04-26 20:06:08 +0000 | [diff] [blame] | 68 | */ |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 69 | virtual void notifyWritten(size_t bytes) = 0; |
reed@google.com | f316634 | 2011-04-26 20:06:08 +0000 | [diff] [blame] | 70 | }; |
| 71 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 72 | class SkGPipeWriter { |
| 73 | public: |
| 74 | SkGPipeWriter(); |
| 75 | ~SkGPipeWriter(); |
| 76 | |
| 77 | bool isRecording() const { return NULL != fCanvas; } |
reed@google.com | dde0956 | 2011-05-23 12:21:05 +0000 | [diff] [blame] | 78 | |
| 79 | enum Flags { |
| 80 | kCrossProcess_Flag = 1 << 0, |
| 81 | }; |
| 82 | |
| 83 | SkCanvas* startRecording(SkGPipeController*, uint32_t flags = 0); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 84 | |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 85 | // called in destructor, but can be called sooner once you know there |
| 86 | // should be no more drawing calls made into the recording canvas. |
| 87 | void endRecording(); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 88 | |
| 89 | private: |
| 90 | class SkGPipeCanvas* fCanvas; |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 91 | SkGPipeController* fController; |
reed@google.com | dde0956 | 2011-05-23 12:21:05 +0000 | [diff] [blame] | 92 | SkFactorySet fFactorySet; |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 93 | SkWriter32 fWriter; |
| 94 | }; |
| 95 | |
| 96 | #endif |