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

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

Issue 1556003003: remove shadeSpan16 from shader (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: cleanup unused macro-generated procs Created 4 years, 11 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/core/SkBitmapProcShader.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 * Copyright 2011 Google Inc. 2 * Copyright 2011 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 "SkBitmapProcShader.h" 8 #include "SkBitmapProcShader.h"
9 #include "SkBitmapProcState.h" 9 #include "SkBitmapProcState.h"
10 #include "SkBitmapProvider.h" 10 #include "SkBitmapProvider.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 return SkShader::CreateBitmapShader(bm, mx, my, &lm); 61 return SkShader::CreateBitmapShader(bm, mx, my, &lm);
62 } 62 }
63 63
64 void SkBitmapProcShader::flatten(SkWriteBuffer& buffer) const { 64 void SkBitmapProcShader::flatten(SkWriteBuffer& buffer) const {
65 buffer.writeMatrix(this->getLocalMatrix()); 65 buffer.writeMatrix(this->getLocalMatrix());
66 buffer.writeBitmap(fRawBitmap); 66 buffer.writeBitmap(fRawBitmap);
67 buffer.writeUInt(fTileModeX); 67 buffer.writeUInt(fTileModeX);
68 buffer.writeUInt(fTileModeY); 68 buffer.writeUInt(fTileModeY);
69 } 69 }
70 70
71 static bool only_scale_and_translate(const SkMatrix& matrix) {
72 unsigned mask = SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask;
73 return (matrix.getType() & ~mask) == 0;
74 }
75
76 bool SkBitmapProcShader::isOpaque() const { 71 bool SkBitmapProcShader::isOpaque() const {
77 return fRawBitmap.isOpaque(); 72 return fRawBitmap.isOpaque();
78 } 73 }
79 74
80 SkShader::Context* SkBitmapProcShader::MakeContext(const SkShader& shader, 75 SkShader::Context* SkBitmapProcShader::MakeContext(const SkShader& shader,
81 TileMode tmx, TileMode tmy, 76 TileMode tmx, TileMode tmy,
82 const SkBitmapProvider& provi der, 77 const SkBitmapProvider& provi der,
83 const ContextRec& rec, void* storage) { 78 const ContextRec& rec, void* storage) {
84 SkMatrix totalInverse; 79 SkMatrix totalInverse;
85 // Do this first, so we know the matrix can be inverted. 80 // Do this first, so we know the matrix can be inverted.
(...skipping 17 matching lines...) Expand all
103 return MakeContext(*this, (TileMode)fTileModeX, (TileMode)fTileModeY, 98 return MakeContext(*this, (TileMode)fTileModeX, (TileMode)fTileModeY,
104 SkBitmapProvider(fRawBitmap), rec, storage); 99 SkBitmapProvider(fRawBitmap), rec, storage);
105 } 100 }
106 101
107 SkBitmapProcShader::BitmapProcShaderContext::BitmapProcShaderContext(const SkSha der& shader, 102 SkBitmapProcShader::BitmapProcShaderContext::BitmapProcShaderContext(const SkSha der& shader,
108 const Conte xtRec& rec, 103 const Conte xtRec& rec,
109 SkBitmapPro cState* state) 104 SkBitmapPro cState* state)
110 : INHERITED(shader, rec) 105 : INHERITED(shader, rec)
111 , fState(state) 106 , fState(state)
112 { 107 {
113 const SkPixmap& pixmap = fState->fPixmap; 108 fFlags = 0;
114 bool isOpaque = pixmap.isOpaque(); 109 if (fState->fPixmap.isOpaque() && (255 == this->getPaintAlpha())) {
115 110 fFlags |= kOpaqueAlpha_Flag;
116 // update fFlags
117 uint32_t flags = 0;
118 if (isOpaque && (255 == this->getPaintAlpha())) {
119 flags |= kOpaqueAlpha_Flag;
120 } 111 }
121
122 switch (pixmap.colorType()) {
123 case kRGB_565_SkColorType:
124 flags |= (kHasSpan16_Flag | kIntrinsicly16_Flag);
125 break;
126 case kIndex_8_SkColorType:
127 case kN32_SkColorType:
128 if (isOpaque) {
129 flags |= kHasSpan16_Flag;
130 }
131 break;
132 case kAlpha_8_SkColorType:
133 break; // never set kHasSpan16_Flag
134 default:
135 break;
136 }
137
138 if (rec.fPaint->isDither() && pixmap.colorType() != kRGB_565_SkColorType) {
139 // gradients can auto-dither in their 16bit sampler, but we don't so
140 // we clear the flag here.
141 flags &= ~kHasSpan16_Flag;
142 }
143
144 // if we're only 1-pixel high, and we don't rotate, then we can claim this
145 if (1 == pixmap.height() &&
146 only_scale_and_translate(this->getTotalInverse())) {
147 flags |= kConstInY32_Flag;
148 if (flags & kHasSpan16_Flag) {
149 flags |= kConstInY16_Flag;
150 }
151 }
152
153 fFlags = flags;
154 } 112 }
155 113
156 SkBitmapProcShader::BitmapProcShaderContext::~BitmapProcShaderContext() { 114 SkBitmapProcShader::BitmapProcShaderContext::~BitmapProcShaderContext() {
157 // The bitmap proc state has been created outside of the context on memory t hat will be freed 115 // The bitmap proc state has been created outside of the context on memory t hat will be freed
158 // elsewhere. Only call the destructor but leave the freeing of the memory t o the caller. 116 // elsewhere. Only call the destructor but leave the freeing of the memory t o the caller.
159 fState->~SkBitmapProcState(); 117 fState->~SkBitmapProcState();
160 } 118 }
161 119
162 #define BUF_MAX 128 120 #define BUF_MAX 128
163 121
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 } 172 }
215 173
216 SkShader::Context::ShadeProc SkBitmapProcShader::BitmapProcShaderContext::asASha deProc(void** ctx) { 174 SkShader::Context::ShadeProc SkBitmapProcShader::BitmapProcShaderContext::asASha deProc(void** ctx) {
217 if (fState->getShaderProc32()) { 175 if (fState->getShaderProc32()) {
218 *ctx = fState; 176 *ctx = fState;
219 return (ShadeProc)fState->getShaderProc32(); 177 return (ShadeProc)fState->getShaderProc32();
220 } 178 }
221 return nullptr; 179 return nullptr;
222 } 180 }
223 181
224 void SkBitmapProcShader::BitmapProcShaderContext::shadeSpan16(int x, int y, uint 16_t dstC[],
225 int count) {
226 const SkBitmapProcState& state = *fState;
227 if (state.getShaderProc16()) {
228 state.getShaderProc16()(&state, x, y, dstC, count);
229 return;
230 }
231
232 uint32_t buffer[BUF_MAX];
233 SkBitmapProcState::MatrixProc mproc = state.getMatrixProc();
234 SkBitmapProcState::SampleProc16 sproc = state.getSampleProc16();
235 int max = state.maxCountForBufferSize(sizeof(buffer));
236
237 SkASSERT(state.fPixmap.addr());
238
239 for (;;) {
240 int n = count;
241 if (n > max) {
242 n = max;
243 }
244 mproc(state, buffer, n, x, y);
245 sproc(state, buffer, n, dstC);
246
247 if ((count -= n) == 0) {
248 break;
249 }
250 x += n;
251 dstC += n;
252 }
253 }
254
255 /////////////////////////////////////////////////////////////////////////////// 182 ///////////////////////////////////////////////////////////////////////////////
256 183
257 #include "SkUnPreMultiply.h" 184 #include "SkUnPreMultiply.h"
258 #include "SkColorShader.h" 185 #include "SkColorShader.h"
259 #include "SkEmptyShader.h" 186 #include "SkEmptyShader.h"
260 187
261 // returns true and set color if the bitmap can be drawn as a single color 188 // returns true and set color if the bitmap can be drawn as a single color
262 // (for efficiency) 189 // (for efficiency)
263 static bool can_use_color_shader(const SkBitmap& bm, SkColor* color) { 190 static bool can_use_color_shader(const SkBitmap& bm, SkColor* color) {
264 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK 191 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 inner.reset(GrSimpleTextureEffect::Create(texture, matrix, params)); 334 inner.reset(GrSimpleTextureEffect::Create(texture, matrix, params));
408 } 335 }
409 336
410 if (kAlpha_8_SkColorType == fRawBitmap.colorType()) { 337 if (kAlpha_8_SkColorType == fRawBitmap.colorType()) {
411 return GrFragmentProcessor::MulOutputByInputUnpremulColor(inner); 338 return GrFragmentProcessor::MulOutputByInputUnpremulColor(inner);
412 } 339 }
413 return GrFragmentProcessor::MulOutputByInputAlpha(inner); 340 return GrFragmentProcessor::MulOutputByInputAlpha(inner);
414 } 341 }
415 342
416 #endif 343 #endif
OLDNEW
« no previous file with comments | « src/core/SkBitmapProcShader.h ('k') | src/core/SkBitmapProcState.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698