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

cc: Fix TestOptionsProvider image entries caching.

Right now TestOptionsProvider tries to intercept transfer cache usage
for images, which invalidates a lot of the assumptions made by the
calling code. Instead change this to create and store transfer cache
entries similar to production behaviour.

Also remove some asserts from TransferCacheTestHelper. Since this is
used by fuzzers, it should behave more like production code.

R=enne@chromium.org
BUG=839304

Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Ifd0f25dd4ef13872245717b85ef8b9bd5df3c1d0
Reviewed-on: https://chromium-review.googlesource.com/1043526Reviewed-by: default avatarenne <enne@chromium.org>
Commit-Queue: Khushal <khushalsagar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#556131}
parent cc89d6be
......@@ -56,9 +56,6 @@ class CC_PAINT_EXPORT ServiceImageTransferCacheEntry
size_t CachedSize() const final;
bool Deserialize(GrContext* context, base::span<const uint8_t> data) final;
void set_image_for_testing(sk_sp<SkImage> image) {
image_ = std::move(image);
}
const sk_sp<SkImage>& image() { return image_; }
private:
......
......@@ -53,28 +53,37 @@ void TestOptionsProvider::PushFonts() {
ImageProvider::ScopedDecodedDrawImage TestOptionsProvider::GetDecodedDrawImage(
const DrawImage& draw_image) {
uint32_t image_id = draw_image.paint_image().GetSkImage()->uniqueID();
// Lock and reuse the entry if possible.
const EntryKey entry_key(TransferCacheEntryType::kImage, image_id);
if (LockEntryDirect(entry_key)) {
return ScopedDecodedDrawImage(
DecodedDrawImage(image_id, SkSize::MakeEmpty(), SkSize::Make(1u, 1u),
draw_image.filter_quality(), true));
}
decoded_images_.push_back(draw_image);
auto& entry = entry_map_[++transfer_cache_entry_id_];
SkBitmap bitmap;
const auto& paint_image = draw_image.paint_image();
bitmap.allocPixelsFlags(
SkImageInfo::MakeN32Premul(paint_image.width(), paint_image.height()),
SkBitmap::kZeroPixels_AllocFlag);
sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap);
entry.set_image_for_testing(image);
return ScopedDecodedDrawImage(DecodedDrawImage(
transfer_cache_entry_id_, SkSize::MakeEmpty(), SkSize::Make(1u, 1u),
draw_image.filter_quality(), true));
}
ServiceTransferCacheEntry* TestOptionsProvider::GetEntryInternal(
TransferCacheEntryType entry_type,
uint32_t entry_id) {
if (entry_type != TransferCacheEntryType::kImage)
return TransferCacheTestHelper::GetEntryInternal(entry_type, entry_id);
auto it = entry_map_.find(entry_id);
CHECK(it != entry_map_.end());
return &it->second;
// Create a transfer cache entry for this image.
auto color_space = SkColorSpace::MakeSRGB();
ClientImageTransferCacheEntry cache_entry(&bitmap.pixmap(),
color_space.get());
std::vector<uint8_t> data;
data.resize(cache_entry.SerializedSize());
if (!cache_entry.Serialize(base::span<uint8_t>(data.data(), data.size()))) {
return ScopedDecodedDrawImage();
}
CreateEntryDirect(entry_key, base::span<uint8_t>(data.data(), data.size()));
return ScopedDecodedDrawImage(
DecodedDrawImage(image_id, SkSize::MakeEmpty(), SkSize::Make(1u, 1u),
draw_image.filter_quality(), true));
}
} // namespace cc
......@@ -52,10 +52,6 @@ class TestOptionsProvider : public ImageProvider,
ScopedDecodedDrawImage GetDecodedDrawImage(
const DrawImage& draw_image) override;
ServiceTransferCacheEntry* GetEntryInternal(TransferCacheEntryType entry_type,
uint32_t entry_id) override;
uint32_t transfer_cache_entry_id_ = 0u;
base::flat_map<uint32_t, ServiceImageTransferCacheEntry> entry_map_;
testing::StrictMock<MockCanvas> canvas_;
PaintOp::SerializeOptions serialize_options_;
......
......@@ -6,11 +6,18 @@
#include "base/containers/span.h"
#include "base/logging.h"
#include "third_party/skia/include/gpu/gl/GrGLInterface.h"
namespace cc {
TransferCacheTestHelper::TransferCacheTestHelper(GrContext* context)
: context_(context) {}
: context_(context) {
if (!context_) {
sk_sp<const GrGLInterface> gl_interface(GrGLCreateNullInterface());
owned_context_ = GrContext::MakeGL(std::move(gl_interface));
context_ = owned_context_.get();
}
}
TransferCacheTestHelper::~TransferCacheTestHelper() = default;
bool TransferCacheTestHelper::LockEntryDirect(const EntryKey& key) {
......@@ -22,9 +29,12 @@ void TransferCacheTestHelper::CreateEntryDirect(const EntryKey& key,
// Deserialize into a service transfer cache entry.
std::unique_ptr<ServiceTransferCacheEntry> service_entry =
ServiceTransferCacheEntry::Create(key.first);
DCHECK(service_entry);
if (!service_entry)
return;
bool success = service_entry->Deserialize(context_, data);
DCHECK(success);
if (!success)
return;
last_added_entry_ = key;
......
......@@ -11,6 +11,7 @@
#include "base/containers/span.h"
#include "cc/paint/transfer_cache_deserialize_helper.h"
#include "cc/paint/transfer_cache_serialize_helper.h"
#include "third_party/skia/include/gpu/GrContext.h"
class GrContext;
......@@ -53,6 +54,7 @@ class TransferCacheTestHelper : public TransferCacheDeserializeHelper,
EntryKey last_added_entry_ = {TransferCacheEntryType::kRawMemory, ~0};
GrContext* context_ = nullptr;
sk_sp<GrContext> owned_context_;
size_t cached_items_limit_ = std::numeric_limits<size_t>::max();
};
......
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