Chromium Code Reviews| 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 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 368 void NativeImageSkia::draw(GraphicsContext* context, const SkRect& srcRect, cons t SkRect& destRect, PassRefPtr<SkXfermode> compOp) const | 368 void NativeImageSkia::draw(GraphicsContext* context, const SkRect& srcRect, cons t SkRect& destRect, PassRefPtr<SkXfermode> compOp) const |
| 369 { | 369 { |
| 370 TRACE_EVENT0("skia", "NativeImageSkia::draw"); | 370 TRACE_EVENT0("skia", "NativeImageSkia::draw"); |
| 371 SkPaint paint; | 371 SkPaint paint; |
| 372 paint.setXfermode(compOp.get()); | 372 paint.setXfermode(compOp.get()); |
| 373 paint.setColorFilter(context->colorFilter()); | 373 paint.setColorFilter(context->colorFilter()); |
| 374 paint.setAlpha(context->getNormalizedAlpha()); | 374 paint.setAlpha(context->getNormalizedAlpha()); |
| 375 paint.setLooper(context->drawLooper()); | 375 paint.setLooper(context->drawLooper()); |
| 376 paint.setAntiAlias(shouldDrawAntiAliased(context, destRect)); | 376 paint.setAntiAlias(shouldDrawAntiAliased(context, destRect)); |
| 377 | 377 |
| 378 bool isLazyDecoded = DeferredImageDecoder::isLazyDecoded(bitmap()); | |
| 379 | |
| 378 ResamplingMode resampling; | 380 ResamplingMode resampling; |
|
Alpha Left Google
2014/05/06 19:05:28
I suggest this be changed to default to AwsomeResa
reveman
2014/05/07 14:32:05
Done.
| |
| 379 if (context->isAccelerated()) { | 381 if (context->isAccelerated()) { |
| 380 resampling = LinearResampling; | 382 resampling = LinearResampling; |
| 381 } else if (context->printing()) { | 383 } else if (context->printing()) { |
| 382 resampling = NoResampling; | 384 resampling = NoResampling; |
| 385 } else if (isLazyDecoded) { | |
| 386 resampling = AwesomeResampling; | |
|
Alpha Left Google
2014/05/06 19:05:28
Reading this code again. I think this code is corr
reveman
2014/05/07 14:32:05
Done.
Stephen White
2014/05/07 18:16:31
Sorry, but I disagree. I much prefer the way David
reveman
2014/05/07 19:00:46
Done.
| |
| 383 } else { | 387 } else { |
| 384 // Take into account scale applied to the canvas when computing sampling mode (e.g. CSS scale or page scale). | 388 // Take into account scale applied to the canvas when computing sampling mode (e.g. CSS scale or page scale). |
| 385 SkRect destRectTarget = destRect; | 389 SkRect destRectTarget = destRect; |
| 386 SkMatrix totalMatrix = context->getTotalMatrix(); | 390 SkMatrix totalMatrix = context->getTotalMatrix(); |
| 387 if (!(totalMatrix.getType() & (SkMatrix::kAffine_Mask | SkMatrix::kPersp ective_Mask))) | 391 if (!(totalMatrix.getType() & (SkMatrix::kAffine_Mask | SkMatrix::kPersp ective_Mask))) |
| 388 totalMatrix.mapRect(&destRectTarget, destRect); | 392 totalMatrix.mapRect(&destRectTarget, destRect); |
| 389 | 393 |
| 390 resampling = computeResamplingMode(totalMatrix, | 394 resampling = computeResamplingMode(totalMatrix, |
| 391 SkScalarToFloat(srcRect.width()), SkScalarToFloat(srcRect.height()), | 395 SkScalarToFloat(srcRect.width()), SkScalarToFloat(srcRect.height()), |
| 392 SkScalarToFloat(destRectTarget.width()), SkScalarToFloat(destRectTar get.height())); | 396 SkScalarToFloat(destRectTarget.width()), SkScalarToFloat(destRectTar get.height())); |
| 393 } | 397 } |
| 394 | 398 |
| 395 if (resampling == NoResampling) { | 399 if (resampling == NoResampling) { |
| 396 // FIXME: This is to not break tests (it results in the filter bitmap fl ag | 400 // FIXME: This is to not break tests (it results in the filter bitmap fl ag |
| 397 // being set to true). We need to decide if we respect NoResampling | 401 // being set to true). We need to decide if we respect NoResampling |
| 398 // being returned from computeResamplingMode. | 402 // being returned from computeResamplingMode. |
| 399 resampling = LinearResampling; | 403 resampling = LinearResampling; |
| 400 } | 404 } |
| 401 resampling = limitResamplingMode(context, resampling); | 405 resampling = limitResamplingMode(context, resampling); |
| 402 | 406 |
| 403 bool isLazyDecoded = DeferredImageDecoder::isLazyDecoded(bitmap()); | |
| 404 // FIXME: Bicubic filtering in Skia is only applied to defer-decoded images | 407 // FIXME: Bicubic filtering in Skia is only applied to defer-decoded images |
| 405 // as an experiment. Once this filtering code path becomes stable we should | 408 // as an experiment. Once this filtering code path becomes stable we should |
| 406 // turn this on for all cases, including non-defer-decoded images. | 409 // turn this on for all cases, including non-defer-decoded images. |
| 407 bool useBicubicFilter = resampling == AwesomeResampling && isLazyDecoded; | 410 bool useBicubicFilter = resampling == AwesomeResampling && isLazyDecoded; |
|
Alpha Left Google
2014/05/06 19:05:28
Because now you want to use skia for all resamplin
Alpha Left Google
2014/05/06 23:07:51
Whooops! This particular comment is wrong. Please
| |
| 408 | 411 |
| 409 paint.setFilterLevel(convertToSkiaFilterLevel(useBicubicFilter, resampling)) ; | 412 paint.setFilterLevel(convertToSkiaFilterLevel(useBicubicFilter, resampling)) ; |
| 410 | 413 |
| 411 if (resampling == AwesomeResampling && !useBicubicFilter) { | 414 if (resampling == AwesomeResampling && !useBicubicFilter) { |
|
Alpha Left Google
2014/05/06 19:05:28
Use !isLasyDecoded instead.
Alpha Left Google
2014/05/06 23:07:51
Whooops! This particular comment is wrong too. Ple
| |
| 412 // Resample the image and then draw the result to canvas with bilinear | 415 // Resample the image and then draw the result to canvas with bilinear |
| 413 // filtering. | 416 // filtering. |
| 414 drawResampledBitmap(context, paint, srcRect, destRect); | 417 drawResampledBitmap(context, paint, srcRect, destRect); |
| 415 } else { | 418 } else { |
| 416 // We want to filter it if we decided to do interpolation above, or if | 419 // We want to filter it if we decided to do interpolation above, or if |
| 417 // there is something interesting going on with the matrix (like a rotat ion). | 420 // there is something interesting going on with the matrix (like a rotat ion). |
| 418 // Note: for serialization, we will want to subset the bitmap first so w e | 421 // Note: for serialization, we will want to subset the bitmap first so w e |
| 419 // don't send extra pixels. | 422 // don't send extra pixels. |
| 420 context->drawBitmapRect(bitmap(), &srcRect, destRect, &paint); | 423 context->drawBitmapRect(bitmap(), &srcRect, destRect, &paint); |
| 421 } | 424 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 462 | 465 |
| 463 // Figure out what size the bitmap will be in the destination. The | 466 // Figure out what size the bitmap will be in the destination. The |
| 464 // destination rect is the bounds of the pattern, we need to use the | 467 // destination rect is the bounds of the pattern, we need to use the |
| 465 // matrix to see how big it will be. | 468 // matrix to see how big it will be. |
| 466 SkRect destRectTarget; | 469 SkRect destRectTarget; |
| 467 totalMatrix.mapRect(&destRectTarget, normSrcRect); | 470 totalMatrix.mapRect(&destRectTarget, normSrcRect); |
| 468 | 471 |
| 469 float destBitmapWidth = SkScalarToFloat(destRectTarget.width()); | 472 float destBitmapWidth = SkScalarToFloat(destRectTarget.width()); |
| 470 float destBitmapHeight = SkScalarToFloat(destRectTarget.height()); | 473 float destBitmapHeight = SkScalarToFloat(destRectTarget.height()); |
| 471 | 474 |
| 475 bool isLazyDecoded = DeferredImageDecoder::isLazyDecoded(bitmap()); | |
| 476 | |
| 472 // Compute the resampling mode. | 477 // Compute the resampling mode. |
| 473 ResamplingMode resampling; | 478 ResamplingMode resampling; |
|
Alpha Left Google
2014/05/06 19:05:28
Same here. Default to AwsomeResampling please.
reveman
2014/05/07 14:32:05
Done.
| |
| 474 if (context->isAccelerated() || context->printing()) | 479 if (context->isAccelerated() || context->printing()) |
| 475 resampling = LinearResampling; | 480 resampling = LinearResampling; |
| 481 else if (isLazyDecoded) | |
| 482 resampling = AwesomeResampling; | |
| 476 else | 483 else |
|
Alpha Left Google
2014/05/06 19:05:28
I suggest this be else if (!isLazyDecoded).
reveman
2014/05/07 14:32:05
Done.
| |
| 477 resampling = computeResamplingMode(totalMatrix, normSrcRect.width(), nor mSrcRect.height(), destBitmapWidth, destBitmapHeight); | 484 resampling = computeResamplingMode(totalMatrix, normSrcRect.width(), nor mSrcRect.height(), destBitmapWidth, destBitmapHeight); |
| 478 resampling = limitResamplingMode(context, resampling); | 485 resampling = limitResamplingMode(context, resampling); |
| 479 | 486 |
| 480 SkMatrix shaderTransform; | 487 SkMatrix shaderTransform; |
| 481 RefPtr<SkShader> shader; | 488 RefPtr<SkShader> shader; |
| 482 | 489 |
| 483 bool isLazyDecoded = DeferredImageDecoder::isLazyDecoded(bitmap()); | |
| 484 // Bicubic filter is only applied to defer-decoded images, see | 490 // Bicubic filter is only applied to defer-decoded images, see |
| 485 // NativeImageSkia::draw for details. | 491 // NativeImageSkia::draw for details. |
| 486 bool useBicubicFilter = resampling == AwesomeResampling && isLazyDecoded; | 492 bool useBicubicFilter = resampling == AwesomeResampling && isLazyDecoded; |
| 487 | 493 |
| 488 if (resampling == AwesomeResampling && !useBicubicFilter) { | 494 if (resampling == AwesomeResampling && !useBicubicFilter) { |
| 489 // Do nice resampling. | 495 // Do nice resampling. |
| 490 float scaleX = destBitmapWidth / normSrcRect.width(); | 496 float scaleX = destBitmapWidth / normSrcRect.width(); |
| 491 float scaleY = destBitmapHeight / normSrcRect.height(); | 497 float scaleY = destBitmapHeight / normSrcRect.height(); |
| 492 SkRect scaledSrcRect; | 498 SkRect scaledSrcRect; |
| 493 | 499 |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 615 SkIRect NativeImageSkia::ImageResourceInfo::rectInSubset(const SkIRect& otherSca ledImageSubset) | 621 SkIRect NativeImageSkia::ImageResourceInfo::rectInSubset(const SkIRect& otherSca ledImageSubset) |
| 616 { | 622 { |
| 617 if (!scaledImageSubset.contains(otherScaledImageSubset)) | 623 if (!scaledImageSubset.contains(otherScaledImageSubset)) |
| 618 return SkIRect::MakeEmpty(); | 624 return SkIRect::MakeEmpty(); |
| 619 SkIRect subsetRect = otherScaledImageSubset; | 625 SkIRect subsetRect = otherScaledImageSubset; |
| 620 subsetRect.offset(-scaledImageSubset.x(), -scaledImageSubset.y()); | 626 subsetRect.offset(-scaledImageSubset.x(), -scaledImageSubset.y()); |
| 621 return subsetRect; | 627 return subsetRect; |
| 622 } | 628 } |
| 623 | 629 |
| 624 } // namespace WebCore | 630 } // namespace WebCore |
| OLD | NEW |