Commit 637c7485 authored by Khushal's avatar Khushal Committed by Commit Bot

cc: Ensure correct scaling for non-lazy images in GPU cache.

When using a non-lazy (bitmap) image in the GPU cache, we assume the
upload to be scaled at the mip-level required for draw, when we
actually use the original image for the upload. Fix this by considering
non-lazy scaled images as lazy generated. This also ensures we use
lower gpu memory, by caching downscaled uploads.

R=ericrk@chromium.org

Bug: 815045, 814219
Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel;master.tryserver.chromium.android:android_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel
Change-Id: I4b7d3f4edbcf0e5ba5574512f662a3fdf53cabd6
Reviewed-on: https://chromium-review.googlesource.com/935441Reviewed-by: default avatarZhenyao Mo <zmo@chromium.org>
Reviewed-by: default avatarEric Karl <ericrk@chromium.org>
Commit-Queue: Khushal <khushalsagar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#539276}
parent bbf2ee0a
...@@ -1514,10 +1514,17 @@ GpuImageDecodeCache::CreateImageData(const DrawImage& draw_image) { ...@@ -1514,10 +1514,17 @@ GpuImageDecodeCache::CreateImageData(const DrawImage& draw_image) {
} }
size_t data_size = image_info.computeMinByteSize(); size_t data_size = image_info.computeMinByteSize();
return base::WrapRefCounted( // |is_bitmap_backed| specifies whether the image has pixel data which can
new ImageData(mode, data_size, draw_image.target_color_space(), // directly be used for the upload. This will be the case for non-lazy images
CalculateDesiredFilterQuality(draw_image), mip_level, // used at the original scale. In these cases, we don't internally cache any
!draw_image.paint_image().IsLazyGenerated())); // cpu component for the image.
// However, if the image will be scaled, we consider it a lazy image and cache
// the scaled result in discardable memory.
const bool is_bitmap_backed =
!draw_image.paint_image().IsLazyGenerated() && mip_level == 0;
return base::WrapRefCounted(new ImageData(
mode, data_size, draw_image.target_color_space(),
CalculateDesiredFilterQuality(draw_image), mip_level, is_bitmap_backed));
} }
void GpuImageDecodeCache::DeleteImage(ImageData* image_data) { void GpuImageDecodeCache::DeleteImage(ImageData* image_data) {
......
...@@ -2210,7 +2210,7 @@ TEST_P(GpuImageDecodeCacheTest, ...@@ -2210,7 +2210,7 @@ TEST_P(GpuImageDecodeCacheTest,
cache->UnrefImage(draw_image); cache->UnrefImage(draw_image);
} }
TEST_P(GpuImageDecodeCacheTest, NonLazyImageUpload) { TEST_P(GpuImageDecodeCacheTest, NonLazyImageUploadNoScale) {
auto cache = CreateCache(); auto cache = CreateCache();
bool is_decomposable = true; bool is_decomposable = true;
SkFilterQuality quality = kHigh_SkFilterQuality; SkFilterQuality quality = kHigh_SkFilterQuality;
...@@ -2226,6 +2226,33 @@ TEST_P(GpuImageDecodeCacheTest, NonLazyImageUpload) { ...@@ -2226,6 +2226,33 @@ TEST_P(GpuImageDecodeCacheTest, NonLazyImageUpload) {
EXPECT_TRUE(decoded_draw_image.image()); EXPECT_TRUE(decoded_draw_image.image());
EXPECT_TRUE(decoded_draw_image.is_budgeted()); EXPECT_TRUE(decoded_draw_image.is_budgeted());
cache->DrawWithImageFinished(draw_image, decoded_draw_image); cache->DrawWithImageFinished(draw_image, decoded_draw_image);
// For non-lazy images used at the original scale, no cpu component should be
// cached
EXPECT_FALSE(cache->GetSWImageDecodeForTesting(draw_image));
}
TEST_P(GpuImageDecodeCacheTest, NonLazyImageUploadDownscaled) {
auto cache = CreateCache();
bool is_decomposable = true;
SkFilterQuality quality = kHigh_SkFilterQuality;
PaintImage image = CreateBitmapImage(gfx::Size(10, 10));
DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()),
quality,
CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
PaintImage::kDefaultFrameIndex, DefaultColorSpace());
viz::ContextProvider::ScopedContextLock context_lock(context_provider());
DecodedDrawImage decoded_draw_image =
EnsureImageBacked(cache->GetDecodedImageForDraw(draw_image));
EXPECT_TRUE(decoded_draw_image.image());
EXPECT_TRUE(decoded_draw_image.is_budgeted());
cache->DrawWithImageFinished(draw_image, decoded_draw_image);
// For non-lazy images which are downscaled, the scaled image should be
// cached.
auto sw_image = cache->GetSWImageDecodeForTesting(draw_image);
EXPECT_TRUE(sw_image);
EXPECT_EQ(sw_image->width(), 5);
EXPECT_EQ(sw_image->height(), 5);
} }
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(
......
...@@ -122,3 +122,6 @@ class PixelExpectations(GpuTestExpectations): ...@@ -122,3 +122,6 @@ class PixelExpectations(GpuTestExpectations):
bug=809868) bug=809868)
self.Flaky('Pixel_CanvasDisplayLinearRGBUnaccelerated2DGPUCompositing', self.Flaky('Pixel_CanvasDisplayLinearRGBUnaccelerated2DGPUCompositing',
['android'], bug=810006) ['android'], bug=810006)
self.Fail('Pixel_CSSFilterEffects', ['mac'], bug=815045)
self.Fail('Pixel_CSSFilterEffects_NoOverlays', ['mac'], bug=815045)
...@@ -643,12 +643,12 @@ def MacSpecificPages(base_name): ...@@ -643,12 +643,12 @@ def MacSpecificPages(base_name):
'filter_effects.html', 'filter_effects.html',
base_name + '_CSSFilterEffects', base_name + '_CSSFilterEffects',
test_rect=[0, 0, 300, 300], test_rect=[0, 0, 300, 300],
revision=7), revision=8),
PixelTestPage( PixelTestPage(
'filter_effects.html', 'filter_effects.html',
base_name + '_CSSFilterEffects_NoOverlays', base_name + '_CSSFilterEffects_NoOverlays',
test_rect=[0, 0, 300, 300], test_rect=[0, 0, 300, 300],
revision=8, revision=9,
tolerance=10, tolerance=10,
browser_args=no_overlays_args), browser_args=no_overlays_args),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment