OLD | NEW |
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" |
11 #include "SkDevice.h" | 11 #include "SkDevice.h" |
12 #include "SkReadBuffer.h" | 12 #include "SkReadBuffer.h" |
13 #include "SkWriteBuffer.h" | 13 #include "SkWriteBuffer.h" |
14 #include "SkValidationUtils.h" | 14 #include "SkValidationUtils.h" |
15 | 15 |
16 //////////////////////////////////////////////////////////////////////////////// | 16 //////////////////////////////////////////////////////////////////////////////// |
17 #if SK_SUPPORT_GPU | 17 #if SK_SUPPORT_GPU |
18 #include "GrInvariantOutput.h" | 18 #include "GrInvariantOutput.h" |
19 #include "effects/GrSingleTextureEffect.h" | 19 #include "effects/GrSingleTextureEffect.h" |
20 #include "gl/GrGLFragmentProcessor.h" | 20 #include "gl/GrGLFragmentProcessor.h" |
21 #include "gl/GrGLTexture.h" | 21 #include "gl/GrGLTexture.h" |
22 #include "gl/builders/GrGLProgramBuilder.h" | 22 #include "gl/builders/GrGLProgramBuilder.h" |
| 23 #include "glsl/GrGLSLProgramDataManager.h" |
23 | 24 |
24 class GrMagnifierEffect : public GrSingleTextureEffect { | 25 class GrMagnifierEffect : public GrSingleTextureEffect { |
25 | 26 |
26 public: | 27 public: |
27 static GrFragmentProcessor* Create(GrTexture* texture, | 28 static GrFragmentProcessor* Create(GrTexture* texture, |
28 const SkRect& bounds, | 29 const SkRect& bounds, |
29 float xOffset, | 30 float xOffset, |
30 float yOffset, | 31 float yOffset, |
31 float xInvZoom, | 32 float xInvZoom, |
32 float yInvZoom, | 33 float yInvZoom, |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 float fYOffset; | 89 float fYOffset; |
89 float fXInvZoom; | 90 float fXInvZoom; |
90 float fYInvZoom; | 91 float fYInvZoom; |
91 float fXInvInset; | 92 float fXInvInset; |
92 float fYInvInset; | 93 float fYInvInset; |
93 | 94 |
94 typedef GrSingleTextureEffect INHERITED; | 95 typedef GrSingleTextureEffect INHERITED; |
95 }; | 96 }; |
96 | 97 |
97 // For brevity | 98 // For brevity |
98 typedef GrGLProgramDataManager::UniformHandle UniformHandle; | 99 typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; |
99 | 100 |
100 class GrGLMagnifierEffect : public GrGLFragmentProcessor { | 101 class GrGLMagnifierEffect : public GrGLFragmentProcessor { |
101 public: | 102 public: |
102 GrGLMagnifierEffect(const GrProcessor&); | 103 GrGLMagnifierEffect(const GrProcessor&); |
103 | 104 |
104 virtual void emitCode(EmitArgs&) override; | 105 virtual void emitCode(EmitArgs&) override; |
105 | 106 |
106 protected: | 107 protected: |
107 void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; | 108 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override
; |
108 | 109 |
109 private: | 110 private: |
110 UniformHandle fOffsetVar; | 111 UniformHandle fOffsetVar; |
111 UniformHandle fInvZoomVar; | 112 UniformHandle fInvZoomVar; |
112 UniformHandle fInvInsetVar; | 113 UniformHandle fInvInsetVar; |
113 UniformHandle fBoundsVar; | 114 UniformHandle fBoundsVar; |
114 | 115 |
115 typedef GrGLFragmentProcessor INHERITED; | 116 typedef GrGLFragmentProcessor INHERITED; |
116 }; | 117 }; |
117 | 118 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 fsBuilder->codeAppend("\t\tvec4 output_color = "); | 165 fsBuilder->codeAppend("\t\tvec4 output_color = "); |
165 fsBuilder->appendTextureLookup(args.fSamplers[0], "mix_coord"); | 166 fsBuilder->appendTextureLookup(args.fSamplers[0], "mix_coord"); |
166 fsBuilder->codeAppend(";\n"); | 167 fsBuilder->codeAppend(";\n"); |
167 | 168 |
168 fsBuilder->codeAppendf("\t\t%s = output_color;", args.fOutputColor); | 169 fsBuilder->codeAppendf("\t\t%s = output_color;", args.fOutputColor); |
169 SkString modulate; | 170 SkString modulate; |
170 GrGLSLMulVarBy4f(&modulate, args.fOutputColor, args.fInputColor); | 171 GrGLSLMulVarBy4f(&modulate, args.fOutputColor, args.fInputColor); |
171 fsBuilder->codeAppend(modulate.c_str()); | 172 fsBuilder->codeAppend(modulate.c_str()); |
172 } | 173 } |
173 | 174 |
174 void GrGLMagnifierEffect::onSetData(const GrGLProgramDataManager& pdman, | 175 void GrGLMagnifierEffect::onSetData(const GrGLSLProgramDataManager& pdman, |
175 const GrProcessor& effect) { | 176 const GrProcessor& effect) { |
176 const GrMagnifierEffect& zoom = effect.cast<GrMagnifierEffect>(); | 177 const GrMagnifierEffect& zoom = effect.cast<GrMagnifierEffect>(); |
177 pdman.set2f(fOffsetVar, zoom.x_offset(), zoom.y_offset()); | 178 pdman.set2f(fOffsetVar, zoom.x_offset(), zoom.y_offset()); |
178 pdman.set2f(fInvZoomVar, zoom.x_inv_zoom(), zoom.y_inv_zoom()); | 179 pdman.set2f(fInvZoomVar, zoom.x_inv_zoom(), zoom.y_inv_zoom()); |
179 pdman.set2f(fInvInsetVar, zoom.x_inv_inset(), zoom.y_inv_inset()); | 180 pdman.set2f(fInvInsetVar, zoom.x_inv_inset(), zoom.y_inv_inset()); |
180 pdman.set4f(fBoundsVar, zoom.bounds().x(), zoom.bounds().y(), | 181 pdman.set4f(fBoundsVar, zoom.bounds().x(), zoom.bounds().y(), |
181 zoom.bounds().width(), zoom.bounds().height()); | 182 zoom.bounds().width(), zoom.bounds().height()); |
182 } | 183 } |
183 | 184 |
184 ///////////////////////////////////////////////////////////////////// | 185 ///////////////////////////////////////////////////////////////////// |
185 | 186 |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 | 373 |
373 #ifndef SK_IGNORE_TO_STRING | 374 #ifndef SK_IGNORE_TO_STRING |
374 void SkMagnifierImageFilter::toString(SkString* str) const { | 375 void SkMagnifierImageFilter::toString(SkString* str) const { |
375 str->appendf("SkMagnifierImageFilter: ("); | 376 str->appendf("SkMagnifierImageFilter: ("); |
376 str->appendf("src: (%f,%f,%f,%f) ", | 377 str->appendf("src: (%f,%f,%f,%f) ", |
377 fSrcRect.fLeft, fSrcRect.fTop, fSrcRect.fRight, fSrcRect.fBotto
m); | 378 fSrcRect.fLeft, fSrcRect.fTop, fSrcRect.fRight, fSrcRect.fBotto
m); |
378 str->appendf("inset: %f", fInset); | 379 str->appendf("inset: %f", fInset); |
379 str->append(")"); | 380 str->append(")"); |
380 } | 381 } |
381 #endif | 382 #endif |
OLD | NEW |