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

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

Issue 1823573003: Change signatures of filter bounds methods to return a rect. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Hide legacy API behind #ifdef; switch callers to new API 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
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"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 canvas.drawBitmap(src, offsetVec.fX, offsetVec.fY, &paint); 92 canvas.drawBitmap(src, offsetVec.fX, offsetVec.fY, &paint);
93 if (fShadowMode == kDrawShadowAndForeground_ShadowMode) { 93 if (fShadowMode == kDrawShadowAndForeground_ShadowMode) {
94 canvas.drawBitmap(src, 0, 0); 94 canvas.drawBitmap(src, 0, 0);
95 } 95 }
96 *result = device->accessBitmap(false); 96 *result = device->accessBitmap(false);
97 offset->fX = bounds.fLeft; 97 offset->fX = bounds.fLeft;
98 offset->fY = bounds.fTop; 98 offset->fY = bounds.fTop;
99 return true; 99 return true;
100 } 100 }
101 101
102 void SkDropShadowImageFilter::computeFastBounds(const SkRect& src, SkRect* dst) const { 102 SkRect SkDropShadowImageFilter::computeFastBounds(const SkRect& src) const {
103 if (getInput(0)) { 103 SkRect bounds = this->getInput(0) ? this->getInput(0)->computeFastBounds(src ) : src;
104 getInput(0)->computeFastBounds(src, dst); 104 SkRect shadowBounds = bounds;
105 } else {
106 *dst = src;
107 }
108
109 SkRect shadowBounds = *dst;
110 shadowBounds.offset(fDx, fDy); 105 shadowBounds.offset(fDx, fDy);
111 shadowBounds.outset(SkScalarMul(fSigmaX, SkIntToScalar(3)), 106 shadowBounds.outset(SkScalarMul(fSigmaX, SkIntToScalar(3)),
112 SkScalarMul(fSigmaY, SkIntToScalar(3))); 107 SkScalarMul(fSigmaY, SkIntToScalar(3)));
113 if (fShadowMode == kDrawShadowAndForeground_ShadowMode) { 108 if (fShadowMode == kDrawShadowAndForeground_ShadowMode) {
114 dst->join(shadowBounds); 109 bounds.join(shadowBounds);
115 } else { 110 } else {
116 *dst = shadowBounds; 111 bounds = shadowBounds;
117 } 112 }
113 return bounds;
118 } 114 }
119 115
120 void SkDropShadowImageFilter::onFilterNodeBounds(const SkIRect& src, const SkMat rix& ctm, 116 SkIRect SkDropShadowImageFilter::onFilterNodeBounds(const SkIRect& src, const Sk Matrix& ctm,
121 SkIRect* dst, MapDirection dire ction) const { 117 MapDirection direction) cons t {
122 *dst = src;
123 SkVector offsetVec = SkVector::Make(fDx, fDy); 118 SkVector offsetVec = SkVector::Make(fDx, fDy);
124 if (kReverse_MapDirection == direction) { 119 if (kReverse_MapDirection == direction) {
125 offsetVec.negate(); 120 offsetVec.negate();
126 } 121 }
127 ctm.mapVectors(&offsetVec, 1); 122 ctm.mapVectors(&offsetVec, 1);
128 dst->offset(SkScalarCeilToInt(offsetVec.x()), 123 SkIRect dst = src.makeOffset(SkScalarCeilToInt(offsetVec.x()),
129 SkScalarCeilToInt(offsetVec.y())); 124 SkScalarCeilToInt(offsetVec.y()));
130 SkVector sigma = SkVector::Make(fSigmaX, fSigmaY); 125 SkVector sigma = SkVector::Make(fSigmaX, fSigmaY);
131 ctm.mapVectors(&sigma, 1); 126 ctm.mapVectors(&sigma, 1);
132 dst->outset(SkScalarCeilToInt(SkScalarMul(sigma.x(), SkIntToScalar(3))), 127 dst.outset(SkScalarCeilToInt(SkScalarMul(sigma.x(), SkIntToScalar(3))),
133 SkScalarCeilToInt(SkScalarMul(sigma.y(), SkIntToScalar(3)))); 128 SkScalarCeilToInt(SkScalarMul(sigma.y(), SkIntToScalar(3))));
134 if (fShadowMode == kDrawShadowAndForeground_ShadowMode) { 129 if (fShadowMode == kDrawShadowAndForeground_ShadowMode) {
135 dst->join(src); 130 dst.join(src);
136 } 131 }
132 return dst;
137 } 133 }
138 134
139 #ifndef SK_IGNORE_TO_STRING 135 #ifndef SK_IGNORE_TO_STRING
140 void SkDropShadowImageFilter::toString(SkString* str) const { 136 void SkDropShadowImageFilter::toString(SkString* str) const {
141 str->appendf("SkDropShadowImageFilter: ("); 137 str->appendf("SkDropShadowImageFilter: (");
142 138
143 str->appendf("dX: %f ", fDx); 139 str->appendf("dX: %f ", fDx);
144 str->appendf("dY: %f ", fDy); 140 str->appendf("dY: %f ", fDy);
145 str->appendf("sigmaX: %f ", fSigmaX); 141 str->appendf("sigmaX: %f ", fSigmaX);
146 str->appendf("sigmaY: %f ", fSigmaY); 142 str->appendf("sigmaY: %f ", fSigmaY);
147 143
148 str->append("Color: "); 144 str->append("Color: ");
149 str->appendHex(fColor); 145 str->appendHex(fColor);
150 146
151 static const char* gModeStrings[] = { 147 static const char* gModeStrings[] = {
152 "kDrawShadowAndForeground", "kDrawShadowOnly" 148 "kDrawShadowAndForeground", "kDrawShadowOnly"
153 }; 149 };
154 150
155 static_assert(kShadowModeCount == SK_ARRAY_COUNT(gModeStrings), "enum_mismat ch"); 151 static_assert(kShadowModeCount == SK_ARRAY_COUNT(gModeStrings), "enum_mismat ch");
156 152
157 str->appendf(" mode: %s", gModeStrings[fShadowMode]); 153 str->appendf(" mode: %s", gModeStrings[fShadowMode]);
158 154
159 str->append(")"); 155 str->append(")");
160 } 156 }
161 #endif 157 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698