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 "SkCanvas.h" | 10 #include "SkCanvas.h" |
11 #include "SkDevice.h" | 11 #include "SkDevice.h" |
12 #include "SkGPipe.h" | 12 #include "SkGPipe.h" |
13 #include "SkMatrix.h" | 13 #include "SkMatrix.h" |
14 | 14 |
15 PipeController::PipeController(SkCanvas* target) | 15 PipeController::PipeController(SkCanvas* target, SkPicture::InstallPixelRefProc
proc) |
16 :fReader(target) { | 16 :fReader(target) { |
17 fBlock = NULL; | 17 fBlock = NULL; |
18 fBlockSize = fBytesWritten = 0; | 18 fBlockSize = fBytesWritten = 0; |
| 19 fReader.setBitmapDecoder(proc); |
19 } | 20 } |
20 | 21 |
21 PipeController::~PipeController() { | 22 PipeController::~PipeController() { |
22 sk_free(fBlock); | 23 sk_free(fBlock); |
23 } | 24 } |
24 | 25 |
25 void* PipeController::requestBlock(size_t minRequest, size_t *actual) { | 26 void* PipeController::requestBlock(size_t minRequest, size_t *actual) { |
26 sk_free(fBlock); | 27 sk_free(fBlock); |
27 fBlockSize = minRequest * 4; | 28 fBlockSize = minRequest * 4; |
28 fBlock = sk_malloc_throw(fBlockSize); | 29 fBlock = sk_malloc_throw(fBlockSize); |
29 fBytesWritten = 0; | 30 fBytesWritten = 0; |
30 *actual = fBlockSize; | 31 *actual = fBlockSize; |
31 return fBlock; | 32 return fBlock; |
32 } | 33 } |
33 | 34 |
34 void PipeController::notifyWritten(size_t bytes) { | 35 void PipeController::notifyWritten(size_t bytes) { |
35 fStatus = fReader.playback(this->getData(), bytes); | 36 fStatus = fReader.playback(this->getData(), bytes); |
36 SkASSERT(SkGPipeReader::kError_Status != fStatus); | 37 SkASSERT(SkGPipeReader::kError_Status != fStatus); |
37 fBytesWritten += bytes; | 38 fBytesWritten += bytes; |
38 } | 39 } |
39 | 40 |
40 //////////////////////////////////////////////////////////////////////////////// | 41 //////////////////////////////////////////////////////////////////////////////// |
41 | 42 |
42 TiledPipeController::TiledPipeController(const SkBitmap& bitmap, | 43 TiledPipeController::TiledPipeController(const SkBitmap& bitmap, |
| 44 SkPicture::InstallPixelRefProc proc, |
43 const SkMatrix* initial) | 45 const SkMatrix* initial) |
44 : INHERITED(NULL) { | 46 : INHERITED(NULL, proc) { |
45 int32_t top = 0; | 47 int32_t top = 0; |
46 int32_t bottom; | 48 int32_t bottom; |
47 int32_t height = bitmap.height() / NumberOfTiles; | 49 int32_t height = bitmap.height() / NumberOfTiles; |
48 SkIRect rect; | 50 SkIRect rect; |
49 for (int i = 0; i < NumberOfTiles; i++) { | 51 for (int i = 0; i < NumberOfTiles; i++) { |
50 bottom = i + 1 == NumberOfTiles ? bitmap.height() : top + height; | 52 bottom = i + 1 == NumberOfTiles ? bitmap.height() : top + height; |
51 rect.setLTRB(0, top, bitmap.width(), bottom); | 53 rect.setLTRB(0, top, bitmap.width(), bottom); |
52 top = bottom; | 54 top = bottom; |
53 | 55 |
54 SkDEBUGCODE(bool extracted = )bitmap.extractSubset(&fBitmaps[i], rect); | 56 SkDEBUGCODE(bool extracted = )bitmap.extractSubset(&fBitmaps[i], rect); |
55 SkASSERT(extracted); | 57 SkASSERT(extracted); |
56 SkDevice* device = new SkDevice(fBitmaps[i]); | 58 SkDevice* device = new SkDevice(fBitmaps[i]); |
57 SkCanvas* canvas = new SkCanvas(device); | 59 SkCanvas* canvas = new SkCanvas(device); |
58 device->unref(); | 60 device->unref(); |
59 if (initial != NULL) { | 61 if (initial != NULL) { |
60 canvas->setMatrix(*initial); | 62 canvas->setMatrix(*initial); |
61 } | 63 } |
62 canvas->translate(SkIntToScalar(-rect.left()), | 64 canvas->translate(SkIntToScalar(-rect.left()), |
63 SkIntToScalar(-rect.top())); | 65 SkIntToScalar(-rect.top())); |
64 if (0 == i) { | 66 if (0 == i) { |
65 fReader.setCanvas(canvas); | 67 fReader.setCanvas(canvas); |
66 } else { | 68 } else { |
67 fReaders[i - 1].setCanvas(canvas); | 69 fReaders[i - 1].setCanvas(canvas); |
| 70 fReaders[i - 1].setBitmapDecoder(proc); |
68 } | 71 } |
69 canvas->unref(); | 72 canvas->unref(); |
70 } | 73 } |
71 } | 74 } |
72 | 75 |
73 void TiledPipeController::notifyWritten(size_t bytes) { | 76 void TiledPipeController::notifyWritten(size_t bytes) { |
74 for (int i = 0; i < NumberOfTiles - 1; i++) { | 77 for (int i = 0; i < NumberOfTiles - 1; i++) { |
75 fReaders[i].playback(this->getData(), bytes); | 78 fReaders[i].playback(this->getData(), bytes); |
76 } | 79 } |
77 this->INHERITED::notifyWritten(bytes); | 80 this->INHERITED::notifyWritten(bytes); |
(...skipping 28 matching lines...) Expand all Loading... |
106 void ThreadSafePipeController::draw(SkCanvas* target) { | 109 void ThreadSafePipeController::draw(SkCanvas* target) { |
107 SkGPipeReader reader(target); | 110 SkGPipeReader reader(target); |
108 for (int currentBlock = 0; currentBlock < fBlockList.count(); currentBlock++
) { | 111 for (int currentBlock = 0; currentBlock < fBlockList.count(); currentBlock++
) { |
109 reader.playback(fBlockList[currentBlock].fBlock, fBlockList[currentBlock
].fBytes); | 112 reader.playback(fBlockList[currentBlock].fBlock, fBlockList[currentBlock
].fBytes); |
110 } | 113 } |
111 | 114 |
112 if (fBlock) { | 115 if (fBlock) { |
113 reader.playback(fBlock, fBytesWritten); | 116 reader.playback(fBlock, fBytesWritten); |
114 } | 117 } |
115 } | 118 } |
OLD | NEW |