Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Side by Side Diff: Source/platform/graphics/skia/NativeImageSkia.cpp

Issue 262263003: Always use AwesomeResampling for lazy decoded images. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: address review feedback Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 ResamplingMode resampling; 378 bool isLazyDecoded = DeferredImageDecoder::isLazyDecoded(bitmap());
379
380 ResamplingMode resampling = AwesomeResampling;
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;
383 } else { 385 } else if (!isLazyDecoded) {
384 // Take into account scale applied to the canvas when computing sampling mode (e.g. CSS scale or page scale). 386 // Take into account scale applied to the canvas when computing sampling mode (e.g. CSS scale or page scale).
385 SkRect destRectTarget = destRect; 387 SkRect destRectTarget = destRect;
386 SkMatrix totalMatrix = context->getTotalMatrix(); 388 SkMatrix totalMatrix = context->getTotalMatrix();
387 if (!(totalMatrix.getType() & (SkMatrix::kAffine_Mask | SkMatrix::kPersp ective_Mask))) 389 if (!(totalMatrix.getType() & (SkMatrix::kAffine_Mask | SkMatrix::kPersp ective_Mask)))
388 totalMatrix.mapRect(&destRectTarget, destRect); 390 totalMatrix.mapRect(&destRectTarget, destRect);
389 391
390 resampling = computeResamplingMode(totalMatrix, 392 resampling = computeResamplingMode(totalMatrix,
391 SkScalarToFloat(srcRect.width()), SkScalarToFloat(srcRect.height()), 393 SkScalarToFloat(srcRect.width()), SkScalarToFloat(srcRect.height()),
392 SkScalarToFloat(destRectTarget.width()), SkScalarToFloat(destRectTar get.height())); 394 SkScalarToFloat(destRectTarget.width()), SkScalarToFloat(destRectTar get.height()));
393 } 395 }
394 396
395 if (resampling == NoResampling) { 397 if (resampling == NoResampling) {
396 // FIXME: This is to not break tests (it results in the filter bitmap fl ag 398 // 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 399 // being set to true). We need to decide if we respect NoResampling
398 // being returned from computeResamplingMode. 400 // being returned from computeResamplingMode.
399 resampling = LinearResampling; 401 resampling = LinearResampling;
400 } 402 }
401 resampling = limitResamplingMode(context, resampling); 403 resampling = limitResamplingMode(context, resampling);
402 404
403 bool isLazyDecoded = DeferredImageDecoder::isLazyDecoded(bitmap());
404 // FIXME: Bicubic filtering in Skia is only applied to defer-decoded images 405 // 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 406 // as an experiment. Once this filtering code path becomes stable we should
406 // turn this on for all cases, including non-defer-decoded images. 407 // turn this on for all cases, including non-defer-decoded images.
407 bool useBicubicFilter = resampling == AwesomeResampling && isLazyDecoded; 408 bool useBicubicFilter = resampling == AwesomeResampling && isLazyDecoded;
408 409
409 paint.setFilterLevel(convertToSkiaFilterLevel(useBicubicFilter, resampling)) ; 410 paint.setFilterLevel(convertToSkiaFilterLevel(useBicubicFilter, resampling)) ;
410 411
411 if (resampling == AwesomeResampling && !useBicubicFilter) { 412 if (resampling == AwesomeResampling && !useBicubicFilter) {
412 // Resample the image and then draw the result to canvas with bilinear 413 // Resample the image and then draw the result to canvas with bilinear
413 // filtering. 414 // filtering.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 463
463 // Figure out what size the bitmap will be in the destination. The 464 // 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 465 // destination rect is the bounds of the pattern, we need to use the
465 // matrix to see how big it will be. 466 // matrix to see how big it will be.
466 SkRect destRectTarget; 467 SkRect destRectTarget;
467 totalMatrix.mapRect(&destRectTarget, normSrcRect); 468 totalMatrix.mapRect(&destRectTarget, normSrcRect);
468 469
469 float destBitmapWidth = SkScalarToFloat(destRectTarget.width()); 470 float destBitmapWidth = SkScalarToFloat(destRectTarget.width());
470 float destBitmapHeight = SkScalarToFloat(destRectTarget.height()); 471 float destBitmapHeight = SkScalarToFloat(destRectTarget.height());
471 472
473 bool isLazyDecoded = DeferredImageDecoder::isLazyDecoded(bitmap());
474
472 // Compute the resampling mode. 475 // Compute the resampling mode.
473 ResamplingMode resampling; 476 ResamplingMode resampling = AwesomeResampling;
Stephen White 2014/05/07 18:16:31 Same here.
reveman 2014/05/07 19:00:46 Done.
474 if (context->isAccelerated() || context->printing()) 477 if (context->isAccelerated() || context->printing())
475 resampling = LinearResampling; 478 resampling = LinearResampling;
476 else 479 else if (!isLazyDecoded)
477 resampling = computeResamplingMode(totalMatrix, normSrcRect.width(), nor mSrcRect.height(), destBitmapWidth, destBitmapHeight); 480 resampling = computeResamplingMode(totalMatrix, normSrcRect.width(), nor mSrcRect.height(), destBitmapWidth, destBitmapHeight);
478 resampling = limitResamplingMode(context, resampling); 481 resampling = limitResamplingMode(context, resampling);
479 482
480 SkMatrix shaderTransform; 483 SkMatrix shaderTransform;
481 RefPtr<SkShader> shader; 484 RefPtr<SkShader> shader;
482 485
483 bool isLazyDecoded = DeferredImageDecoder::isLazyDecoded(bitmap());
484 // Bicubic filter is only applied to defer-decoded images, see 486 // Bicubic filter is only applied to defer-decoded images, see
485 // NativeImageSkia::draw for details. 487 // NativeImageSkia::draw for details.
486 bool useBicubicFilter = resampling == AwesomeResampling && isLazyDecoded; 488 bool useBicubicFilter = resampling == AwesomeResampling && isLazyDecoded;
487 489
488 if (resampling == AwesomeResampling && !useBicubicFilter) { 490 if (resampling == AwesomeResampling && !useBicubicFilter) {
489 // Do nice resampling. 491 // Do nice resampling.
490 float scaleX = destBitmapWidth / normSrcRect.width(); 492 float scaleX = destBitmapWidth / normSrcRect.width();
491 float scaleY = destBitmapHeight / normSrcRect.height(); 493 float scaleY = destBitmapHeight / normSrcRect.height();
492 SkRect scaledSrcRect; 494 SkRect scaledSrcRect;
493 495
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 SkIRect NativeImageSkia::ImageResourceInfo::rectInSubset(const SkIRect& otherSca ledImageSubset) 617 SkIRect NativeImageSkia::ImageResourceInfo::rectInSubset(const SkIRect& otherSca ledImageSubset)
616 { 618 {
617 if (!scaledImageSubset.contains(otherScaledImageSubset)) 619 if (!scaledImageSubset.contains(otherScaledImageSubset))
618 return SkIRect::MakeEmpty(); 620 return SkIRect::MakeEmpty();
619 SkIRect subsetRect = otherScaledImageSubset; 621 SkIRect subsetRect = otherScaledImageSubset;
620 subsetRect.offset(-scaledImageSubset.x(), -scaledImageSubset.y()); 622 subsetRect.offset(-scaledImageSubset.x(), -scaledImageSubset.y());
621 return subsetRect; 623 return subsetRect;
622 } 624 }
623 625
624 } // namespace WebCore 626 } // namespace WebCore
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698