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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 | 137 |
138 return LinearResampling; | 138 return LinearResampling; |
139 } | 139 } |
140 | 140 |
141 static ResamplingMode limitResamplingMode(GraphicsContext* context, ResamplingMo de resampling) | 141 static ResamplingMode limitResamplingMode(GraphicsContext* context, ResamplingMo de resampling) |
142 { | 142 { |
143 switch (context->imageInterpolationQuality()) { | 143 switch (context->imageInterpolationQuality()) { |
144 case InterpolationNone: | 144 case InterpolationNone: |
145 return NoResampling; | 145 return NoResampling; |
146 case InterpolationMedium: | 146 case InterpolationMedium: |
147 // For now we treat InterpolationMedium and InterpolationLow the same. | 147 if (resampling == AwesomeResampling) |
148 return MediumResampling; | |
149 break; | |
148 case InterpolationLow: | 150 case InterpolationLow: |
149 if (resampling == AwesomeResampling) | 151 if (resampling == AwesomeResampling || resampling == MediumResampling) |
150 return LinearResampling; | 152 return LinearResampling; |
151 break; | 153 break; |
152 case InterpolationHigh: | 154 case InterpolationHigh: |
153 case InterpolationDefault: | |
Stephen Chennney
2014/03/18 12:56:32
I think you'll get build errors due to enum not in
Alpha Left Google
2014/03/18 22:59:13
Actually this is correct since InterpolationDefaul
| |
154 break; | 155 break; |
155 } | 156 } |
156 | 157 |
157 return resampling; | 158 return resampling; |
158 } | 159 } |
159 | 160 |
160 // This function is used to scale an image and extract a scaled fragment. | 161 // This function is used to scale an image and extract a scaled fragment. |
161 // | 162 // |
162 // ALGORITHM | 163 // ALGORITHM |
163 // | 164 // |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
346 SkScalarToFloat(destRectTarget.width()), SkScalarToFloat(destRectTar get.height())); | 347 SkScalarToFloat(destRectTarget.width()), SkScalarToFloat(destRectTar get.height())); |
347 } | 348 } |
348 | 349 |
349 if (resampling == NoResampling) { | 350 if (resampling == NoResampling) { |
350 // FIXME: This is to not break tests (it results in the filter bitmap fl ag | 351 // FIXME: This is to not break tests (it results in the filter bitmap fl ag |
351 // being set to true). We need to decide if we respect NoResampling | 352 // being set to true). We need to decide if we respect NoResampling |
352 // being returned from computeResamplingMode. | 353 // being returned from computeResamplingMode. |
353 resampling = LinearResampling; | 354 resampling = LinearResampling; |
354 } | 355 } |
355 resampling = limitResamplingMode(context, resampling); | 356 resampling = limitResamplingMode(context, resampling); |
356 paint.setFilterBitmap(resampling == LinearResampling); | |
357 | 357 |
358 bool isLazyDecoded = DeferredImageDecoder::isLazyDecoded(bitmap()); | 358 bool isLazyDecoded = DeferredImageDecoder::isLazyDecoded(bitmap()); |
359 // FIXME: Bicubic filtering in Skia is only applied to defer-decoded images | 359 // FIXME: Bicubic filtering in Skia is only applied to defer-decoded images |
360 // as an experiment. Once this filtering code path becomes stable we should | 360 // as an experiment. Once this filtering code path becomes stable we should |
361 // turn this on for all cases, including non-defer-decoded images. | 361 // turn this on for all cases, including non-defer-decoded images. |
362 bool useBicubicFilter = resampling == AwesomeResampling && isLazyDecoded; | 362 bool useBicubicFilter = resampling == AwesomeResampling && isLazyDecoded; |
363 | 363 |
364 if (useBicubicFilter) | 364 if (useBicubicFilter) |
365 paint.setFilterLevel(SkPaint::kHigh_FilterLevel); | 365 paint.setFilterLevel(SkPaint::kHigh_FilterLevel); |
366 else if (resampling == MediumResampling) | |
Stephen White
2014/03/18 17:26:43
I'd suggest to refactor this out into a helper fun
Alpha Left Google
2014/03/18 22:59:13
Done.
| |
367 paint.setFilterLevel(SkPaint::kMedium_FilterLevel); | |
368 else if (resampling == LinearResampling) | |
369 paint.setFilterLevel(SkPaint::kLow_FilterLevel); | |
370 else | |
371 paint.setFilterLevel(SkPaint::kNone_FilterLevel); | |
366 | 372 |
367 if (resampling == AwesomeResampling && !useBicubicFilter) { | 373 if (resampling == AwesomeResampling && !useBicubicFilter) { |
368 // Resample the image and then draw the result to canvas with bilinear | 374 // Resample the image and then draw the result to canvas with bilinear |
369 // filtering. | 375 // filtering. |
370 drawResampledBitmap(context, paint, srcRect, destRect); | 376 drawResampledBitmap(context, paint, srcRect, destRect); |
371 } else { | 377 } else { |
372 // We want to filter it if we decided to do interpolation above, or if | 378 // We want to filter it if we decided to do interpolation above, or if |
373 // there is something interesting going on with the matrix (like a rotat ion). | 379 // there is something interesting going on with the matrix (like a rotat ion). |
374 // Note: for serialization, we will want to subset the bitmap first so w e | 380 // Note: for serialization, we will want to subset the bitmap first so w e |
375 // don't send extra pixels. | 381 // don't send extra pixels. |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
490 float adjustedX = phase.x() + normSrcRect.x() * scale.width(); | 496 float adjustedX = phase.x() + normSrcRect.x() * scale.width(); |
491 float adjustedY = phase.y() + normSrcRect.y() * scale.height(); | 497 float adjustedY = phase.y() + normSrcRect.y() * scale.height(); |
492 shaderTransform.postTranslate(SkFloatToScalar(adjustedX), SkFloatToScalar(ad justedY)); | 498 shaderTransform.postTranslate(SkFloatToScalar(adjustedX), SkFloatToScalar(ad justedY)); |
493 shader->setLocalMatrix(shaderTransform); | 499 shader->setLocalMatrix(shaderTransform); |
494 | 500 |
495 SkPaint paint; | 501 SkPaint paint; |
496 paint.setShader(shader.get()); | 502 paint.setShader(shader.get()); |
497 paint.setXfermode(WebCoreCompositeToSkiaComposite(compositeOp, blendMode).ge t()); | 503 paint.setXfermode(WebCoreCompositeToSkiaComposite(compositeOp, blendMode).ge t()); |
498 paint.setColorFilter(context->colorFilter()); | 504 paint.setColorFilter(context->colorFilter()); |
499 | 505 |
500 paint.setFilterBitmap(resampling == LinearResampling); | |
501 if (useBicubicFilter) | 506 if (useBicubicFilter) |
502 paint.setFilterLevel(SkPaint::kHigh_FilterLevel); | 507 paint.setFilterLevel(SkPaint::kHigh_FilterLevel); |
508 else if (resampling == MediumResampling) | |
509 paint.setFilterLevel(SkPaint::kMedium_FilterLevel); | |
510 else if (resampling == LinearResampling) | |
511 paint.setFilterLevel(SkPaint::kLow_FilterLevel); | |
512 else | |
513 paint.setFilterLevel(SkPaint::kNone_FilterLevel); | |
503 if (isLazyDecoded) | 514 if (isLazyDecoded) |
504 PlatformInstrumentation::didDrawLazyPixelRef(bitmap().getGenerationID()) ; | 515 PlatformInstrumentation::didDrawLazyPixelRef(bitmap().getGenerationID()) ; |
505 | 516 |
506 context->drawRect(destRect, paint); | 517 context->drawRect(destRect, paint); |
507 } | 518 } |
508 | 519 |
509 bool NativeImageSkia::shouldCacheResampling(const SkISize& scaledImageSize, cons t SkIRect& scaledImageSubset) const | 520 bool NativeImageSkia::shouldCacheResampling(const SkISize& scaledImageSize, cons t SkIRect& scaledImageSubset) const |
510 { | 521 { |
511 // Check whether the requested dimensions match previous request. | 522 // Check whether the requested dimensions match previous request. |
512 bool matchesPreviousRequest = m_cachedImageInfo.isEqual(scaledImageSize, sca ledImageSubset); | 523 bool matchesPreviousRequest = m_cachedImageInfo.isEqual(scaledImageSize, sca ledImageSubset); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
572 SkIRect NativeImageSkia::ImageResourceInfo::rectInSubset(const SkIRect& otherSca ledImageSubset) | 583 SkIRect NativeImageSkia::ImageResourceInfo::rectInSubset(const SkIRect& otherSca ledImageSubset) |
573 { | 584 { |
574 if (!scaledImageSubset.contains(otherScaledImageSubset)) | 585 if (!scaledImageSubset.contains(otherScaledImageSubset)) |
575 return SkIRect::MakeEmpty(); | 586 return SkIRect::MakeEmpty(); |
576 SkIRect subsetRect = otherScaledImageSubset; | 587 SkIRect subsetRect = otherScaledImageSubset; |
577 subsetRect.offset(-scaledImageSubset.x(), -scaledImageSubset.y()); | 588 subsetRect.offset(-scaledImageSubset.x(), -scaledImageSubset.y()); |
578 return subsetRect; | 589 return subsetRect; |
579 } | 590 } |
580 | 591 |
581 } // namespace WebCore | 592 } // namespace WebCore |
OLD | NEW |