Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: src/pipe/utils/SamplePipeControllers.cpp

Issue 267863002: 4x allocation in PipeController is probably overkill. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: keep test Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/pipe/utils/SamplePipeControllers.h ('k') | tests/DeferredCanvasTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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) { 16 : fReader(target), fBlockSize(0), fBytesWritten(0) {
17 fBlock = NULL;
18 fBlockSize = fBytesWritten = 0;
19 fReader.setBitmapDecoder(proc); 17 fReader.setBitmapDecoder(proc);
20 } 18 }
21 19
22 PipeController::~PipeController() { 20 void* PipeController::requestBlock(size_t minRequest, size_t* actual) {
23 sk_free(fBlock); 21 fBlockSize = minRequest;
24 } 22 fBlock.reset(fBlockSize);
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);
30 fBytesWritten = 0; 23 fBytesWritten = 0;
31 *actual = fBlockSize; 24 *actual = fBlockSize;
32 return fBlock; 25 return fBlock.get();
33 } 26 }
34 27
35 void PipeController::notifyWritten(size_t bytes) { 28 void PipeController::notifyWritten(size_t bytes) {
36 fStatus = fReader.playback(this->getData(), bytes); 29 fStatus = fReader.playback(this->getData(), bytes);
37 SkASSERT(SkGPipeReader::kError_Status != fStatus); 30 SkASSERT(SkGPipeReader::kError_Status != fStatus);
38 fBytesWritten += bytes; 31 fBytesWritten += bytes;
39 } 32 }
40 33
41 //////////////////////////////////////////////////////////////////////////////// 34 ////////////////////////////////////////////////////////////////////////////////
42 35
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 void ThreadSafePipeController::draw(SkCanvas* target) { 102 void ThreadSafePipeController::draw(SkCanvas* target) {
110 SkGPipeReader reader(target); 103 SkGPipeReader reader(target);
111 for (int currentBlock = 0; currentBlock < fBlockList.count(); currentBlock++ ) { 104 for (int currentBlock = 0; currentBlock < fBlockList.count(); currentBlock++ ) {
112 reader.playback(fBlockList[currentBlock].fBlock, fBlockList[currentBlock ].fBytes); 105 reader.playback(fBlockList[currentBlock].fBlock, fBlockList[currentBlock ].fBytes);
113 } 106 }
114 107
115 if (fBlock) { 108 if (fBlock) {
116 reader.playback(fBlock, fBytesWritten); 109 reader.playback(fBlock, fBytesWritten);
117 } 110 }
118 } 111 }
OLDNEW
« no previous file with comments | « src/pipe/utils/SamplePipeControllers.h ('k') | tests/DeferredCanvasTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698