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 "SamplePipeControllers.h" | 8 #include "SamplePipeControllers.h" |
9 | 9 |
10 #include "SkBitmapDevice.h" | 10 #include "SkBitmapDevice.h" |
11 #include "SkCanvas.h" | 11 #include "SkCanvas.h" |
12 #include "SkGPipe.h" | 12 #include "SkGPipe.h" |
13 #include "SkMatrix.h" | 13 #include "SkMatrix.h" |
14 | 14 |
15 PipeController::PipeController(SkCanvas* target, SkPicture::InstallPixelRefProc
proc) | 15 PipeController::PipeController(SkCanvas* target, SkPicture::InstallPixelRefProc
proc) |
16 : fReader(target), fBlockSize(0), fBytesWritten(0) { | 16 :fReader(target) { |
| 17 fBlock = NULL; |
| 18 fBlockSize = fBytesWritten = 0; |
17 fReader.setBitmapDecoder(proc); | 19 fReader.setBitmapDecoder(proc); |
18 } | 20 } |
19 | 21 |
20 void* PipeController::requestBlock(size_t minRequest, size_t* actual) { | 22 PipeController::~PipeController() { |
21 fBlockSize = minRequest; | 23 sk_free(fBlock); |
22 fBlock.reset(fBlockSize); | 24 } |
| 25 |
| 26 void* PipeController::requestBlock(size_t minRequest, size_t *actual) { |
| 27 sk_free(fBlock); |
| 28 fBlockSize = minRequest * 4; |
| 29 fBlock = sk_malloc_throw(fBlockSize); |
23 fBytesWritten = 0; | 30 fBytesWritten = 0; |
24 *actual = fBlockSize; | 31 *actual = fBlockSize; |
25 return fBlock.get(); | 32 return fBlock; |
26 } | 33 } |
27 | 34 |
28 void PipeController::notifyWritten(size_t bytes) { | 35 void PipeController::notifyWritten(size_t bytes) { |
29 fStatus = fReader.playback(this->getData(), bytes); | 36 fStatus = fReader.playback(this->getData(), bytes); |
30 SkASSERT(SkGPipeReader::kError_Status != fStatus); | 37 SkASSERT(SkGPipeReader::kError_Status != fStatus); |
31 fBytesWritten += bytes; | 38 fBytesWritten += bytes; |
32 } | 39 } |
33 | 40 |
34 //////////////////////////////////////////////////////////////////////////////// | 41 //////////////////////////////////////////////////////////////////////////////// |
35 | 42 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 void ThreadSafePipeController::draw(SkCanvas* target) { | 109 void ThreadSafePipeController::draw(SkCanvas* target) { |
103 SkGPipeReader reader(target); | 110 SkGPipeReader reader(target); |
104 for (int currentBlock = 0; currentBlock < fBlockList.count(); currentBlock++
) { | 111 for (int currentBlock = 0; currentBlock < fBlockList.count(); currentBlock++
) { |
105 reader.playback(fBlockList[currentBlock].fBlock, fBlockList[currentBlock
].fBytes); | 112 reader.playback(fBlockList[currentBlock].fBlock, fBlockList[currentBlock
].fBytes); |
106 } | 113 } |
107 | 114 |
108 if (fBlock) { | 115 if (fBlock) { |
109 reader.playback(fBlock, fBytesWritten); | 116 reader.playback(fBlock, fBytesWritten); |
110 } | 117 } |
111 } | 118 } |
OLD | NEW |