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

Side by Side Diff: src/effects/SkColorFilters.cpp

Issue 491673002: Initial refactor of shaderbuilder (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 4 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/effects/SkBlurMaskFilter.cpp ('k') | src/effects/SkColorMatrixFilter.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 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
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 "SkBlitRow.h" 8 #include "SkBlitRow.h"
9 #include "SkColorFilter.h" 9 #include "SkColorFilter.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 return SkColorFilter::CreateModeFilter(color, mode); 120 return SkColorFilter::CreateModeFilter(color, mode);
121 } 121 }
122 122
123 /////////////////////////////////////////////////////////////////////////////// 123 ///////////////////////////////////////////////////////////////////////////////
124 #if SK_SUPPORT_GPU 124 #if SK_SUPPORT_GPU
125 #include "GrBlend.h" 125 #include "GrBlend.h"
126 #include "GrEffect.h" 126 #include "GrEffect.h"
127 #include "GrEffectUnitTest.h" 127 #include "GrEffectUnitTest.h"
128 #include "GrTBackendEffectFactory.h" 128 #include "GrTBackendEffectFactory.h"
129 #include "gl/GrGLEffect.h" 129 #include "gl/GrGLEffect.h"
130 #include "gl/GrGLShaderBuilder.h" 130 #include "gl/builders/GrGLProgramBuilder.h"
131 #include "SkGr.h" 131 #include "SkGr.h"
132 132
133 namespace { 133 namespace {
134 /** 134 /**
135 * A definition of blend equation for one coefficient. Generates a 135 * A definition of blend equation for one coefficient. Generates a
136 * blend_coeff * value "expression". 136 * blend_coeff * value "expression".
137 */ 137 */
138 template<typename ColorExpr> 138 template<typename ColorExpr>
139 static inline ColorExpr blend_term(SkXfermode::Coeff coeff, 139 static inline ColorExpr blend_term(SkXfermode::Coeff coeff,
140 const ColorExpr& src, 140 const ColorExpr& src,
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 215
216 SkXfermode::Mode mode() const { return fMode; } 216 SkXfermode::Mode mode() const { return fMode; }
217 GrColor color() const { return fColor; } 217 GrColor color() const { return fColor; }
218 218
219 class GLEffect : public GrGLEffect { 219 class GLEffect : public GrGLEffect {
220 public: 220 public:
221 GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&) 221 GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&)
222 : INHERITED(factory) { 222 : INHERITED(factory) {
223 } 223 }
224 224
225 virtual void emitCode(GrGLShaderBuilder* builder, 225 virtual void emitCode(GrGLProgramBuilder* builder,
226 const GrDrawEffect& drawEffect, 226 const GrDrawEffect& drawEffect,
227 const GrEffectKey& key, 227 const GrEffectKey& key,
228 const char* outputColor, 228 const char* outputColor,
229 const char* inputColor, 229 const char* inputColor,
230 const TransformedCoordsArray& coords, 230 const TransformedCoordsArray& coords,
231 const TextureSamplerArray& samplers) SK_OVERRIDE { 231 const TextureSamplerArray& samplers) SK_OVERRIDE {
232 SkXfermode::Mode mode = drawEffect.castEffect<ModeColorFilterEffect> ().mode(); 232 SkXfermode::Mode mode = drawEffect.castEffect<ModeColorFilterEffect> ().mode();
233 233
234 SkASSERT(SkXfermode::kDst_Mode != mode); 234 SkASSERT(SkXfermode::kDst_Mode != mode);
235 const char* colorFilterColorUniName = NULL; 235 const char* colorFilterColorUniName = NULL;
236 if (drawEffect.castEffect<ModeColorFilterEffect>().willUseFilterColo r()) { 236 if (drawEffect.castEffect<ModeColorFilterEffect>().willUseFilterColo r()) {
237 fFilterColorUni = builder->addUniform(GrGLShaderBuilder::kFragme nt_Visibility, 237 fFilterColorUni = builder->addUniform(GrGLProgramBuilder::kFragm ent_Visibility,
238 kVec4f_GrSLType, "FilterCo lor", 238 kVec4f_GrSLType, "FilterCo lor",
239 &colorFilterColorUniName); 239 &colorFilterColorUniName);
240 } 240 }
241 241
242 GrGLSLExpr4 filter = 242 GrGLSLExpr4 filter =
243 color_filter_expression(mode, GrGLSLExpr4(colorFilterColorUniNam e), GrGLSLExpr4(inputColor)); 243 color_filter_expression(mode, GrGLSLExpr4(colorFilterColorUniNam e), GrGLSLExpr4(inputColor));
244 244
245 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, filter.c_str()); 245 builder->getFragmentShaderBuilder()->
246 codeAppendf("\t%s = %s;\n", outputColor, filter.c_str());
246 } 247 }
247 248
248 static void GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&, 249 static void GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&,
249 GrEffectKeyBuilder* b) { 250 GrEffectKeyBuilder* b) {
250 const ModeColorFilterEffect& colorModeFilter = drawEffect.castEffect <ModeColorFilterEffect>(); 251 const ModeColorFilterEffect& colorModeFilter = drawEffect.castEffect <ModeColorFilterEffect>();
251 // The SL code does not depend on filter color at the moment, so no need to represent it 252 // The SL code does not depend on filter color at the moment, so no need to represent it
252 // in the key. 253 // in the key.
253 b->add32(colorModeFilter.mode()); 254 b->add32(colorModeFilter.mode());
254 } 255 }
255 256
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 matrix.postTranslate(SkIntToScalar(SkColorGetR(add)), 542 matrix.postTranslate(SkIntToScalar(SkColorGetR(add)),
542 SkIntToScalar(SkColorGetG(add)), 543 SkIntToScalar(SkColorGetG(add)),
543 SkIntToScalar(SkColorGetB(add)), 544 SkIntToScalar(SkColorGetB(add)),
544 0); 545 0);
545 return SkColorMatrixFilter::Create(matrix); 546 return SkColorMatrixFilter::Create(matrix);
546 } 547 }
547 548
548 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkColorFilter) 549 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkColorFilter)
549 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkModeColorFilter) 550 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkModeColorFilter)
550 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END 551 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
OLDNEW
« no previous file with comments | « src/effects/SkBlurMaskFilter.cpp ('k') | src/effects/SkColorMatrixFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698