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

Side by Side Diff: src/core/SkBitmapProcShader.cpp

Issue 23591030: start to remove lockPixels from bitmapshader (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 3 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 | Annotate | Revision Log
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "SkColorPriv.h" 8 #include "SkColorPriv.h"
9 #include "SkFlattenableBuffers.h" 9 #include "SkFlattenableBuffers.h"
10 #include "SkPixelRef.h" 10 #include "SkPixelRef.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 73
74 static bool only_scale_and_translate(const SkMatrix& matrix) { 74 static bool only_scale_and_translate(const SkMatrix& matrix) {
75 unsigned mask = SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask; 75 unsigned mask = SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask;
76 return (matrix.getType() & ~mask) == 0; 76 return (matrix.getType() & ~mask) == 0;
77 } 77 }
78 78
79 bool SkBitmapProcShader::isOpaque() const { 79 bool SkBitmapProcShader::isOpaque() const {
80 return fRawBitmap.isOpaque(); 80 return fRawBitmap.isOpaque();
81 } 81 }
82 82
83 static bool validForDrawing(const SkBitmap& bm) {
scroggo 2013/09/10 18:08:31 Style nit: valid_for_drawing
reed1 2013/09/10 20:28:11 Done.
84 if (0 == bm.width() || 0 == bm.height()) {
85 return false; // nothing to draw
86 }
87 if (NULL == bm.pixelRef()) {
88 return false; // no pixels to read
89 }
90 if (SkBitmap::kIndex8_Config == bm.config()) {
91 // ugh, I have to lock-pixels to inspect the colortable
92 bm.lockPixels();
scroggo 2013/09/10 18:08:31 AutoLockPixels?
reed1 2013/09/10 20:28:11 Done.
93 SkColorTable* ct = bm.getColorTable();
94 bm.unlockPixels();
95 if (!ct) {
96 return false;
97 }
98 }
99 return true;
100 }
101
83 bool SkBitmapProcShader::setContext(const SkBitmap& device, 102 bool SkBitmapProcShader::setContext(const SkBitmap& device,
84 const SkPaint& paint, 103 const SkPaint& paint,
85 const SkMatrix& matrix) { 104 const SkMatrix& matrix) {
105 if (!fRawBitmap.getTexture() && !validForDrawing(fRawBitmap)) {
scroggo 2013/09/10 18:08:31 Should valid_for_drawing check bitmap.getTexture()
reed1 2013/09/10 20:28:11 Yes, though I don't see now why we could work with
106 return false;
107 }
108
86 // do this first, so we have a correct inverse matrix 109 // do this first, so we have a correct inverse matrix
87 if (!this->INHERITED::setContext(device, paint, matrix)) { 110 if (!this->INHERITED::setContext(device, paint, matrix)) {
88 return false; 111 return false;
89 } 112 }
90 113
91 fState.fOrigBitmap = fRawBitmap; 114 fState.fOrigBitmap = fRawBitmap;
92 fState.fOrigBitmap.lockPixels(); 115 if (!fState.chooseProcs(this->getTotalInverse(), paint)) {
93 if (!fState.fOrigBitmap.getTexture() && !fState.fOrigBitmap.readyToDraw()) {
94 fState.fOrigBitmap.unlockPixels();
95 this->INHERITED::endContext(); 116 this->INHERITED::endContext();
96 return false; 117 return false;
97 } 118 }
98
99 if (!fState.chooseProcs(this->getTotalInverse(), paint)) {
100 fState.fOrigBitmap.unlockPixels();
101 this->INHERITED::endContext();
102 return false;
103 }
104 119
105 const SkBitmap& bitmap = *fState.fBitmap; 120 const SkBitmap& bitmap = *fState.fBitmap;
106 bool bitmapIsOpaque = bitmap.isOpaque(); 121 bool bitmapIsOpaque = bitmap.isOpaque();
107 122
108 // update fFlags 123 // update fFlags
109 uint32_t flags = 0; 124 uint32_t flags = 0;
110 if (bitmapIsOpaque && (255 == this->getPaintAlpha())) { 125 if (bitmapIsOpaque && (255 == this->getPaintAlpha())) {
111 flags |= kOpaqueAlpha_Flag; 126 flags |= kOpaqueAlpha_Flag;
112 } 127 }
113 128
(...skipping 26 matching lines...) Expand all
140 if (flags & kHasSpan16_Flag) { 155 if (flags & kHasSpan16_Flag) {
141 flags |= kConstInY16_Flag; 156 flags |= kConstInY16_Flag;
142 } 157 }
143 } 158 }
144 159
145 fFlags = flags; 160 fFlags = flags;
146 return true; 161 return true;
147 } 162 }
148 163
149 void SkBitmapProcShader::endContext() { 164 void SkBitmapProcShader::endContext() {
150 fState.fOrigBitmap.unlockPixels();
151 fState.endContext(); 165 fState.endContext();
152 this->INHERITED::endContext(); 166 this->INHERITED::endContext();
153 } 167 }
154 168
155 #define BUF_MAX 128 169 #define BUF_MAX 128
156 170
157 #define TEST_BUFFER_OVERRITEx 171 #define TEST_BUFFER_OVERRITEx
158 172
159 #ifdef TEST_BUFFER_OVERRITE 173 #ifdef TEST_BUFFER_OVERRITE
160 #define TEST_BUFFER_EXTRA 32 174 #define TEST_BUFFER_EXTRA 32
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 GrEffectRef* effect = NULL; 411 GrEffectRef* effect = NULL;
398 if (paintFilterLevel == SkPaint::kHigh_FilterLevel) { 412 if (paintFilterLevel == SkPaint::kHigh_FilterLevel) {
399 effect = GrBicubicEffect::Create(texture, matrix, params); 413 effect = GrBicubicEffect::Create(texture, matrix, params);
400 } else { 414 } else {
401 effect = GrSimpleTextureEffect::Create(texture, matrix, params); 415 effect = GrSimpleTextureEffect::Create(texture, matrix, params);
402 } 416 }
403 GrUnlockAndUnrefCachedBitmapTexture(texture); 417 GrUnlockAndUnrefCachedBitmapTexture(texture);
404 return effect; 418 return effect;
405 } 419 }
406 #endif 420 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698