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

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

Issue 2041113004: sk_sp for gpu. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Reserve correctly. Created 4 years, 6 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/SkMatrixConvolutionImageFilter.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 "SkMagnifierImageFilter.h" 8 #include "SkMagnifierImageFilter.h"
9 9
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
(...skipping 10 matching lines...) Expand all
21 #include "GrInvariantOutput.h" 21 #include "GrInvariantOutput.h"
22 #include "effects/GrSingleTextureEffect.h" 22 #include "effects/GrSingleTextureEffect.h"
23 #include "glsl/GrGLSLFragmentProcessor.h" 23 #include "glsl/GrGLSLFragmentProcessor.h"
24 #include "glsl/GrGLSLFragmentShaderBuilder.h" 24 #include "glsl/GrGLSLFragmentShaderBuilder.h"
25 #include "glsl/GrGLSLProgramDataManager.h" 25 #include "glsl/GrGLSLProgramDataManager.h"
26 #include "glsl/GrGLSLUniformHandler.h" 26 #include "glsl/GrGLSLUniformHandler.h"
27 27
28 class GrMagnifierEffect : public GrSingleTextureEffect { 28 class GrMagnifierEffect : public GrSingleTextureEffect {
29 29
30 public: 30 public:
31 static GrFragmentProcessor* Create(GrTexture* texture, 31 static sk_sp<GrFragmentProcessor> Make(GrTexture* texture,
32 const SkRect& bounds, 32 const SkRect& bounds,
33 float xOffset, 33 float xOffset,
34 float yOffset, 34 float yOffset,
35 float xInvZoom, 35 float xInvZoom,
36 float yInvZoom, 36 float yInvZoom,
37 float xInvInset, 37 float xInvInset,
38 float yInvInset) { 38 float yInvInset) {
39 return new GrMagnifierEffect(texture, bounds, 39 return sk_sp<GrFragmentProcessor>(new GrMagnifierEffect(texture, bounds,
40 xOffset, yOffset, 40 xOffset, yOffset ,
41 xInvZoom, yInvZoom, 41 xInvZoom, yInvZo om,
42 xInvInset, yInvInset); 42 xInvInset, yInvI nset));
43 } 43 }
44 44
45 ~GrMagnifierEffect() override {}; 45 ~GrMagnifierEffect() override {};
46 46
47 const char* name() const override { return "Magnifier"; } 47 const char* name() const override { return "Magnifier"; }
48 48
49 const SkRect& bounds() const { return fBounds; } // Bounds of source imag e. 49 const SkRect& bounds() const { return fBounds; } // Bounds of source imag e.
50 // Offset to apply to zoomed pixels, (srcRect position / texture size). 50 // Offset to apply to zoomed pixels, (srcRect position / texture size).
51 float xOffset() const { return fXOffset; } 51 float xOffset() const { return fXOffset; }
52 float yOffset() const { return fYOffset; } 52 float yOffset() const { return fYOffset; }
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 GrProcessorKeyBuilder* b) const { 185 GrProcessorKeyBuilder* b) const {
186 GrGLMagnifierEffect::GenKey(*this, caps, b); 186 GrGLMagnifierEffect::GenKey(*this, caps, b);
187 } 187 }
188 188
189 GrGLSLFragmentProcessor* GrMagnifierEffect::onCreateGLSLInstance() const { 189 GrGLSLFragmentProcessor* GrMagnifierEffect::onCreateGLSLInstance() const {
190 return new GrGLMagnifierEffect; 190 return new GrGLMagnifierEffect;
191 } 191 }
192 192
193 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrMagnifierEffect); 193 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrMagnifierEffect);
194 194
195 const GrFragmentProcessor* GrMagnifierEffect::TestCreate(GrProcessorTestData* d) { 195 sk_sp<GrFragmentProcessor> GrMagnifierEffect::TestCreate(GrProcessorTestData* d) {
196 GrTexture* texture = d->fTextures[0]; 196 GrTexture* texture = d->fTextures[0];
197 const int kMaxWidth = 200; 197 const int kMaxWidth = 200;
198 const int kMaxHeight = 200; 198 const int kMaxHeight = 200;
199 const int kMaxInset = 20; 199 const int kMaxInset = 20;
200 uint32_t width = d->fRandom->nextULessThan(kMaxWidth); 200 uint32_t width = d->fRandom->nextULessThan(kMaxWidth);
201 uint32_t height = d->fRandom->nextULessThan(kMaxHeight); 201 uint32_t height = d->fRandom->nextULessThan(kMaxHeight);
202 uint32_t x = d->fRandom->nextULessThan(kMaxWidth - width); 202 uint32_t x = d->fRandom->nextULessThan(kMaxWidth - width);
203 uint32_t y = d->fRandom->nextULessThan(kMaxHeight - height); 203 uint32_t y = d->fRandom->nextULessThan(kMaxHeight - height);
204 uint32_t inset = d->fRandom->nextULessThan(kMaxInset); 204 uint32_t inset = d->fRandom->nextULessThan(kMaxInset);
205 205
206 GrFragmentProcessor* effect = GrMagnifierEffect::Create( 206 sk_sp<GrFragmentProcessor> effect(GrMagnifierEffect::Make(
207 texture, 207 texture,
208 SkRect::MakeWH(SkIntToScalar(kMaxWidth), SkIntToScalar(kMaxHeight)), 208 SkRect::MakeWH(SkIntToScalar(kMaxWidth), SkIntToScalar(kMaxHeight)),
209 (float) width / texture->width(), 209 (float) width / texture->width(),
210 (float) height / texture->height(), 210 (float) height / texture->height(),
211 texture->width() / (float) x, 211 texture->width() / (float) x,
212 texture->height() / (float) y, 212 texture->height() / (float) y,
213 (float) inset / texture->width(), 213 (float) inset / texture->width(),
214 (float) inset / texture->height()); 214 (float) inset / texture->height()));
215 SkASSERT(effect); 215 SkASSERT(effect);
216 return effect; 216 return effect;
217 } 217 }
218 218
219 /////////////////////////////////////////////////////////////////////////////// 219 ///////////////////////////////////////////////////////////////////////////////
220 220
221 bool GrMagnifierEffect::onIsEqual(const GrFragmentProcessor& sBase) const { 221 bool GrMagnifierEffect::onIsEqual(const GrFragmentProcessor& sBase) const {
222 const GrMagnifierEffect& s = sBase.cast<GrMagnifierEffect>(); 222 const GrMagnifierEffect& s = sBase.cast<GrMagnifierEffect>();
223 return (this->fBounds == s.fBounds && 223 return (this->fBounds == s.fBounds &&
224 this->fXOffset == s.fXOffset && 224 this->fXOffset == s.fXOffset &&
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 fSrcRect.height() * inputTexture->height() / bounds.height () - fSrcRect.y(); 317 fSrcRect.height() * inputTexture->height() / bounds.height () - fSrcRect.y();
318 int boundsY = inputTexture->origin() == kTopLeft_GrSurfaceOrigin 318 int boundsY = inputTexture->origin() == kTopLeft_GrSurfaceOrigin
319 ? bounds.y() 319 ? bounds.y()
320 : inputTexture->height() - bounds.height(); 320 : inputTexture->height() - bounds.height();
321 SkRect effectBounds = SkRect::MakeXYWH( 321 SkRect effectBounds = SkRect::MakeXYWH(
322 SkIntToScalar(bounds.x()) / inputTexture->width(), 322 SkIntToScalar(bounds.x()) / inputTexture->width(),
323 SkIntToScalar(boundsY) / inputTexture->height(), 323 SkIntToScalar(boundsY) / inputTexture->height(),
324 SkIntToScalar(inputTexture->width()) / bounds.width(), 324 SkIntToScalar(inputTexture->width()) / bounds.width(),
325 SkIntToScalar(inputTexture->height()) / bounds.height()); 325 SkIntToScalar(inputTexture->height()) / bounds.height());
326 // SRGBTODO: Handle sRGB here 326 // SRGBTODO: Handle sRGB here
327 sk_sp<GrFragmentProcessor> fp(GrMagnifierEffect::Create( 327 sk_sp<GrFragmentProcessor> fp(GrMagnifierEffect::Make(
328 inputTexture.get(), 328 inputTexture.get(),
329 effectBounds, 329 effectBounds,
330 fSrcRect.x() / inputText ure->width(), 330 fSrcRect.x() / inputText ure->width(),
331 yOffset / inputTexture-> height(), 331 yOffset / inputTexture-> height(),
332 invXZoom, 332 invXZoom,
333 invYZoom, 333 invYZoom,
334 bounds.width() * invInse t, 334 bounds.width() * invInse t,
335 bounds.height() * invIns et)); 335 bounds.height() * invIns et));
336 if (!fp) { 336 if (!fp) {
337 return nullptr; 337 return nullptr;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 414
415 #ifndef SK_IGNORE_TO_STRING 415 #ifndef SK_IGNORE_TO_STRING
416 void SkMagnifierImageFilter::toString(SkString* str) const { 416 void SkMagnifierImageFilter::toString(SkString* str) const {
417 str->appendf("SkMagnifierImageFilter: ("); 417 str->appendf("SkMagnifierImageFilter: (");
418 str->appendf("src: (%f,%f,%f,%f) ", 418 str->appendf("src: (%f,%f,%f,%f) ",
419 fSrcRect.fLeft, fSrcRect.fTop, fSrcRect.fRight, fSrcRect.fBotto m); 419 fSrcRect.fLeft, fSrcRect.fTop, fSrcRect.fRight, fSrcRect.fBotto m);
420 str->appendf("inset: %f", fInset); 420 str->appendf("inset: %f", fInset);
421 str->append(")"); 421 str->append(")");
422 } 422 }
423 #endif 423 #endif
OLDNEW
« no previous file with comments | « src/effects/SkLumaColorFilter.cpp ('k') | src/effects/SkMatrixConvolutionImageFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698