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

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

Issue 88243004: Enhance SkDropShadowImageFilter to support separate X & Y sigmas, and crop rect. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years 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 | Annotate | Revision Log
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" 10 #include "SkBitmap.h"
11 #include "SkBlurImageFilter.h" 11 #include "SkBlurImageFilter.h"
12 #include "SkCanvas.h" 12 #include "SkCanvas.h"
13 #include "SkColorMatrixFilter.h" 13 #include "SkColorMatrixFilter.h"
14 #include "SkDevice.h" 14 #include "SkDevice.h"
15 #include "SkFlattenableBuffers.h" 15 #include "SkFlattenableBuffers.h"
16 16
17 SkDropShadowImageFilter::SkDropShadowImageFilter(SkScalar dx, SkScalar dy, SkSca lar sigma, SkColor color, SkImageFilter* input) 17 SkDropShadowImageFilter::SkDropShadowImageFilter(SkScalar dx, SkScalar dy, SkSca lar sigma, SkColor color, SkImageFilter* input)
18 : SkImageFilter(input) 18 : INHERITED(input)
19 , fDx(dx) 19 , fDx(dx)
20 , fDy(dy) 20 , fDy(dy)
21 , fSigma(sigma) 21 , fSigmaX(sigma)
22 , fSigmaY(sigma)
22 , fColor(color) 23 , fColor(color)
23 { 24 {
24 } 25 }
26
27 SkDropShadowImageFilter::SkDropShadowImageFilter(SkScalar dx, SkScalar dy, SkSca lar sigmaX, SkScalar sigmaY, SkColor color, SkImageFilter* input, const CropRect * cropRect)
28 : INHERITED(input, cropRect)
29 , fDx(dx)
30 , fDy(dy)
31 , fSigmaX(sigmaX)
32 , fSigmaY(sigmaY)
33 , fColor(color)
34 {
35 }
25 36
26 SkDropShadowImageFilter::SkDropShadowImageFilter(SkFlattenableReadBuffer& buffer ) 37 SkDropShadowImageFilter::SkDropShadowImageFilter(SkFlattenableReadBuffer& buffer )
27 : INHERITED(1, buffer) { 38 : INHERITED(1, buffer) {
28 fDx = buffer.readScalar(); 39 fDx = buffer.readScalar();
29 fDy = buffer.readScalar(); 40 fDy = buffer.readScalar();
30 fSigma = buffer.readScalar(); 41 fSigmaX = buffer.readScalar();
42 fSigmaY = buffer.readScalar();
31 fColor = buffer.readColor(); 43 fColor = buffer.readColor();
32 buffer.validate(SkScalarIsFinite(fDx) && 44 buffer.validate(SkScalarIsFinite(fDx) &&
33 SkScalarIsFinite(fDy) && 45 SkScalarIsFinite(fDy) &&
34 SkScalarIsFinite(fSigma)); 46 SkScalarIsFinite(fSigmaX) &&
47 SkScalarIsFinite(fSigmaY));
35 } 48 }
36 49
37 void SkDropShadowImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const 50 void SkDropShadowImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const
38 { 51 {
39 this->INHERITED::flatten(buffer); 52 this->INHERITED::flatten(buffer);
40 buffer.writeScalar(fDx); 53 buffer.writeScalar(fDx);
41 buffer.writeScalar(fDy); 54 buffer.writeScalar(fDy);
42 buffer.writeScalar(fSigma); 55 buffer.writeScalar(fSigmaX);
56 buffer.writeScalar(fSigmaY);
43 buffer.writeColor(fColor); 57 buffer.writeColor(fColor);
44 } 58 }
45 59
46 bool SkDropShadowImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& source , const SkMatrix& matrix, SkBitmap* result, SkIPoint* loc) 60 bool SkDropShadowImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& source , const SkMatrix& matrix, SkBitmap* result, SkIPoint* loc)
47 { 61 {
48 SkBitmap src = source; 62 SkBitmap src = source;
49 if (getInput(0) && !getInput(0)->filterImage(proxy, source, matrix, &src, lo c)) 63 if (getInput(0) && !getInput(0)->filterImage(proxy, source, matrix, &src, lo c))
50 return false; 64 return false;
51 65
52 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(src.width(), src.heigh t())); 66 SkIRect bounds;
67 src.getBounds(&bounds);
68 if (!this->applyCropRect(&bounds, matrix)) {
69 return false;
70 }
71
72 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds .height()));
53 SkCanvas canvas(device.get()); 73 SkCanvas canvas(device.get());
54 74
55 SkAutoTUnref<SkImageFilter> blurFilter(new SkBlurImageFilter(fSigma, fSigma) ); 75 SkAutoTUnref<SkImageFilter> blurFilter(new SkBlurImageFilter(fSigmaX, fSigma Y));
56 SkAutoTUnref<SkColorFilter> colorFilter(SkColorFilter::CreateModeFilter(fCol or, SkXfermode::kSrcIn_Mode)); 76 SkAutoTUnref<SkColorFilter> colorFilter(SkColorFilter::CreateModeFilter(fCol or, SkXfermode::kSrcIn_Mode));
57 SkPaint paint; 77 SkPaint paint;
58 paint.setImageFilter(blurFilter.get()); 78 paint.setImageFilter(blurFilter.get());
59 paint.setColorFilter(colorFilter.get()); 79 paint.setColorFilter(colorFilter.get());
60 paint.setXfermodeMode(SkXfermode::kSrcOver_Mode); 80 paint.setXfermodeMode(SkXfermode::kSrcOver_Mode);
81 canvas.translate(-SkIntToScalar(bounds.fLeft), -SkIntToScalar(bounds.fTop));
61 canvas.drawBitmap(src, fDx, fDy, &paint); 82 canvas.drawBitmap(src, fDx, fDy, &paint);
62 canvas.drawBitmap(src, 0, 0); 83 canvas.drawBitmap(src, 0, 0);
63 *result = device->accessBitmap(false); 84 *result = device->accessBitmap(false);
85 loc->fX += bounds.fLeft;
86 loc->fY += bounds.fTop;
64 return true; 87 return true;
65 } 88 }
OLDNEW
« include/effects/SkDropShadowImageFilter.h ('K') | « include/effects/SkDropShadowImageFilter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698