| 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" |
| 22 | |
| 23 | class SkCanvas; |
| 24 | |
| 25 | class SkGPipeReader { |
| 26 | public: |
| 27 | SkGPipeReader(SkCanvas* target); |
| 28 | ~SkGPipeReader(); |
| 29 | |
| 30 | enum Status { |
| 31 | kDone_Status, //!< no more data expected from reader |
| 32 | kEOF_Status, //!< need more data from reader |
| 33 | kError_Status //!< encountered error |
| 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 |
| reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 38 | Status playback(const void* data, size_t length); |
| 39 | |
| 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 | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 77 | SkCanvas* startRecording(SkGPipeController*); |
| 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 | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 86 | SkWriter32 fWriter; |
| 87 | }; |
| 88 | |
| 89 | #endif |