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