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

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
« no previous file with comments | « include/core/SkPixelRef.h ('k') | src/core/SkBitmapProcState.h » ('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 /* 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 valid_for_drawing(const SkBitmap& bm) {
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 SkAutoLockPixels alp(bm);
93 if (!bm.getColorTable()) {
94 return false;
95 }
96 }
97 return true;
98 }
99
83 bool SkBitmapProcShader::setContext(const SkBitmap& device, 100 bool SkBitmapProcShader::setContext(const SkBitmap& device,
84 const SkPaint& paint, 101 const SkPaint& paint,
85 const SkMatrix& matrix) { 102 const SkMatrix& matrix) {
103 if (!fRawBitmap.getTexture() && !valid_for_drawing(fRawBitmap)) {
104 return false;
105 }
106
86 // do this first, so we have a correct inverse matrix 107 // do this first, so we have a correct inverse matrix
87 if (!this->INHERITED::setContext(device, paint, matrix)) { 108 if (!this->INHERITED::setContext(device, paint, matrix)) {
88 return false; 109 return false;
89 } 110 }
90 111
91 fState.fOrigBitmap = fRawBitmap; 112 fState.fOrigBitmap = fRawBitmap;
92 fState.fOrigBitmap.lockPixels(); 113 if (!fState.chooseProcs(this->getTotalInverse(), paint)) {
93 if (!fState.fOrigBitmap.getTexture() && !fState.fOrigBitmap.readyToDraw()) {
94 fState.fOrigBitmap.unlockPixels();
95 this->INHERITED::endContext(); 114 this->INHERITED::endContext();
96 return false; 115 return false;
97 } 116 }
98
99 if (!fState.chooseProcs(this->getTotalInverse(), paint)) {
100 fState.fOrigBitmap.unlockPixels();
101 this->INHERITED::endContext();
102 return false;
103 }
104 117
105 const SkBitmap& bitmap = *fState.fBitmap; 118 const SkBitmap& bitmap = *fState.fBitmap;
106 bool bitmapIsOpaque = bitmap.isOpaque(); 119 bool bitmapIsOpaque = bitmap.isOpaque();
107 120
108 // update fFlags 121 // update fFlags
109 uint32_t flags = 0; 122 uint32_t flags = 0;
110 if (bitmapIsOpaque && (255 == this->getPaintAlpha())) { 123 if (bitmapIsOpaque && (255 == this->getPaintAlpha())) {
111 flags |= kOpaqueAlpha_Flag; 124 flags |= kOpaqueAlpha_Flag;
112 } 125 }
113 126
(...skipping 26 matching lines...) Expand all
140 if (flags & kHasSpan16_Flag) { 153 if (flags & kHasSpan16_Flag) {
141 flags |= kConstInY16_Flag; 154 flags |= kConstInY16_Flag;
142 } 155 }
143 } 156 }
144 157
145 fFlags = flags; 158 fFlags = flags;
146 return true; 159 return true;
147 } 160 }
148 161
149 void SkBitmapProcShader::endContext() { 162 void SkBitmapProcShader::endContext() {
150 fState.fOrigBitmap.unlockPixels();
151 fState.endContext(); 163 fState.endContext();
152 this->INHERITED::endContext(); 164 this->INHERITED::endContext();
153 } 165 }
154 166
155 #define BUF_MAX 128 167 #define BUF_MAX 128
156 168
157 #define TEST_BUFFER_OVERRITEx 169 #define TEST_BUFFER_OVERRITEx
158 170
159 #ifdef TEST_BUFFER_OVERRITE 171 #ifdef TEST_BUFFER_OVERRITE
160 #define TEST_BUFFER_EXTRA 32 172 #define TEST_BUFFER_EXTRA 32
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 GrEffectRef* effect = NULL; 409 GrEffectRef* effect = NULL;
398 if (paintFilterLevel == SkPaint::kHigh_FilterLevel) { 410 if (paintFilterLevel == SkPaint::kHigh_FilterLevel) {
399 effect = GrBicubicEffect::Create(texture, matrix, params); 411 effect = GrBicubicEffect::Create(texture, matrix, params);
400 } else { 412 } else {
401 effect = GrSimpleTextureEffect::Create(texture, matrix, params); 413 effect = GrSimpleTextureEffect::Create(texture, matrix, params);
402 } 414 }
403 GrUnlockAndUnrefCachedBitmapTexture(texture); 415 GrUnlockAndUnrefCachedBitmapTexture(texture);
404 return effect; 416 return effect;
405 } 417 }
406 #endif 418 #endif
OLDNEW
« no previous file with comments | « include/core/SkPixelRef.h ('k') | src/core/SkBitmapProcState.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698