Commit d9401164 authored by Khushal's avatar Khushal Committed by Commit Bot

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.

R=cblume@chromium.org

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: default avatarChris Blume <cblume@chromium.org>
Cr-Commit-Position: refs/heads/master@{#736239}
parent dcd5a395
......@@ -559,6 +559,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)
......@@ -593,6 +595,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
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