diff options
author | enne@chromium.org <enne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-07 09:16:34 +0000 |
---|---|---|
committer | enne@chromium.org <enne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-07 09:16:34 +0000 |
commit | 0dd9815a9ae48eef6e8b7d89a1f38916a55f469b (patch) | |
tree | 655f62497248bf16b07f223c5fab2ad4ff3dfb14 /cc/resources/picture_pile_impl_unittest.cc | |
parent | 37b7206a8c304700fb250a4eba8e22dd038a8b04 (diff) | |
download | chromium_src-0dd9815a9ae48eef6e8b7d89a1f38916a55f469b.zip chromium_src-0dd9815a9ae48eef6e8b7d89a1f38916a55f469b.tar.gz chromium_src-0dd9815a9ae48eef6e8b7d89a1f38916a55f469b.tar.bz2 |
cc: Clear impl-side painting canvases more efficiently
This change pipes the contents opaque flag from the layer to the pile
recording. If this flag is true, the layer promises that it will raster
something opaque covering layer bounds. This lets us avoid a clear for all but
the internal edge texels which need to be cleared for filtering during
rasterization and the external edge texels which need to be cleared for
filtering during drawing.
Any non-opaque layer now just gets cleared to transparent, as that seemed to be
about 4x faster on average than drawing a rect even for rects that didn't cover
the entire canvas.
R=vmpstr@chromium.org
BUG=246782
Review URL: https://chromiumcodereview.appspot.com/16580011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@204779 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/resources/picture_pile_impl_unittest.cc')
-rw-r--r-- | cc/resources/picture_pile_impl_unittest.cc | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/cc/resources/picture_pile_impl_unittest.cc b/cc/resources/picture_pile_impl_unittest.cc index d0e78b9..336dc7a 100644 --- a/cc/resources/picture_pile_impl_unittest.cc +++ b/cc/resources/picture_pile_impl_unittest.cc @@ -11,6 +11,7 @@ #include "third_party/skia/include/core/SkPixelRef.h" #include "third_party/skia/include/core/SkShader.h" #include "ui/gfx/rect.h" +#include "ui/gfx/size_conversions.h" namespace cc { namespace { @@ -712,5 +713,86 @@ TEST(PicturePileImplTest, PixelRefIteratorMultiplePictures) { } } +TEST(PicturePileImpl, RasterContentsOpaque) { + gfx::Size tile_size(1000, 1000); + gfx::Size layer_bounds(3, 5); + float contents_scale = 1.5f; + + scoped_refptr<FakePicturePileImpl> pile = + FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); + // Because the caller sets content opaque, it also promises that it + // has at least filled in layer_bounds opaquely. + SkPaint red_paint; + red_paint.setColor(SK_ColorRED); + pile->add_draw_rect_with_paint(gfx::Rect(layer_bounds), red_paint); + + pile->SetMinContentsScale(contents_scale); + pile->set_background_color(SK_ColorRED); + pile->set_contents_opaque(true); + pile->RerecordPile(); + + gfx::Size content_bounds( + gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale))); + + // Simulate a canvas rect larger than the content bounds. Every pixel + // up to one pixel outside the content bounds is guaranteed to be opaque. + // Outside of that is undefined. + gfx::Rect canvas_rect(content_bounds); + canvas_rect.Inset(0, 0, -1, -1); + + SkBitmap bitmap; + bitmap.setConfig(SkBitmap::kARGB_8888_Config, + canvas_rect.width(), + canvas_rect.height()); + bitmap.allocPixels(); + SkCanvas canvas(bitmap); + + PicturePileImpl::RasterStats raster_stats; + pile->RasterToBitmap( + &canvas, canvas_rect, contents_scale, &raster_stats); + + SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); + int num_pixels = bitmap.width() * bitmap.height(); + for (int i = 0; i < num_pixels; ++i) { + EXPECT_EQ(SkColorGetA(pixels[i]), 255u); + } +} + +TEST(PicturePileImpl, RasterContentsTransparent) { + gfx::Size tile_size(1000, 1000); + gfx::Size layer_bounds(5, 3); + float contents_scale = 0.5f; + + scoped_refptr<FakePicturePileImpl> pile = + FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); + pile->set_background_color(SK_ColorTRANSPARENT); + pile->set_contents_opaque(false); + pile->SetMinContentsScale(contents_scale); + pile->RerecordPile(); + + gfx::Size content_bounds( + gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale))); + + gfx::Rect canvas_rect(content_bounds); + canvas_rect.Inset(0, 0, -1, -1); + + SkBitmap bitmap; + bitmap.setConfig(SkBitmap::kARGB_8888_Config, + canvas_rect.width(), + canvas_rect.height()); + bitmap.allocPixels(); + SkCanvas canvas(bitmap); + + PicturePileImpl::RasterStats raster_stats; + pile->RasterToBitmap( + &canvas, canvas_rect, contents_scale, &raster_stats); + + SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); + int num_pixels = bitmap.width() * bitmap.height(); + for (int i = 0; i < num_pixels; ++i) { + EXPECT_EQ(SkColorGetA(pixels[i]), 0u); + } +} + } // namespace } // namespace cc |