Skip to content
Permalink
Browse files

cc: Fix handling of mips for images on the CPU with OOPR.

If an image is greater than max texture size it can not be uploaded to
the GPU and we keep a copy on the CPU instead for rasterization. While
for GPU backed images adding mips requires re-allocating a new mipped
texture, for these images it should be a no-op since its handled by skia
internally. The existing code was erroneously trying to upload them.

TBR=​cblume@chromium.org

(cherry picked from commit d940116)

Bug: 1046414
Change-Id: If88f76578dae99470991f7e4fb136107b94e23a0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2026227
Commit-Queue: Khushal <khushalsagar@chromium.org>
Auto-Submit: Khushal <khushalsagar@chromium.org>
Reviewed-by: Chris Blume <cblume@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#736239}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2031768
Reviewed-by: Khushal <khushalsagar@chromium.org>
Cr-Commit-Position: refs/branch-heads/3987@{#777}
Cr-Branched-From: c4e8da9-refs/heads/master@{#722274}
  • Loading branch information
Khushal Commit Bot
Khushal authored and Commit Bot committed Jan 31, 2020
1 parent e3ca01c commit 2fce75de7aa95ed8c6098ecca8ec7fc42431fbef
@@ -548,6 +548,8 @@ sk_sp<SkImage> ServiceImageTransferCacheEntry::MakeSkImage(
image = MakeTextureImage(context_, std::move(image), target_color_space,
has_mips_ ? GrMipMapped::kYes : GrMipMapped::kNo);
} else {
// If the image is on the CPU, no work is needed to generate mips.
has_mips_ = true;
sk_sp<SkImage> original =
SkImage::MakeFromRaster(pixmap, [](const void*, void*) {}, nullptr);
if (!original)
@@ -582,6 +584,7 @@ void ServiceImageTransferCacheEntry::EnsureMips() {
if (has_mips_)
return;

DCHECK(fits_on_gpu_);
if (is_yuv()) {
DCHECK(image_);
DCHECK(yuv_color_space_.has_value());
@@ -132,6 +132,7 @@ class CC_PAINT_EXPORT ServiceImageTransferCacheEntry

// Ensures the cached image has mips.
void EnsureMips();
bool has_mips() const { return has_mips_; }

// Used in tests and for registering each texture for memory dumps.
const sk_sp<SkImage>& GetPlaneImage(size_t index) const;
@@ -404,5 +404,57 @@ INSTANTIATE_TEST_SUITE_P(All,
YUVDecodeFormat::kYUV2),
TestParamToString);

TEST(ImageTransferCacheEntryTestNoYUV, CPUImageWithMips) {
GrMockOptions options;
auto gr_context = GrContext::MakeMock(&options);

SkBitmap bitmap;
bitmap.allocPixels(
SkImageInfo::MakeN32Premul(gr_context->maxTextureSize() + 1, 10));
ClientImageTransferCacheEntry client_entry(&bitmap.pixmap(), nullptr, true);
std::vector<uint8_t> storage(client_entry.SerializedSize());
client_entry.Serialize(base::make_span(storage.data(), storage.size()));

ServiceImageTransferCacheEntry service_entry;
service_entry.Deserialize(gr_context.get(),
base::make_span(storage.data(), storage.size()));
ASSERT_TRUE(service_entry.image());
auto pre_mip_image = service_entry.image();
EXPECT_FALSE(pre_mip_image->isTextureBacked());
EXPECT_TRUE(service_entry.has_mips());

service_entry.EnsureMips();
ASSERT_TRUE(service_entry.image());
EXPECT_FALSE(service_entry.image()->isTextureBacked());
EXPECT_TRUE(service_entry.has_mips());
EXPECT_EQ(pre_mip_image, service_entry.image());
}

TEST(ImageTransferCacheEntryTestNoYUV, CPUImageAddMipsLater) {
GrMockOptions options;
auto gr_context = GrContext::MakeMock(&options);

SkBitmap bitmap;
bitmap.allocPixels(
SkImageInfo::MakeN32Premul(gr_context->maxTextureSize() + 1, 10));
ClientImageTransferCacheEntry client_entry(&bitmap.pixmap(), nullptr, false);
std::vector<uint8_t> storage(client_entry.SerializedSize());
client_entry.Serialize(base::make_span(storage.data(), storage.size()));

ServiceImageTransferCacheEntry service_entry;
service_entry.Deserialize(gr_context.get(),
base::make_span(storage.data(), storage.size()));
ASSERT_TRUE(service_entry.image());
auto pre_mip_image = service_entry.image();
EXPECT_FALSE(pre_mip_image->isTextureBacked());
EXPECT_TRUE(service_entry.has_mips());

service_entry.EnsureMips();
ASSERT_TRUE(service_entry.image());
EXPECT_FALSE(service_entry.image()->isTextureBacked());
EXPECT_TRUE(service_entry.has_mips());
EXPECT_EQ(pre_mip_image, service_entry.image());
}

} // namespace
} // namespace cc

0 comments on commit 2fce75d

Please sign in to comment.
You can’t perform that action at this time.