OLD | NEW |
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 "SkSurface.h" |
15 #include "SkReadBuffer.h" | 15 #include "SkReadBuffer.h" |
16 #include "SkWriteBuffer.h" | 16 #include "SkWriteBuffer.h" |
17 | 17 |
18 SkDropShadowImageFilter::SkDropShadowImageFilter(SkScalar dx, SkScalar dy, | 18 SkDropShadowImageFilter::SkDropShadowImageFilter(SkScalar dx, SkScalar dy, |
19 SkScalar sigmaX, SkScalar sigma
Y, SkColor color, | 19 SkScalar sigmaX, SkScalar sigma
Y, SkColor color, |
20 ShadowMode shadowMode, SkImageF
ilter* input, | 20 ShadowMode shadowMode, SkImageF
ilter* input, |
21 const CropRect* cropRect, uint3
2_t uniqueID) | 21 const CropRect* cropRect, uint3
2_t uniqueID) |
22 : INHERITED(1, &input, cropRect, uniqueID) | 22 : INHERITED(1, &input, cropRect, uniqueID) |
23 , fDx(dx) | 23 , fDx(dx) |
24 , fDy(dy) | 24 , fDy(dy) |
(...skipping 21 matching lines...) Expand all Loading... |
46 void SkDropShadowImageFilter::flatten(SkWriteBuffer& buffer) const { | 46 void SkDropShadowImageFilter::flatten(SkWriteBuffer& buffer) const { |
47 this->INHERITED::flatten(buffer); | 47 this->INHERITED::flatten(buffer); |
48 buffer.writeScalar(fDx); | 48 buffer.writeScalar(fDx); |
49 buffer.writeScalar(fDy); | 49 buffer.writeScalar(fDy); |
50 buffer.writeScalar(fSigmaX); | 50 buffer.writeScalar(fSigmaX); |
51 buffer.writeScalar(fSigmaY); | 51 buffer.writeScalar(fSigmaY); |
52 buffer.writeColor(fColor); | 52 buffer.writeColor(fColor); |
53 buffer.writeInt(static_cast<int>(fShadowMode)); | 53 buffer.writeInt(static_cast<int>(fShadowMode)); |
54 } | 54 } |
55 | 55 |
56 bool SkDropShadowImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& source
, | 56 bool SkDropShadowImageFilter::onFilterImage(Proxy* proxy, SkImage& source, |
57 const Context& ctx, | 57 const Context& ctx, |
58 SkBitmap* result, SkIPoint* offset)
const | 58 SkAutoTUnref<SkImage>& result, SkIPo
int* offset) const |
59 { | 59 { |
60 SkBitmap src = source; | 60 SkAutoTUnref<SkImage> src(&source); |
61 SkIPoint srcOffset = SkIPoint::Make(0, 0); | 61 SkIPoint srcOffset = SkIPoint::Make(0, 0); |
62 if (getInput(0) && !getInput(0)->filterImage(proxy, source, ctx, &src, &srcO
ffset)) | 62 if (getInput(0) && !getInput(0)->filterImage(proxy, source, ctx, src, &srcOf
fset)) |
63 return false; | 63 return false; |
64 | 64 |
65 SkIRect bounds; | 65 SkIRect bounds; |
66 if (!this->applyCropRect(ctx, src, srcOffset, &bounds)) { | 66 if (!this->applyCropRect(ctx, *src, srcOffset, &bounds)) { |
67 return false; | 67 return false; |
68 } | 68 } |
69 | 69 |
70 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds
.height())); | 70 SkAutoTUnref<SkSurface> surface(proxy->createSurface(bounds.width(), bounds.
height())); |
71 if (NULL == device.get()) { | 71 if (NULL == surface.get()) { |
72 return false; | 72 return false; |
73 } | 73 } |
74 SkCanvas canvas(device.get()); | 74 SkCanvas* canvas = surface->getCanvas(); |
75 | 75 |
76 SkVector sigma = SkVector::Make(fSigmaX, fSigmaY); | 76 SkVector sigma = SkVector::Make(fSigmaX, fSigmaY); |
77 ctx.ctm().mapVectors(&sigma, 1); | 77 ctx.ctm().mapVectors(&sigma, 1); |
78 sigma.fX = SkMaxScalar(0, sigma.fX); | 78 sigma.fX = SkMaxScalar(0, sigma.fX); |
79 sigma.fY = SkMaxScalar(0, sigma.fY); | 79 sigma.fY = SkMaxScalar(0, sigma.fY); |
80 SkAutoTUnref<SkImageFilter> blurFilter(SkBlurImageFilter::Create(sigma.fX, s
igma.fY)); | 80 SkAutoTUnref<SkImageFilter> blurFilter(SkBlurImageFilter::Create(sigma.fX, s
igma.fY)); |
81 SkAutoTUnref<SkColorFilter> colorFilter( | 81 SkAutoTUnref<SkColorFilter> colorFilter( |
82 SkColorFilter::CreateModeFilter(fColor, SkXfermode::kSrcIn_Mode)); | 82 SkColorFilter::CreateModeFilter(fColor, SkXfermode::kSrcIn_Mode)); |
83 SkPaint paint; | 83 SkPaint paint; |
84 paint.setImageFilter(blurFilter.get()); | 84 paint.setImageFilter(blurFilter.get()); |
85 paint.setColorFilter(colorFilter.get()); | 85 paint.setColorFilter(colorFilter.get()); |
86 paint.setXfermodeMode(SkXfermode::kSrcOver_Mode); | 86 paint.setXfermodeMode(SkXfermode::kSrcOver_Mode); |
87 SkVector offsetVec = SkVector::Make(fDx, fDy); | 87 SkVector offsetVec = SkVector::Make(fDx, fDy); |
88 ctx.ctm().mapVectors(&offsetVec, 1); | 88 ctx.ctm().mapVectors(&offsetVec, 1); |
89 canvas.translate(SkIntToScalar(srcOffset.fX - bounds.fLeft), | 89 canvas->translate(SkIntToScalar(srcOffset.fX - bounds.fLeft), |
90 SkIntToScalar(srcOffset.fY - bounds.fTop)); | 90 SkIntToScalar(srcOffset.fY - bounds.fTop)); |
91 canvas.drawBitmap(src, offsetVec.fX, offsetVec.fY, &paint); | 91 canvas->drawImage(src, offsetVec.fX, offsetVec.fY, &paint); |
92 if (fShadowMode == kDrawShadowAndForeground_ShadowMode) { | 92 if (fShadowMode == kDrawShadowAndForeground_ShadowMode) { |
93 canvas.drawBitmap(src, 0, 0); | 93 canvas->drawImage(src, 0, 0); |
94 } | 94 } |
95 *result = device->accessBitmap(false); | 95 |
| 96 SkImage* image = surface->newImageSnapshot(SkSurface::kYes_Budgeted); |
| 97 if (NULL == image) { |
| 98 return false; |
| 99 } |
| 100 result.reset(image); |
| 101 |
96 offset->fX = bounds.fLeft; | 102 offset->fX = bounds.fLeft; |
97 offset->fY = bounds.fTop; | 103 offset->fY = bounds.fTop; |
98 return true; | 104 return true; |
99 } | 105 } |
100 | 106 |
101 void SkDropShadowImageFilter::computeFastBounds(const SkRect& src, SkRect* dst)
const { | 107 void SkDropShadowImageFilter::computeFastBounds(const SkRect& src, SkRect* dst)
const { |
102 if (getInput(0)) { | 108 if (getInput(0)) { |
103 getInput(0)->computeFastBounds(src, dst); | 109 getInput(0)->computeFastBounds(src, dst); |
104 } else { | 110 } else { |
105 *dst = src; | 111 *dst = src; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 "kDrawShadowAndForeground", "kDrawShadowOnly" | 159 "kDrawShadowAndForeground", "kDrawShadowOnly" |
154 }; | 160 }; |
155 | 161 |
156 SK_COMPILE_ASSERT(kShadowModeCount == SK_ARRAY_COUNT(gModeStrings), enum_mis
match); | 162 SK_COMPILE_ASSERT(kShadowModeCount == SK_ARRAY_COUNT(gModeStrings), enum_mis
match); |
157 | 163 |
158 str->appendf(" mode: %s", gModeStrings[fShadowMode]); | 164 str->appendf(" mode: %s", gModeStrings[fShadowMode]); |
159 | 165 |
160 str->append(")"); | 166 str->append(")"); |
161 } | 167 } |
162 #endif | 168 #endif |
OLD | NEW |