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 | |
| 36 | Status playback(const void* data, size_t length); |
| 37 | |
| 38 | private: |
| 39 | SkCanvas* fCanvas; |
| 40 | class SkGPipeState* fState; |
| 41 | }; |
| 42 | |
| 43 | /////////////////////////////////////////////////////////////////////////////// |
| 44 | |
reed@google.com | f316634 | 2011-04-26 20:06:08 +0000 | [diff] [blame^] | 45 | class SkGPipeControler { |
| 46 | public: |
| 47 | struct Block { |
| 48 | void* fAddr; |
| 49 | size_t fSize; |
| 50 | }; |
| 51 | |
| 52 | enum Status { |
| 53 | kSuccess_Status, |
| 54 | kFailure_Status |
| 55 | }; |
| 56 | |
| 57 | /** |
| 58 | * To record drawing commands, we request blocks from the controller for |
| 59 | * subsequent writes, and we want to send/flush blocks of commands we have |
| 60 | * already written. |
| 61 | * |
| 62 | * For each call to handleBlock, the send block will contain the block |
| 63 | * (previously returned in a request parameter) that we have written, and |
| 64 | * if there is more to be recorded, the request block will receive the |
| 65 | * new block of memory to write into. When the writer detects that there |
| 66 | * are no more drawing commands expected, it will call handleBlock with |
| 67 | * NULL for the request parameter. |
| 68 | * |
| 69 | * If handleBlock ever returns kFailure_Status, the writer will cease to |
| 70 | * call handleBlock. |
| 71 | */ |
| 72 | virtual Status handleBlock(const Block& send, Block* request) = 0; |
| 73 | }; |
| 74 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 75 | class SkGPipeWriter { |
| 76 | public: |
| 77 | SkGPipeWriter(); |
| 78 | ~SkGPipeWriter(); |
| 79 | |
| 80 | bool isRecording() const { return NULL != fCanvas; } |
reed@google.com | f316634 | 2011-04-26 20:06:08 +0000 | [diff] [blame^] | 81 | SkCanvas* startRecording(SkGPipeControler*); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 82 | void endRecording(); |
| 83 | |
| 84 | size_t flatten(void* buffer); |
| 85 | |
| 86 | private: |
| 87 | class SkGPipeCanvas* fCanvas; |
reed@google.com | f316634 | 2011-04-26 20:06:08 +0000 | [diff] [blame^] | 88 | SkGPipeControler* fControler; |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 89 | SkWriter32 fWriter; |
| 90 | }; |
| 91 | |
| 92 | #endif |