| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 The Android Open Source Project | 2 * Copyright 2012 The Android Open Source Project |
| 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 "SkBitmap.h" | 8 #include "SkBitmap.h" |
| 9 #include "SkMagnifierImageFilter.h" | 9 #include "SkMagnifierImageFilter.h" |
| 10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 this->fYInvInset == s.fYInvInset); | 225 this->fYInvInset == s.fYInvInset); |
| 226 } | 226 } |
| 227 | 227 |
| 228 void GrMagnifierEffect::getConstantColorComponents(GrColor* color, uint32_t* val
idFlags) const { | 228 void GrMagnifierEffect::getConstantColorComponents(GrColor* color, uint32_t* val
idFlags) const { |
| 229 this->updateConstantColorComponentsForModulation(color, validFlags); | 229 this->updateConstantColorComponentsForModulation(color, validFlags); |
| 230 } | 230 } |
| 231 | 231 |
| 232 #endif | 232 #endif |
| 233 | 233 |
| 234 //////////////////////////////////////////////////////////////////////////////// | 234 //////////////////////////////////////////////////////////////////////////////// |
| 235 |
| 236 SkImageFilter* SkMagnifierImageFilter::Create(const SkRect& srcRect, SkScalar in
set, |
| 237 SkImageFilter* input) { |
| 238 |
| 239 if (!SkScalarIsFinite(inset) || !SkIsValidRect(srcRect)) { |
| 240 return NULL; |
| 241 } |
| 242 // Negative numbers in src rect are not supported |
| 243 if (srcRect.fLeft < 0 || srcRect.fTop < 0) { |
| 244 return NULL; |
| 245 } |
| 246 return SkNEW_ARGS(SkMagnifierImageFilter, (srcRect, inset, input)); |
| 247 } |
| 248 |
| 249 |
| 250 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING |
| 235 SkMagnifierImageFilter::SkMagnifierImageFilter(SkReadBuffer& buffer) | 251 SkMagnifierImageFilter::SkMagnifierImageFilter(SkReadBuffer& buffer) |
| 236 : INHERITED(1, buffer) { | 252 : INHERITED(1, buffer) { |
| 237 float x = buffer.readScalar(); | 253 float x = buffer.readScalar(); |
| 238 float y = buffer.readScalar(); | 254 float y = buffer.readScalar(); |
| 239 float width = buffer.readScalar(); | 255 float width = buffer.readScalar(); |
| 240 float height = buffer.readScalar(); | 256 float height = buffer.readScalar(); |
| 241 fSrcRect = SkRect::MakeXYWH(x, y, width, height); | 257 fSrcRect = SkRect::MakeXYWH(x, y, width, height); |
| 242 fInset = buffer.readScalar(); | 258 fInset = buffer.readScalar(); |
| 243 | 259 |
| 244 buffer.validate(SkScalarIsFinite(fInset) && SkIsValidRect(fSrcRect) && | 260 buffer.validate(SkScalarIsFinite(fInset) && SkIsValidRect(fSrcRect) && |
| 245 // Negative numbers in src rect are not supported | 261 // Negative numbers in src rect are not supported |
| 246 (fSrcRect.fLeft >= 0) && (fSrcRect.fTop >= 0)); | 262 (fSrcRect.fLeft >= 0) && (fSrcRect.fTop >= 0)); |
| 247 } | 263 } |
| 264 #endif |
| 248 | 265 |
| 249 SkMagnifierImageFilter::SkMagnifierImageFilter(const SkRect& srcRect, SkScalar i
nset, | 266 SkMagnifierImageFilter::SkMagnifierImageFilter(const SkRect& srcRect, SkScalar i
nset, |
| 250 SkImageFilter* input) | 267 SkImageFilter* input) |
| 251 : INHERITED(1, &input), fSrcRect(srcRect), fInset(inset) { | 268 : INHERITED(1, &input), fSrcRect(srcRect), fInset(inset) { |
| 252 SkASSERT(srcRect.x() >= 0 && srcRect.y() >= 0 && inset >= 0); | 269 SkASSERT(srcRect.x() >= 0 && srcRect.y() >= 0 && inset >= 0); |
| 253 } | 270 } |
| 254 | 271 |
| 255 #if SK_SUPPORT_GPU | 272 #if SK_SUPPORT_GPU |
| 256 bool SkMagnifierImageFilter::asNewEffect(GrEffect** effect, GrTexture* texture,
const SkMatrix&, | 273 bool SkMagnifierImageFilter::asNewEffect(GrEffect** effect, GrTexture* texture,
const SkMatrix&, |
| 257 const SkIRect&) const { | 274 const SkIRect&) const { |
| 258 if (effect) { | 275 if (effect) { |
| 259 SkScalar yOffset = (texture->origin() == kTopLeft_GrSurfaceOrigin) ? fSr
cRect.y() : | 276 SkScalar yOffset = (texture->origin() == kTopLeft_GrSurfaceOrigin) ? fSr
cRect.y() : |
| 260 (texture->height() - (fSrcRect.y() + fSrcRect.height(
))); | 277 (texture->height() - (fSrcRect.y() + fSrcRect.height(
))); |
| 261 SkScalar invInset = fInset > 0 ? SkScalarInvert(fInset) : SK_Scalar1; | 278 SkScalar invInset = fInset > 0 ? SkScalarInvert(fInset) : SK_Scalar1; |
| 262 *effect = GrMagnifierEffect::Create(texture, | 279 *effect = GrMagnifierEffect::Create(texture, |
| 263 fSrcRect.x() / texture->width(), | 280 fSrcRect.x() / texture->width(), |
| 264 yOffset / texture->height(), | 281 yOffset / texture->height(), |
| 265 fSrcRect.width() / texture->width(), | 282 fSrcRect.width() / texture->width(), |
| 266 fSrcRect.height() / texture->height(
), | 283 fSrcRect.height() / texture->height(
), |
| 267 texture->width() * invInset, | 284 texture->width() * invInset, |
| 268 texture->height() * invInset); | 285 texture->height() * invInset); |
| 269 } | 286 } |
| 270 return true; | 287 return true; |
| 271 } | 288 } |
| 272 #endif | 289 #endif |
| 273 | 290 |
| 291 SkFlattenable* SkMagnifierImageFilter::CreateProc(SkReadBuffer& buffer) { |
| 292 SK_IMAGEFILTER_UNFLATTEN_COMMON(1); |
| 293 SkRect src; |
| 294 buffer.readRect(&src); |
| 295 return Create(src, buffer.readScalar(), common.inputAt(0)); |
| 296 } |
| 297 |
| 274 void SkMagnifierImageFilter::flatten(SkWriteBuffer& buffer) const { | 298 void SkMagnifierImageFilter::flatten(SkWriteBuffer& buffer) const { |
| 275 this->INHERITED::flatten(buffer); | 299 this->INHERITED::flatten(buffer); |
| 276 buffer.writeScalar(fSrcRect.x()); | 300 buffer.writeRect(fSrcRect); |
| 277 buffer.writeScalar(fSrcRect.y()); | |
| 278 buffer.writeScalar(fSrcRect.width()); | |
| 279 buffer.writeScalar(fSrcRect.height()); | |
| 280 buffer.writeScalar(fInset); | 301 buffer.writeScalar(fInset); |
| 281 } | 302 } |
| 282 | 303 |
| 283 bool SkMagnifierImageFilter::onFilterImage(Proxy*, const SkBitmap& src, | 304 bool SkMagnifierImageFilter::onFilterImage(Proxy*, const SkBitmap& src, |
| 284 const Context&, SkBitmap* dst, | 305 const Context&, SkBitmap* dst, |
| 285 SkIPoint* offset) const { | 306 SkIPoint* offset) const { |
| 286 SkASSERT(src.colorType() == kN32_SkColorType); | 307 SkASSERT(src.colorType() == kN32_SkColorType); |
| 287 SkASSERT(fSrcRect.width() < src.width()); | 308 SkASSERT(fSrcRect.width() < src.width()); |
| 288 SkASSERT(fSrcRect.height() < src.height()); | 309 SkASSERT(fSrcRect.height() < src.height()); |
| 289 | 310 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 | 363 |
| 343 int x_val = SkPin32(SkScalarFloorToInt(x_interp), 0, width - 1); | 364 int x_val = SkPin32(SkScalarFloorToInt(x_interp), 0, width - 1); |
| 344 int y_val = SkPin32(SkScalarFloorToInt(y_interp), 0, height - 1); | 365 int y_val = SkPin32(SkScalarFloorToInt(y_interp), 0, height - 1); |
| 345 | 366 |
| 346 *dptr = sptr[y_val * width + x_val]; | 367 *dptr = sptr[y_val * width + x_val]; |
| 347 dptr++; | 368 dptr++; |
| 348 } | 369 } |
| 349 } | 370 } |
| 350 return true; | 371 return true; |
| 351 } | 372 } |
| OLD | NEW |