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 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 SkMatrix localMatrix; | 251 SkMatrix localMatrix; |
252 // We also need to translate it such that the origin of the pattern is the | 252 // We also need to translate it such that the origin of the pattern is the |
253 // origin of the destination rect, which is what WebKit expects. Skia uses | 253 // origin of the destination rect, which is what WebKit expects. Skia uses |
254 // the coordinate system origin as the base for the pattern. If WebKit wants | 254 // the coordinate system origin as the base for the pattern. If WebKit wants |
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 SkPaint::FilterLevel filterLevel = static_cast<SkPaint::FilterLevel>(resampl
ing); |
261 | 262 |
262 // Bicubic filter is only applied to defer-decoded images, see | 263 // Bicubic filter is only applied to defer-decoded images, see |
263 // NativeImageSkia::draw for details. | 264 // NativeImageSkia::draw for details. |
264 bool useBicubicFilter = resampling == InterpolationHigh && isLazyDecoded; | 265 if (resampling == InterpolationHigh && !isLazyDecoded) { |
265 bool isResampled = false; | |
266 if (resampling == InterpolationHigh && !useBicubicFilter) { | |
267 // Do nice resampling. | 266 // Do nice resampling. |
268 isResampled = true; | 267 filterLevel = SkPaint::kNone_FilterLevel; |
269 float scaleX = destBitmapWidth / normSrcRect.width(); | 268 float scaleX = destBitmapWidth / normSrcRect.width(); |
270 float scaleY = destBitmapHeight / normSrcRect.height(); | 269 float scaleY = destBitmapHeight / normSrcRect.height(); |
271 SkRect scaledSrcRect; | 270 SkRect scaledSrcRect; |
272 | 271 |
273 // Since we are resizing the bitmap, we need to remove the scale | 272 // Since we are resizing the bitmap, we need to remove the scale |
274 // applied to the pixels in the bitmap shader. This means we need | 273 // applied to the pixels in the bitmap shader. This means we need |
275 // CTM * localMatrix to have identity scale. Since we | 274 // CTM * localMatrix to have identity scale. Since we |
276 // can't modify CTM (or the rectangle will be drawn in the wrong | 275 // can't modify CTM (or the rectangle will be drawn in the wrong |
277 // place), we must set localMatrix's scale to the inverse of | 276 // place), we must set localMatrix's scale to the inverse of |
278 // CTM scale. | 277 // CTM scale. |
(...skipping 25 matching lines...) Expand all Loading... |
304 shader = adoptRef(SkShader::CreateBitmapShader( | 303 shader = adoptRef(SkShader::CreateBitmapShader( |
305 createBitmapWithSpace(srcSubset, repeatSpacing.width() * ctmScal
eX, repeatSpacing.height() * ctmScaleY), | 304 createBitmapWithSpace(srcSubset, repeatSpacing.width() * ctmScal
eX, repeatSpacing.height() * ctmScaleY), |
306 SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &localMa
trix)); | 305 SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &localMa
trix)); |
307 } | 306 } |
308 } | 307 } |
309 | 308 |
310 SkPaint paint; | 309 SkPaint paint; |
311 paint.setShader(shader.get()); | 310 paint.setShader(shader.get()); |
312 paint.setXfermode(WebCoreCompositeToSkiaComposite(compositeOp, blendMode).ge
t()); | 311 paint.setXfermode(WebCoreCompositeToSkiaComposite(compositeOp, blendMode).ge
t()); |
313 paint.setColorFilter(context->colorFilter()); | 312 paint.setColorFilter(context->colorFilter()); |
314 paint.setFilterLevel(isResampled ? SkPaint::kNone_FilterLevel : static_cast<
SkPaint::FilterLevel>(resampling)); | 313 paint.setFilterLevel(filterLevel); |
315 | 314 |
316 if (isLazyDecoded) | 315 if (isLazyDecoded) |
317 PlatformInstrumentation::didDrawLazyPixelRef(bitmap().getGenerationID())
; | 316 PlatformInstrumentation::didDrawLazyPixelRef(bitmap().getGenerationID())
; |
318 | 317 |
319 context->drawRect(destRect, paint); | 318 context->drawRect(destRect, paint); |
320 } | 319 } |
321 | 320 |
322 bool NativeImageSkia::shouldCacheResampling(const SkISize& scaledImageSize, cons
t SkIRect& scaledImageSubset) const | 321 bool NativeImageSkia::shouldCacheResampling(const SkISize& scaledImageSize, cons
t SkIRect& scaledImageSubset) const |
323 { | 322 { |
324 // Check whether the requested dimensions match previous request. | 323 // Check whether the requested dimensions match previous request. |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 SkIRect NativeImageSkia::ImageResourceInfo::rectInSubset(const SkIRect& otherSca
ledImageSubset) | 384 SkIRect NativeImageSkia::ImageResourceInfo::rectInSubset(const SkIRect& otherSca
ledImageSubset) |
386 { | 385 { |
387 if (!scaledImageSubset.contains(otherScaledImageSubset)) | 386 if (!scaledImageSubset.contains(otherScaledImageSubset)) |
388 return SkIRect::MakeEmpty(); | 387 return SkIRect::MakeEmpty(); |
389 SkIRect subsetRect = otherScaledImageSubset; | 388 SkIRect subsetRect = otherScaledImageSubset; |
390 subsetRect.offset(-scaledImageSubset.x(), -scaledImageSubset.y()); | 389 subsetRect.offset(-scaledImageSubset.x(), -scaledImageSubset.y()); |
391 return subsetRect; | 390 return subsetRect; |
392 } | 391 } |
393 | 392 |
394 } // namespace blink | 393 } // namespace blink |
OLD | NEW |