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

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

Issue 1287023009: Added tree structure to GrGLFragmentProcessor, i.e. GL instances (Closed) Base URL: https://skia.googlesource.com/skia@cs3_isequal_nonrecursive
Patch Set: moved onSetData from public to protected, onCreateGLInstance from public to private in subclasses Created 5 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/SkLumaColorFilter.cpp ('k') | src/effects/SkMorphologyImageFilter.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 The Android Open Source Project 2 * Copyright 2012 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 "SkBitmap.h" 8 #include "SkBitmap.h"
9 #include "SkMagnifierImageFilter.h" 9 #include "SkMagnifierImageFilter.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
(...skipping 29 matching lines...) Expand all
40 xInvZoom, 40 xInvZoom,
41 yInvZoom, 41 yInvZoom,
42 xInvInset, 42 xInvInset,
43 yInvInset)); 43 yInvInset));
44 } 44 }
45 45
46 virtual ~GrMagnifierEffect() {}; 46 virtual ~GrMagnifierEffect() {};
47 47
48 const char* name() const override { return "Magnifier"; } 48 const char* name() const override { return "Magnifier"; }
49 49
50 GrGLFragmentProcessor* createGLInstance() const override;
51
52 const SkRect& bounds() const { return fBounds; } // Bounds of source imag e. 50 const SkRect& bounds() const { return fBounds; } // Bounds of source imag e.
53 // Offset to apply to zoomed pixels, (srcRect position / texture size). 51 // Offset to apply to zoomed pixels, (srcRect position / texture size).
54 float x_offset() const { return fXOffset; } 52 float x_offset() const { return fXOffset; }
55 float y_offset() const { return fYOffset; } 53 float y_offset() const { return fYOffset; }
56 54
57 // Scale to apply to zoomed pixels (srcRect size / bounds size). 55 // Scale to apply to zoomed pixels (srcRect size / bounds size).
58 float x_inv_zoom() const { return fXInvZoom; } 56 float x_inv_zoom() const { return fXInvZoom; }
59 float y_inv_zoom() const { return fYInvZoom; } 57 float y_inv_zoom() const { return fYInvZoom; }
60 58
61 // 1/radius over which to transition from unzoomed to zoomed pixels (bounds size / inset). 59 // 1/radius over which to transition from unzoomed to zoomed pixels (bounds size / inset).
(...skipping 14 matching lines...) Expand all
76 , fBounds(bounds) 74 , fBounds(bounds)
77 , fXOffset(xOffset) 75 , fXOffset(xOffset)
78 , fYOffset(yOffset) 76 , fYOffset(yOffset)
79 , fXInvZoom(xInvZoom) 77 , fXInvZoom(xInvZoom)
80 , fYInvZoom(yInvZoom) 78 , fYInvZoom(yInvZoom)
81 , fXInvInset(xInvInset) 79 , fXInvInset(xInvInset)
82 , fYInvInset(yInvInset) { 80 , fYInvInset(yInvInset) {
83 this->initClassID<GrMagnifierEffect>(); 81 this->initClassID<GrMagnifierEffect>();
84 } 82 }
85 83
84 GrGLFragmentProcessor* onCreateGLInstance() const override;
85
86 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov erride; 86 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov erride;
87 87
88 bool onIsEqual(const GrFragmentProcessor&) const override; 88 bool onIsEqual(const GrFragmentProcessor&) const override;
89 89
90 void onComputeInvariantOutput(GrInvariantOutput* inout) const override; 90 void onComputeInvariantOutput(GrInvariantOutput* inout) const override;
91 91
92 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; 92 GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
93 93
94 SkRect fBounds; 94 SkRect fBounds;
95 float fXOffset; 95 float fXOffset;
96 float fYOffset; 96 float fYOffset;
97 float fXInvZoom; 97 float fXInvZoom;
98 float fYInvZoom; 98 float fYInvZoom;
99 float fXInvInset; 99 float fXInvInset;
100 float fYInvInset; 100 float fYInvInset;
101 101
102 typedef GrSingleTextureEffect INHERITED; 102 typedef GrSingleTextureEffect INHERITED;
103 }; 103 };
104 104
105 // For brevity 105 // For brevity
106 typedef GrGLProgramDataManager::UniformHandle UniformHandle; 106 typedef GrGLProgramDataManager::UniformHandle UniformHandle;
107 107
108 class GrGLMagnifierEffect : public GrGLFragmentProcessor { 108 class GrGLMagnifierEffect : public GrGLFragmentProcessor {
109 public: 109 public:
110 GrGLMagnifierEffect(const GrProcessor&); 110 GrGLMagnifierEffect(const GrProcessor&);
111 111
112 virtual void emitCode(EmitArgs&) override; 112 virtual void emitCode(EmitArgs&) override;
113 113
114 void setData(const GrGLProgramDataManager&, const GrProcessor&) override; 114 protected:
115 void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override;
115 116
116 private: 117 private:
117 UniformHandle fOffsetVar; 118 UniformHandle fOffsetVar;
118 UniformHandle fInvZoomVar; 119 UniformHandle fInvZoomVar;
119 UniformHandle fInvInsetVar; 120 UniformHandle fInvInsetVar;
120 UniformHandle fBoundsVar; 121 UniformHandle fBoundsVar;
121 122
122 typedef GrGLFragmentProcessor INHERITED; 123 typedef GrGLFragmentProcessor INHERITED;
123 }; 124 };
124 125
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 fsBuilder->codeAppend("\t\tvec4 output_color = "); 172 fsBuilder->codeAppend("\t\tvec4 output_color = ");
172 fsBuilder->appendTextureLookup(args.fSamplers[0], "mix_coord"); 173 fsBuilder->appendTextureLookup(args.fSamplers[0], "mix_coord");
173 fsBuilder->codeAppend(";\n"); 174 fsBuilder->codeAppend(";\n");
174 175
175 fsBuilder->codeAppendf("\t\t%s = output_color;", args.fOutputColor); 176 fsBuilder->codeAppendf("\t\t%s = output_color;", args.fOutputColor);
176 SkString modulate; 177 SkString modulate;
177 GrGLSLMulVarBy4f(&modulate, args.fOutputColor, args.fInputColor); 178 GrGLSLMulVarBy4f(&modulate, args.fOutputColor, args.fInputColor);
178 fsBuilder->codeAppend(modulate.c_str()); 179 fsBuilder->codeAppend(modulate.c_str());
179 } 180 }
180 181
181 void GrGLMagnifierEffect::setData(const GrGLProgramDataManager& pdman, 182 void GrGLMagnifierEffect::onSetData(const GrGLProgramDataManager& pdman,
182 const GrProcessor& effect) { 183 const GrProcessor& effect) {
183 const GrMagnifierEffect& zoom = effect.cast<GrMagnifierEffect>(); 184 const GrMagnifierEffect& zoom = effect.cast<GrMagnifierEffect>();
184 pdman.set2f(fOffsetVar, zoom.x_offset(), zoom.y_offset()); 185 pdman.set2f(fOffsetVar, zoom.x_offset(), zoom.y_offset());
185 pdman.set2f(fInvZoomVar, zoom.x_inv_zoom(), zoom.y_inv_zoom()); 186 pdman.set2f(fInvZoomVar, zoom.x_inv_zoom(), zoom.y_inv_zoom());
186 pdman.set2f(fInvInsetVar, zoom.x_inv_inset(), zoom.y_inv_inset()); 187 pdman.set2f(fInvInsetVar, zoom.x_inv_inset(), zoom.y_inv_inset());
187 pdman.set4f(fBoundsVar, zoom.bounds().x(), zoom.bounds().y(), 188 pdman.set4f(fBoundsVar, zoom.bounds().x(), zoom.bounds().y(),
188 zoom.bounds().width(), zoom.bounds().height()); 189 zoom.bounds().width(), zoom.bounds().height());
189 } 190 }
190 191
191 ///////////////////////////////////////////////////////////////////// 192 /////////////////////////////////////////////////////////////////////
192 193
193 void GrMagnifierEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, 194 void GrMagnifierEffect::onGetGLProcessorKey(const GrGLSLCaps& caps,
194 GrProcessorKeyBuilder* b) const { 195 GrProcessorKeyBuilder* b) const {
195 GrGLMagnifierEffect::GenKey(*this, caps, b); 196 GrGLMagnifierEffect::GenKey(*this, caps, b);
196 } 197 }
197 198
198 GrGLFragmentProcessor* GrMagnifierEffect::createGLInstance() const { 199 GrGLFragmentProcessor* GrMagnifierEffect::onCreateGLInstance() const {
199 return SkNEW_ARGS(GrGLMagnifierEffect, (*this)); 200 return SkNEW_ARGS(GrGLMagnifierEffect, (*this));
200 } 201 }
201 202
202 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrMagnifierEffect); 203 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrMagnifierEffect);
203 204
204 GrFragmentProcessor* GrMagnifierEffect::TestCreate(GrProcessorTestData* d) { 205 GrFragmentProcessor* GrMagnifierEffect::TestCreate(GrProcessorTestData* d) {
205 GrTexture* texture = d->fTextures[0]; 206 GrTexture* texture = d->fTextures[0];
206 const int kMaxWidth = 200; 207 const int kMaxWidth = 200;
207 const int kMaxHeight = 200; 208 const int kMaxHeight = 200;
208 const int kMaxInset = 20; 209 const int kMaxInset = 20;
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 380
380 #ifndef SK_IGNORE_TO_STRING 381 #ifndef SK_IGNORE_TO_STRING
381 void SkMagnifierImageFilter::toString(SkString* str) const { 382 void SkMagnifierImageFilter::toString(SkString* str) const {
382 str->appendf("SkMagnifierImageFilter: ("); 383 str->appendf("SkMagnifierImageFilter: (");
383 str->appendf("src: (%f,%f,%f,%f) ", 384 str->appendf("src: (%f,%f,%f,%f) ",
384 fSrcRect.fLeft, fSrcRect.fTop, fSrcRect.fRight, fSrcRect.fBotto m); 385 fSrcRect.fLeft, fSrcRect.fTop, fSrcRect.fRight, fSrcRect.fBotto m);
385 str->appendf("inset: %f", fInset); 386 str->appendf("inset: %f", fInset);
386 str->append(")"); 387 str->append(")");
387 } 388 }
388 #endif 389 #endif
OLDNEW
« no previous file with comments | « src/effects/SkLumaColorFilter.cpp ('k') | src/effects/SkMorphologyImageFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698