OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2008, Google Inc. All rights reserved. | 2 * Copyright (c) 2008, Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 // a shifted image, it will shift it from there using the localMatrix. | 255 // a shifted image, it will shift it from there using the localMatrix. |
256 const float adjustedX = phase.x() + normSrcRect.x() * scale.width(); | 256 const float adjustedX = phase.x() + normSrcRect.x() * scale.width(); |
257 const float adjustedY = phase.y() + normSrcRect.y() * scale.height(); | 257 const float adjustedY = phase.y() + normSrcRect.y() * scale.height(); |
258 localMatrix.setTranslate(SkFloatToScalar(adjustedX), SkFloatToScalar(adjuste
dY)); | 258 localMatrix.setTranslate(SkFloatToScalar(adjustedX), SkFloatToScalar(adjuste
dY)); |
259 | 259 |
260 RefPtr<SkShader> shader; | 260 RefPtr<SkShader> shader; |
261 | 261 |
262 // Bicubic filter is only applied to defer-decoded images, see | 262 // Bicubic filter is only applied to defer-decoded images, see |
263 // NativeImageSkia::draw for details. | 263 // NativeImageSkia::draw for details. |
264 bool useBicubicFilter = resampling == InterpolationHigh && isLazyDecoded; | 264 bool useBicubicFilter = resampling == InterpolationHigh && isLazyDecoded; |
265 | 265 bool isResampled = false; |
266 if (resampling == InterpolationHigh && !useBicubicFilter) { | 266 if (resampling == InterpolationHigh && !useBicubicFilter) { |
267 // Do nice resampling. | 267 // Do nice resampling. |
| 268 isResampled = true; |
268 float scaleX = destBitmapWidth / normSrcRect.width(); | 269 float scaleX = destBitmapWidth / normSrcRect.width(); |
269 float scaleY = destBitmapHeight / normSrcRect.height(); | 270 float scaleY = destBitmapHeight / normSrcRect.height(); |
270 SkRect scaledSrcRect; | 271 SkRect scaledSrcRect; |
271 | 272 |
272 // Since we are resizing the bitmap, we need to remove the scale | 273 // Since we are resizing the bitmap, we need to remove the scale |
273 // applied to the pixels in the bitmap shader. This means we need | 274 // applied to the pixels in the bitmap shader. This means we need |
274 // CTM * localMatrix to have identity scale. Since we | 275 // CTM * localMatrix to have identity scale. Since we |
275 // can't modify CTM (or the rectangle will be drawn in the wrong | 276 // can't modify CTM (or the rectangle will be drawn in the wrong |
276 // place), we must set localMatrix's scale to the inverse of | 277 // place), we must set localMatrix's scale to the inverse of |
277 // CTM scale. | 278 // CTM scale. |
(...skipping 25 matching lines...) Expand all Loading... |
303 shader = adoptRef(SkShader::CreateBitmapShader( | 304 shader = adoptRef(SkShader::CreateBitmapShader( |
304 createBitmapWithSpace(srcSubset, repeatSpacing.width() * ctmScal
eX, repeatSpacing.height() * ctmScaleY), | 305 createBitmapWithSpace(srcSubset, repeatSpacing.width() * ctmScal
eX, repeatSpacing.height() * ctmScaleY), |
305 SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &localMa
trix)); | 306 SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &localMa
trix)); |
306 } | 307 } |
307 } | 308 } |
308 | 309 |
309 SkPaint paint; | 310 SkPaint paint; |
310 paint.setShader(shader.get()); | 311 paint.setShader(shader.get()); |
311 paint.setXfermode(WebCoreCompositeToSkiaComposite(compositeOp, blendMode).ge
t()); | 312 paint.setXfermode(WebCoreCompositeToSkiaComposite(compositeOp, blendMode).ge
t()); |
312 paint.setColorFilter(context->colorFilter()); | 313 paint.setColorFilter(context->colorFilter()); |
313 paint.setFilterLevel(convertToSkiaFilterLevel(useBicubicFilter, resampling))
; | 314 paint.setFilterLevel(isResampled ? SkPaint::kNone_FilterLevel : static_cast<
SkPaint::FilterLevel>(resampling)); |
314 | 315 |
315 if (isLazyDecoded) | 316 if (isLazyDecoded) |
316 PlatformInstrumentation::didDrawLazyPixelRef(bitmap().getGenerationID())
; | 317 PlatformInstrumentation::didDrawLazyPixelRef(bitmap().getGenerationID())
; |
317 | 318 |
318 context->drawRect(destRect, paint); | 319 context->drawRect(destRect, paint); |
319 } | 320 } |
320 | 321 |
321 bool NativeImageSkia::shouldCacheResampling(const SkISize& scaledImageSize, cons
t SkIRect& scaledImageSubset) const | 322 bool NativeImageSkia::shouldCacheResampling(const SkISize& scaledImageSize, cons
t SkIRect& scaledImageSubset) const |
322 { | 323 { |
323 // Check whether the requested dimensions match previous request. | 324 // Check whether the requested dimensions match previous request. |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 SkIRect NativeImageSkia::ImageResourceInfo::rectInSubset(const SkIRect& otherSca
ledImageSubset) | 385 SkIRect NativeImageSkia::ImageResourceInfo::rectInSubset(const SkIRect& otherSca
ledImageSubset) |
385 { | 386 { |
386 if (!scaledImageSubset.contains(otherScaledImageSubset)) | 387 if (!scaledImageSubset.contains(otherScaledImageSubset)) |
387 return SkIRect::MakeEmpty(); | 388 return SkIRect::MakeEmpty(); |
388 SkIRect subsetRect = otherScaledImageSubset; | 389 SkIRect subsetRect = otherScaledImageSubset; |
389 subsetRect.offset(-scaledImageSubset.x(), -scaledImageSubset.y()); | 390 subsetRect.offset(-scaledImageSubset.x(), -scaledImageSubset.y()); |
390 return subsetRect; | 391 return subsetRect; |
391 } | 392 } |
392 | 393 |
393 } // namespace blink | 394 } // namespace blink |
OLD | NEW |