scroggo@google.com | 72c9672 | 2012-06-06 21:07:10 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "SkBitmap.h" |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 9 | #include "SkChunkAlloc.h" |
scroggo@google.com | 72c9672 | 2012-06-06 21:07:10 +0000 | [diff] [blame] | 10 | #include "SkGPipe.h" |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 11 | #include "SkTDArray.h" |
scroggo@google.com | 72c9672 | 2012-06-06 21:07:10 +0000 | [diff] [blame] | 12 | |
| 13 | class SkCanvas; |
scroggo@google.com | b073d92 | 2012-06-08 15:35:03 +0000 | [diff] [blame] | 14 | class SkMatrix; |
scroggo@google.com | 72c9672 | 2012-06-06 21:07:10 +0000 | [diff] [blame] | 15 | |
| 16 | class PipeController : public SkGPipeController { |
| 17 | public: |
| 18 | PipeController(SkCanvas* target); |
| 19 | virtual ~PipeController(); |
| 20 | virtual void* requestBlock(size_t minRequest, size_t* actual) SK_OVERRIDE; |
| 21 | virtual void notifyWritten(size_t bytes) SK_OVERRIDE; |
| 22 | protected: |
| 23 | const void* getData() { return (const char*) fBlock + fBytesWritten; } |
| 24 | SkGPipeReader fReader; |
| 25 | private: |
| 26 | void* fBlock; |
| 27 | size_t fBlockSize; |
| 28 | size_t fBytesWritten; |
| 29 | SkGPipeReader::Status fStatus; |
| 30 | }; |
| 31 | |
| 32 | //////////////////////////////////////////////////////////////////////////////// |
| 33 | |
| 34 | class TiledPipeController : public PipeController { |
| 35 | public: |
scroggo@google.com | b073d92 | 2012-06-08 15:35:03 +0000 | [diff] [blame] | 36 | TiledPipeController(const SkBitmap&, const SkMatrix* initialMatrix = NULL); |
scroggo@google.com | 72c9672 | 2012-06-06 21:07:10 +0000 | [diff] [blame] | 37 | virtual ~TiledPipeController() {}; |
| 38 | virtual void notifyWritten(size_t bytes) SK_OVERRIDE; |
scroggo@google.com | 284bf50 | 2012-07-17 16:10:34 +0000 | [diff] [blame] | 39 | virtual int numberOfReaders() const SK_OVERRIDE { return NumberOfTiles; } |
scroggo@google.com | 72c9672 | 2012-06-06 21:07:10 +0000 | [diff] [blame] | 40 | private: |
| 41 | enum { |
| 42 | NumberOfTiles = 10 |
| 43 | }; |
| 44 | SkGPipeReader fReaders[NumberOfTiles - 1]; |
| 45 | SkBitmap fBitmaps[NumberOfTiles]; |
| 46 | typedef PipeController INHERITED; |
| 47 | }; |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 48 | |
| 49 | //////////////////////////////////////////////////////////////////////////////// |
| 50 | |
| 51 | /** |
| 52 | * Borrowed (and modified) from SkDeferredCanvas.cpp::DeferredPipeController. |
scroggo@google.com | 8e073ba | 2012-08-31 16:25:46 +0000 | [diff] [blame] | 53 | * Allows playing back from multiple threads, but does not do the threading itself. |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 54 | */ |
scroggo@google.com | 8e073ba | 2012-08-31 16:25:46 +0000 | [diff] [blame] | 55 | class ThreadSafePipeController : public SkGPipeController { |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 56 | public: |
scroggo@google.com | 8e073ba | 2012-08-31 16:25:46 +0000 | [diff] [blame] | 57 | ThreadSafePipeController(int numberOfReaders); |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 58 | virtual void* requestBlock(size_t minRequest, size_t* actual) SK_OVERRIDE; |
| 59 | virtual void notifyWritten(size_t bytes) SK_OVERRIDE; |
| 60 | virtual int numberOfReaders() const SK_OVERRIDE { return fNumberOfReaders; } |
| 61 | |
| 62 | /** |
| 63 | * Play the stored drawing commands to the specified canvas. If SkGPipeWriter::startRecording |
| 64 | * used the flag SkGPipeWriter::kSimultaneousReaders_Flag, this can be called from different |
| 65 | * threads simultaneously. |
| 66 | */ |
scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 67 | void draw(SkCanvas*); |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 68 | private: |
| 69 | enum { |
| 70 | kMinBlockSize = 4096 |
| 71 | }; |
| 72 | struct PipeBlock { |
| 73 | PipeBlock(void* block, size_t bytes) { fBlock = block, fBytes = bytes; } |
| 74 | // Stream of draw commands written by the SkGPipeWriter. Allocated by fAllocator, which will |
| 75 | // handle freeing it. |
| 76 | void* fBlock; |
| 77 | // Number of bytes that were written to fBlock. |
| 78 | size_t fBytes; |
| 79 | }; |
| 80 | void* fBlock; |
| 81 | size_t fBytesWritten; |
| 82 | SkChunkAlloc fAllocator; |
| 83 | SkTDArray<PipeBlock> fBlockList; |
| 84 | int fNumberOfReaders; |
| 85 | }; |