Commit 7a950ebc authored by Antoine Labour's avatar Antoine Labour Committed by Commit Bot

Fix TileResourceFreedIfLostWhileExported

After switching one-copy to SharedImageInterface,
TileResourceFreedIfLostWhileExported lost its meaning as it's only
counting staging textures instead of resource textures. This restores
the behavior by making sure we ask the SharedImageInterface on the
worker context (where they are created now) instead of the
GLES2Interface on the compositor context.

Bug: 882513
Change-Id: I1257c9e130bfa615d56602b0ce74f2830d5a55f5
Reviewed-on: https://chromium-review.googlesource.com/c/1325087
Commit-Queue: Antoine Labour <piman@chromium.org>
Reviewed-by: default avatarJonathan Backer <backer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606614}
parent a3e34588
......@@ -1630,14 +1630,19 @@ class TileResourceFreedIfLostWhileExported : public LayerTreeHostContextTest {
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void DrawLayersOnThread(LayerTreeHostImpl* impl) override {
auto* context_provider = static_cast<viz::TestContextProvider*>(
impl->layer_tree_frame_sink()->worker_context_provider());
viz::TestSharedImageInterface* sii =
context_provider->SharedImageInterface();
switch (impl->active_tree()->source_frame_number()) {
case 0:
// The PicturLayer has a texture for a tile, that has been exported to
// the display compositor now.
EXPECT_EQ(1u, impl->resource_provider()->num_resources_for_testing());
EXPECT_EQ(1u, impl->resource_pool()->resource_count());
// Shows that the tile texture is allocated with the current context.
num_textures_ = gl_->NumTextures();
// Shows that the tile texture is allocated with the current worker
// context.
num_textures_ = sii->shared_image_count();
EXPECT_GT(num_textures_, 0u);
// Lose the LayerTreeFrameSink connection. The tile resource should
......@@ -1651,8 +1656,8 @@ class TileResourceFreedIfLostWhileExported : public LayerTreeHostContextTest {
EXPECT_EQ(1u, impl->resource_provider()->num_resources_for_testing());
EXPECT_EQ(1u, impl->resource_pool()->resource_count());
// Shows that the replacement tile texture is re-allocated with the
// current context, not just the previous one.
EXPECT_EQ(num_textures_, gl_->NumTextures());
// current worker context, not just the previous one.
EXPECT_EQ(num_textures_, sii->shared_image_count());
EndTest();
}
}
......
......@@ -18,7 +18,6 @@
#include "components/viz/common/gpu/context_cache_controller.h"
#include "components/viz/test/test_gles2_interface.h"
#include "gpu/command_buffer/client/raster_implementation_gles.h"
#include "gpu/command_buffer/client/shared_image_interface.h"
#include "gpu/command_buffer/common/skia_utils.h"
#include "gpu/skia_bindings/grcontext_for_gles2_interface.h"
#include "third_party/skia/include/gpu/GrContext.h"
......@@ -111,41 +110,47 @@ class TestGLES2InterfaceForContextProvider : public TestGLES2Interface {
DISALLOW_COPY_AND_ASSIGN(TestGLES2InterfaceForContextProvider);
};
class TestSharedImageInterface : public gpu::SharedImageInterface {
public:
~TestSharedImageInterface() override = default;
gpu::Mailbox CreateSharedImage(ResourceFormat format,
const gfx::Size& size,
const gfx::ColorSpace& color_space,
uint32_t usage) override {
return gpu::Mailbox::Generate();
}
gpu::Mailbox CreateSharedImage(
gfx::GpuMemoryBuffer* gpu_memory_buffer,
gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
const gfx::ColorSpace& color_space,
uint32_t usage) override {
return gpu::Mailbox::Generate();
}
} // namespace
void UpdateSharedImage(const gpu::SyncToken& sync_token,
const gpu::Mailbox& mailbox) override {}
TestSharedImageInterface::TestSharedImageInterface() = default;
TestSharedImageInterface::~TestSharedImageInterface() = default;
gpu::Mailbox TestSharedImageInterface::CreateSharedImage(
ResourceFormat format,
const gfx::Size& size,
const gfx::ColorSpace& color_space,
uint32_t usage) {
auto mailbox = gpu::Mailbox::Generate();
shared_images_.insert(mailbox);
return mailbox;
}
void DestroySharedImage(const gpu::SyncToken& sync_token,
const gpu::Mailbox& mailbox) override {}
gpu::Mailbox TestSharedImageInterface::CreateSharedImage(
gfx::GpuMemoryBuffer* gpu_memory_buffer,
gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
const gfx::ColorSpace& color_space,
uint32_t usage) {
auto mailbox = gpu::Mailbox::Generate();
shared_images_.insert(mailbox);
return mailbox;
}
gpu::SyncToken GenUnverifiedSyncToken() override {
return gpu::SyncToken(gpu::CommandBufferNamespace::GPU_IO,
gpu::CommandBufferId(), ++release_id_);
}
void TestSharedImageInterface::UpdateSharedImage(
const gpu::SyncToken& sync_token,
const gpu::Mailbox& mailbox) {
DCHECK(shared_images_.find(mailbox) != shared_images_.end());
}
private:
uint64_t release_id_ = 0;
};
void TestSharedImageInterface::DestroySharedImage(
const gpu::SyncToken& sync_token,
const gpu::Mailbox& mailbox) {
shared_images_.erase(mailbox);
}
} // namespace
gpu::SyncToken TestSharedImageInterface::GenUnverifiedSyncToken() {
return gpu::SyncToken(gpu::CommandBufferNamespace::GPU_IO,
gpu::CommandBufferId(), ++release_id_);
}
// static
scoped_refptr<TestContextProvider> TestContextProvider::Create(
......@@ -307,7 +312,7 @@ class GrContext* TestContextProvider::GrContext() {
return gr_context_->get();
}
gpu::SharedImageInterface* TestContextProvider::SharedImageInterface() {
TestSharedImageInterface* TestContextProvider::SharedImageInterface() {
return shared_image_interface_.get();
}
......
......@@ -11,6 +11,7 @@
#include <memory>
#include "base/callback.h"
#include "base/containers/flat_set.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
......@@ -20,6 +21,7 @@
#include "components/viz/common/gpu/raster_context_provider.h"
#include "components/viz/test/test_context_support.h"
#include "gpu/command_buffer/client/gles2_interface_stub.h"
#include "gpu/command_buffer/client/shared_image_interface.h"
#include "gpu/config/gpu_feature_info.h"
#include "third_party/skia/include/core/SkRefCnt.h"
......@@ -30,6 +32,37 @@ class GrContextForGLES2Interface;
namespace viz {
class TestGLES2Interface;
class TestSharedImageInterface : public gpu::SharedImageInterface {
public:
TestSharedImageInterface();
~TestSharedImageInterface() override;
gpu::Mailbox CreateSharedImage(ResourceFormat format,
const gfx::Size& size,
const gfx::ColorSpace& color_space,
uint32_t usage) override;
gpu::Mailbox CreateSharedImage(
gfx::GpuMemoryBuffer* gpu_memory_buffer,
gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
const gfx::ColorSpace& color_space,
uint32_t usage) override;
void UpdateSharedImage(const gpu::SyncToken& sync_token,
const gpu::Mailbox& mailbox) override;
void DestroySharedImage(const gpu::SyncToken& sync_token,
const gpu::Mailbox& mailbox) override;
gpu::SyncToken GenUnverifiedSyncToken() override;
size_t shared_image_count() const { return shared_images_.size(); }
private:
uint64_t release_id_ = 0;
base::flat_set<gpu::Mailbox> shared_images_;
};
class TestContextProvider
: public base::RefCountedThreadSafe<TestContextProvider>,
public ContextProvider,
......@@ -62,7 +95,7 @@ class TestContextProvider
gpu::raster::RasterInterface* RasterInterface() override;
gpu::ContextSupport* ContextSupport() override;
class GrContext* GrContext() override;
gpu::SharedImageInterface* SharedImageInterface() override;
TestSharedImageInterface* SharedImageInterface() override;
ContextCacheController* CacheController() override;
base::Lock* GetLock() override;
void AddObserver(ContextLostObserver* obs) override;
......@@ -97,7 +130,7 @@ class TestContextProvider
std::unique_ptr<gpu::raster::RasterInterface> raster_context_;
std::unique_ptr<skia_bindings::GrContextForGLES2Interface> gr_context_;
std::unique_ptr<ContextCacheController> cache_controller_;
std::unique_ptr<gpu::SharedImageInterface> shared_image_interface_;
std::unique_ptr<TestSharedImageInterface> shared_image_interface_;
const bool support_locking_ ALLOW_UNUSED_TYPE;
bool bound_ = false;
......
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