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

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

Issue 1784863003: Switch SkDropShaderImageFilter over to new onFilterImage interface (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Use x() & y() Created 4 years, 9 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 | « include/effects/SkDropShadowImageFilter.h ('k') | no next file » | 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 2013 Google Inc. 2 * Copyright 2013 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 "SkDropShadowImageFilter.h" 8 #include "SkDropShadowImageFilter.h"
9 9
10 #include "SkBitmap.h"
11 #include "SkBlurImageFilter.h" 10 #include "SkBlurImageFilter.h"
12 #include "SkCanvas.h" 11 #include "SkCanvas.h"
13 #include "SkColorMatrixFilter.h"
14 #include "SkDevice.h"
15 #include "SkReadBuffer.h" 12 #include "SkReadBuffer.h"
13 #include "SkSpecialImage.h"
14 #include "SkSpecialSurface.h"
16 #include "SkWriteBuffer.h" 15 #include "SkWriteBuffer.h"
17 16
18 SkDropShadowImageFilter::SkDropShadowImageFilter(SkScalar dx, SkScalar dy, 17 SkDropShadowImageFilter::SkDropShadowImageFilter(SkScalar dx, SkScalar dy,
19 SkScalar sigmaX, SkScalar sigma Y, SkColor color, 18 SkScalar sigmaX, SkScalar sigma Y, SkColor color,
20 ShadowMode shadowMode, SkImageF ilter* input, 19 ShadowMode shadowMode, SkImageF ilter* input,
21 const CropRect* cropRect) 20 const CropRect* cropRect)
22 : INHERITED(1, &input, cropRect) 21 : INHERITED(1, &input, cropRect)
23 , fDx(dx) 22 , fDx(dx)
24 , fDy(dy) 23 , fDy(dy)
25 , fSigmaX(sigmaX) 24 , fSigmaX(sigmaX)
26 , fSigmaY(sigmaY) 25 , fSigmaY(sigmaY)
27 , fColor(color) 26 , fColor(color)
28 , fShadowMode(shadowMode) 27 , fShadowMode(shadowMode) {
29 {
30 } 28 }
31 29
32 SkFlattenable* SkDropShadowImageFilter::CreateProc(SkReadBuffer& buffer) { 30 SkFlattenable* SkDropShadowImageFilter::CreateProc(SkReadBuffer& buffer) {
33 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); 31 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1);
34 SkScalar dx = buffer.readScalar(); 32 SkScalar dx = buffer.readScalar();
35 SkScalar dy = buffer.readScalar(); 33 SkScalar dy = buffer.readScalar();
36 SkScalar sigmaX = buffer.readScalar(); 34 SkScalar sigmaX = buffer.readScalar();
37 SkScalar sigmaY = buffer.readScalar(); 35 SkScalar sigmaY = buffer.readScalar();
38 SkColor color = buffer.readColor(); 36 SkColor color = buffer.readColor();
39 ShadowMode shadowMode = buffer.isVersionLT(SkReadBuffer::kDropShadowMode_Ver sion) ? 37 ShadowMode shadowMode = buffer.isVersionLT(SkReadBuffer::kDropShadowMode_Ver sion) ?
40 kDrawShadowAndForeground_ShadowMode : 38 kDrawShadowAndForeground_ShadowMode :
41 static_cast<ShadowMode>(buffer.readInt()); 39 static_cast<ShadowMode>(buffer.readInt());
42 return Create(dx, dy, sigmaX, sigmaY, color, shadowMode, common.getInput(0), 40 return Create(dx, dy, sigmaX, sigmaY, color, shadowMode, common.getInput(0),
43 &common.cropRect()); 41 &common.cropRect());
44 } 42 }
45 43
46 void SkDropShadowImageFilter::flatten(SkWriteBuffer& buffer) const { 44 void SkDropShadowImageFilter::flatten(SkWriteBuffer& buffer) const {
47 this->INHERITED::flatten(buffer); 45 this->INHERITED::flatten(buffer);
48 buffer.writeScalar(fDx); 46 buffer.writeScalar(fDx);
49 buffer.writeScalar(fDy); 47 buffer.writeScalar(fDy);
50 buffer.writeScalar(fSigmaX); 48 buffer.writeScalar(fSigmaX);
51 buffer.writeScalar(fSigmaY); 49 buffer.writeScalar(fSigmaY);
52 buffer.writeColor(fColor); 50 buffer.writeColor(fColor);
53 buffer.writeInt(static_cast<int>(fShadowMode)); 51 buffer.writeInt(static_cast<int>(fShadowMode));
54 } 52 }
55 53
56 bool SkDropShadowImageFilter::onFilterImageDeprecated(Proxy* proxy, const SkBitm ap& source, 54 SkSpecialImage* SkDropShadowImageFilter::onFilterImage(SkSpecialImage* source, c onst Context& ctx,
57 const Context& ctx, 55 SkIPoint* offset) const {
58 SkBitmap* result, SkIPoint * offset) const { 56 SkIPoint inputOffset = SkIPoint::Make(0, 0);
59 SkBitmap src = source; 57 SkAutoTUnref<SkSpecialImage> input(this->filterInput(0, source, ctx, &inputO ffset));
60 SkIPoint srcOffset = SkIPoint::Make(0, 0); 58 if (!input) {
61 if (!this->filterInputDeprecated(0, proxy, source, ctx, &src, &srcOffset)) 59 return nullptr;
62 return false;
63
64 SkIRect srcBounds = src.bounds();
65 srcBounds.offset(srcOffset);
66 SkIRect bounds;
67 if (!this->applyCropRect(ctx, srcBounds, &bounds)) {
68 return false;
69 } 60 }
70 61
71 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds .height())); 62 const SkIRect inputBounds = SkIRect::MakeXYWH(inputOffset.x(), inputOffset.y (),
72 if (nullptr == device.get()) { 63 input->width(), input->height( ));
73 return false; 64 SkIRect bounds;
65 if (!this->applyCropRect(ctx, inputBounds, &bounds)) {
66 return nullptr;
74 } 67 }
75 SkCanvas canvas(device.get()); 68
69 const SkImageInfo info = SkImageInfo::MakeN32(bounds.width(), bounds.height( ),
70 kPremul_SkAlphaType);
71 sk_sp<SkSpecialSurface> surf(source->makeSurface(info));
72 if (!surf) {
73 return nullptr;
74 }
75
76 SkCanvas* canvas = surf->getCanvas();
77 SkASSERT(canvas);
78
79 canvas->clear(0x0);
76 80
77 SkVector sigma = SkVector::Make(fSigmaX, fSigmaY); 81 SkVector sigma = SkVector::Make(fSigmaX, fSigmaY);
78 ctx.ctm().mapVectors(&sigma, 1); 82 ctx.ctm().mapVectors(&sigma, 1);
79 sigma.fX = SkMaxScalar(0, sigma.fX); 83 sigma.fX = SkMaxScalar(0, sigma.fX);
80 sigma.fY = SkMaxScalar(0, sigma.fY); 84 sigma.fY = SkMaxScalar(0, sigma.fY);
85
81 SkAutoTUnref<SkImageFilter> blurFilter(SkBlurImageFilter::Create(sigma.fX, s igma.fY)); 86 SkAutoTUnref<SkImageFilter> blurFilter(SkBlurImageFilter::Create(sigma.fX, s igma.fY));
82 SkPaint paint; 87 SkPaint paint;
83 paint.setImageFilter(blurFilter.get()); 88 paint.setImageFilter(blurFilter.get());
84 paint.setColorFilter(SkColorFilter::MakeModeFilter(fColor, SkXfermode::kSrcI n_Mode)); 89 paint.setColorFilter(SkColorFilter::MakeModeFilter(fColor, SkXfermode::kSrcI n_Mode));
85 paint.setXfermodeMode(SkXfermode::kSrcOver_Mode); 90 paint.setXfermodeMode(SkXfermode::kSrcOver_Mode);
91
86 SkVector offsetVec = SkVector::Make(fDx, fDy); 92 SkVector offsetVec = SkVector::Make(fDx, fDy);
87 ctx.ctm().mapVectors(&offsetVec, 1); 93 ctx.ctm().mapVectors(&offsetVec, 1);
88 canvas.translate(SkIntToScalar(srcOffset.fX - bounds.fLeft), 94
89 SkIntToScalar(srcOffset.fY - bounds.fTop)); 95 canvas->translate(SkIntToScalar(inputOffset.fX - bounds.fLeft),
90 canvas.drawBitmap(src, offsetVec.fX, offsetVec.fY, &paint); 96 SkIntToScalar(inputOffset.fY - bounds.fTop));
97 input->draw(canvas, offsetVec.fX, offsetVec.fY, &paint);
98
91 if (fShadowMode == kDrawShadowAndForeground_ShadowMode) { 99 if (fShadowMode == kDrawShadowAndForeground_ShadowMode) {
92 canvas.drawBitmap(src, 0, 0); 100 input->draw(canvas, 0, 0, nullptr);
93 } 101 }
94 *result = device->accessBitmap(false);
95 offset->fX = bounds.fLeft; 102 offset->fX = bounds.fLeft;
96 offset->fY = bounds.fTop; 103 offset->fY = bounds.fTop;
97 return true; 104 return surf->makeImageSnapshot().release();
98 } 105 }
99 106
100 SkRect SkDropShadowImageFilter::computeFastBounds(const SkRect& src) const { 107 SkRect SkDropShadowImageFilter::computeFastBounds(const SkRect& src) const {
101 SkRect bounds = this->getInput(0) ? this->getInput(0)->computeFastBounds(src ) : src; 108 SkRect bounds = this->getInput(0) ? this->getInput(0)->computeFastBounds(src ) : src;
102 SkRect shadowBounds = bounds; 109 SkRect shadowBounds = bounds;
103 shadowBounds.offset(fDx, fDy); 110 shadowBounds.offset(fDx, fDy);
104 shadowBounds.outset(SkScalarMul(fSigmaX, SkIntToScalar(3)), 111 shadowBounds.outset(SkScalarMul(fSigmaX, SkIntToScalar(3)),
105 SkScalarMul(fSigmaY, SkIntToScalar(3))); 112 SkScalarMul(fSigmaY, SkIntToScalar(3)));
106 if (fShadowMode == kDrawShadowAndForeground_ShadowMode) { 113 if (fShadowMode == kDrawShadowAndForeground_ShadowMode) {
107 bounds.join(shadowBounds); 114 bounds.join(shadowBounds);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 "kDrawShadowAndForeground", "kDrawShadowOnly" 153 "kDrawShadowAndForeground", "kDrawShadowOnly"
147 }; 154 };
148 155
149 static_assert(kShadowModeCount == SK_ARRAY_COUNT(gModeStrings), "enum_mismat ch"); 156 static_assert(kShadowModeCount == SK_ARRAY_COUNT(gModeStrings), "enum_mismat ch");
150 157
151 str->appendf(" mode: %s", gModeStrings[fShadowMode]); 158 str->appendf(" mode: %s", gModeStrings[fShadowMode]);
152 159
153 str->append(")"); 160 str->append(")");
154 } 161 }
155 #endif 162 #endif
OLDNEW
« no previous file with comments | « include/effects/SkDropShadowImageFilter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698