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 "SkBlurImageFilter.h" | 10 #include "SkBlurImageFilter.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 void SkDropShadowImageFilter::flatten(SkWriteBuffer& buffer) const { | 44 void SkDropShadowImageFilter::flatten(SkWriteBuffer& buffer) const { |
45 this->INHERITED::flatten(buffer); | 45 this->INHERITED::flatten(buffer); |
46 buffer.writeScalar(fDx); | 46 buffer.writeScalar(fDx); |
47 buffer.writeScalar(fDy); | 47 buffer.writeScalar(fDy); |
48 buffer.writeScalar(fSigmaX); | 48 buffer.writeScalar(fSigmaX); |
49 buffer.writeScalar(fSigmaY); | 49 buffer.writeScalar(fSigmaY); |
50 buffer.writeColor(fColor); | 50 buffer.writeColor(fColor); |
51 buffer.writeInt(static_cast<int>(fShadowMode)); | 51 buffer.writeInt(static_cast<int>(fShadowMode)); |
52 } | 52 } |
53 | 53 |
54 SkSpecialImage* SkDropShadowImageFilter::onFilterImage(SkSpecialImage* source, c
onst Context& ctx, | 54 sk_sp<SkSpecialImage> SkDropShadowImageFilter::onFilterImage(SkSpecialImage* sou
rce, |
55 SkIPoint* offset) const { | 55 const Context& ctx, |
| 56 SkIPoint* offset) c
onst { |
56 SkIPoint inputOffset = SkIPoint::Make(0, 0); | 57 SkIPoint inputOffset = SkIPoint::Make(0, 0); |
57 SkAutoTUnref<SkSpecialImage> input(this->filterInput(0, source, ctx, &inputO
ffset)); | 58 sk_sp<SkSpecialImage> input(this->filterInput(0, source, ctx, &inputOffset))
; |
58 if (!input) { | 59 if (!input) { |
59 return nullptr; | 60 return nullptr; |
60 } | 61 } |
61 | 62 |
62 const SkIRect inputBounds = SkIRect::MakeXYWH(inputOffset.x(), inputOffset.y
(), | 63 const SkIRect inputBounds = SkIRect::MakeXYWH(inputOffset.x(), inputOffset.y
(), |
63 input->width(), input->height(
)); | 64 input->width(), input->height(
)); |
64 SkIRect bounds; | 65 SkIRect bounds; |
65 if (!this->applyCropRect(ctx, inputBounds, &bounds)) { | 66 if (!this->applyCropRect(ctx, inputBounds, &bounds)) { |
66 return nullptr; | 67 return nullptr; |
67 } | 68 } |
(...skipping 26 matching lines...) Expand all Loading... |
94 | 95 |
95 canvas->translate(SkIntToScalar(inputOffset.fX - bounds.fLeft), | 96 canvas->translate(SkIntToScalar(inputOffset.fX - bounds.fLeft), |
96 SkIntToScalar(inputOffset.fY - bounds.fTop)); | 97 SkIntToScalar(inputOffset.fY - bounds.fTop)); |
97 input->draw(canvas, offsetVec.fX, offsetVec.fY, &paint); | 98 input->draw(canvas, offsetVec.fX, offsetVec.fY, &paint); |
98 | 99 |
99 if (fShadowMode == kDrawShadowAndForeground_ShadowMode) { | 100 if (fShadowMode == kDrawShadowAndForeground_ShadowMode) { |
100 input->draw(canvas, 0, 0, nullptr); | 101 input->draw(canvas, 0, 0, nullptr); |
101 } | 102 } |
102 offset->fX = bounds.fLeft; | 103 offset->fX = bounds.fLeft; |
103 offset->fY = bounds.fTop; | 104 offset->fY = bounds.fTop; |
104 return surf->makeImageSnapshot().release(); | 105 return surf->makeImageSnapshot(); |
105 } | 106 } |
106 | 107 |
107 SkRect SkDropShadowImageFilter::computeFastBounds(const SkRect& src) const { | 108 SkRect SkDropShadowImageFilter::computeFastBounds(const SkRect& src) const { |
108 SkRect bounds = this->getInput(0) ? this->getInput(0)->computeFastBounds(src
) : src; | 109 SkRect bounds = this->getInput(0) ? this->getInput(0)->computeFastBounds(src
) : src; |
109 SkRect shadowBounds = bounds; | 110 SkRect shadowBounds = bounds; |
110 shadowBounds.offset(fDx, fDy); | 111 shadowBounds.offset(fDx, fDy); |
111 shadowBounds.outset(SkScalarMul(fSigmaX, SkIntToScalar(3)), | 112 shadowBounds.outset(SkScalarMul(fSigmaX, SkIntToScalar(3)), |
112 SkScalarMul(fSigmaY, SkIntToScalar(3))); | 113 SkScalarMul(fSigmaY, SkIntToScalar(3))); |
113 if (fShadowMode == kDrawShadowAndForeground_ShadowMode) { | 114 if (fShadowMode == kDrawShadowAndForeground_ShadowMode) { |
114 bounds.join(shadowBounds); | 115 bounds.join(shadowBounds); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 "kDrawShadowAndForeground", "kDrawShadowOnly" | 154 "kDrawShadowAndForeground", "kDrawShadowOnly" |
154 }; | 155 }; |
155 | 156 |
156 static_assert(kShadowModeCount == SK_ARRAY_COUNT(gModeStrings), "enum_mismat
ch"); | 157 static_assert(kShadowModeCount == SK_ARRAY_COUNT(gModeStrings), "enum_mismat
ch"); |
157 | 158 |
158 str->appendf(" mode: %s", gModeStrings[fShadowMode]); | 159 str->appendf(" mode: %s", gModeStrings[fShadowMode]); |
159 | 160 |
160 str->append(")"); | 161 str->append(")"); |
161 } | 162 } |
162 #endif | 163 #endif |
OLD | NEW |