Commit 1c496f10 authored by Andres Calderon Jaramillo's avatar Andres Calderon Jaramillo Committed by Commit Bot

Test transfer cache entry creation for accelerated image decodes.

This CL modifies the ImageDecodeAcceleratorStub unit tests to test that
service-side transfer cache entries are created correctly for completed
image decodes.

Additionally, a "return true;" is added to
GpuChannelMessageFilter::OnMessageReceived() to make sure that image
decode accelerator requests early out.

Test: all the ImageDecodeAcceleratorStub unit tests pass.
Bug: 868400
Change-Id: I95db80df9ef1f7651807177ffcc3d653b96e1374
Reviewed-on: https://chromium-review.googlesource.com/c/1368600Reviewed-by: default avatarAntoine Labour <piman@chromium.org>
Reviewed-by: default avatarSunny Sachanandani <sunnyps@chromium.org>
Commit-Queue: Andres Calderon Jaramillo <andrescj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#628180}
parent 37100e85
...@@ -272,6 +272,7 @@ target(link_target_type, "gles2_sources") { ...@@ -272,6 +272,7 @@ target(link_target_type, "gles2_sources") {
include_dirs = [ "//third_party/mesa_headers" ] include_dirs = [ "//third_party/mesa_headers" ]
public_deps = [ public_deps = [
"//cc/paint",
"//gpu/command_buffer/common", "//gpu/command_buffer/common",
"//gpu/command_buffer/common:gles2_sources", "//gpu/command_buffer/common:gles2_sources",
"//gpu/command_buffer/common:raster_sources", "//gpu/command_buffer/common:raster_sources",
...@@ -283,7 +284,6 @@ target(link_target_type, "gles2_sources") { ...@@ -283,7 +284,6 @@ target(link_target_type, "gles2_sources") {
":service", ":service",
"//base", "//base",
"//base/third_party/dynamic_annotations", "//base/third_party/dynamic_annotations",
"//cc/paint",
"//components/viz/common:resource_format_utils", "//components/viz/common:resource_format_utils",
"//gpu/command_buffer/client", "//gpu/command_buffer/client",
"//gpu/command_buffer/common:gles2_utils", "//gpu/command_buffer/common:gles2_utils",
......
include_rules = [ include_rules = [
"+cc/paint",
"+components/viz/common/features.h", "+components/viz/common/features.h",
"+components/viz/common/resources/resource_format.h", "+components/viz/common/resources/resource_format.h",
"+third_party/skia", "+third_party/skia",
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/memory/shared_memory.h" #include "base/memory/shared_memory.h"
#include "base/no_destructor.h"
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "base/trace_event/trace_event.h" #include "base/trace_event/trace_event.h"
...@@ -782,13 +783,23 @@ void CommandBufferStub::RemoveDestructionObserver( ...@@ -782,13 +783,23 @@ void CommandBufferStub::RemoveDestructionObserver(
} }
std::unique_ptr<MemoryTracker> CommandBufferStub::CreateMemoryTracker( std::unique_ptr<MemoryTracker> CommandBufferStub::CreateMemoryTracker(
const GPUCreateCommandBufferConfig init_params) const { const GPUCreateCommandBufferConfig& init_params) const {
MemoryTrackerFactory current_factory = GetMemoryTrackerFactory();
if (current_factory)
return current_factory.Run(init_params);
return std::make_unique<GpuCommandBufferMemoryTracker>( return std::make_unique<GpuCommandBufferMemoryTracker>(
channel_->client_id(), channel_->client_tracing_id(), channel_->client_id(), channel_->client_tracing_id(),
command_buffer_id_.GetUnsafeValue(), init_params.attribs.context_type, command_buffer_id_.GetUnsafeValue(), init_params.attribs.context_type,
channel_->task_runner()); channel_->task_runner());
} }
// static
void CommandBufferStub::SetMemoryTrackerFactoryForTesting(
MemoryTrackerFactory factory) {
SetOrGetMemoryTrackerFactory(factory);
}
MemoryTracker* CommandBufferStub::GetMemoryTracker() const { MemoryTracker* CommandBufferStub::GetMemoryTracker() const {
return context_group_->memory_tracker(); return context_group_->memory_tracker();
} }
...@@ -820,4 +831,20 @@ void CommandBufferStub::MarkContextLost() { ...@@ -820,4 +831,20 @@ void CommandBufferStub::MarkContextLost() {
command_buffer_->SetParseError(error::kLostContext); command_buffer_->SetParseError(error::kLostContext);
} }
// static
CommandBufferStub::MemoryTrackerFactory
CommandBufferStub::GetMemoryTrackerFactory() {
return SetOrGetMemoryTrackerFactory(base::NullCallback());
}
// static
CommandBufferStub::MemoryTrackerFactory
CommandBufferStub::SetOrGetMemoryTrackerFactory(MemoryTrackerFactory factory) {
static base::NoDestructor<MemoryTrackerFactory> current_factory{
base::NullCallback()};
if (factory)
*current_factory = factory;
return *current_factory;
}
} // namespace gpu } // namespace gpu
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "base/callback.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/observer_list.h" #include "base/observer_list.h"
...@@ -44,6 +45,7 @@ struct GpuCommandBufferMsg_CreateImage_Params; ...@@ -44,6 +45,7 @@ struct GpuCommandBufferMsg_CreateImage_Params;
namespace gpu { namespace gpu {
class DecoderContext; class DecoderContext;
struct Mailbox; struct Mailbox;
class MemoryTracker;
struct SyncToken; struct SyncToken;
struct WaitForCommandState; struct WaitForCommandState;
class GpuChannel; class GpuChannel;
...@@ -102,6 +104,14 @@ class GPU_IPC_SERVICE_EXPORT CommandBufferStub ...@@ -102,6 +104,14 @@ class GPU_IPC_SERVICE_EXPORT CommandBufferStub
void OnRescheduleAfterFinished() override; void OnRescheduleAfterFinished() override;
void ScheduleGrContextCleanup() override; void ScheduleGrContextCleanup() override;
using MemoryTrackerFactory =
base::RepeatingCallback<std::unique_ptr<MemoryTracker>(
const GPUCreateCommandBufferConfig&)>;
// Overrides the way CreateMemoryTracker() uses to create a MemoryTracker.
// This is intended for mocking the MemoryTracker in tests.
static void SetMemoryTrackerFactoryForTesting(MemoryTrackerFactory factory);
MemoryTracker* GetMemoryTracker() const; MemoryTracker* GetMemoryTracker() const;
// Whether this command buffer can currently handle IPC messages. // Whether this command buffer can currently handle IPC messages.
...@@ -138,7 +148,7 @@ class GPU_IPC_SERVICE_EXPORT CommandBufferStub ...@@ -138,7 +148,7 @@ class GPU_IPC_SERVICE_EXPORT CommandBufferStub
GpuChannel* channel); GpuChannel* channel);
std::unique_ptr<MemoryTracker> CreateMemoryTracker( std::unique_ptr<MemoryTracker> CreateMemoryTracker(
const GPUCreateCommandBufferConfig init_params) const; const GPUCreateCommandBufferConfig& init_params) const;
// Must be called during Initialize(). Takes ownership to co-ordinate // Must be called during Initialize(). Takes ownership to co-ordinate
// teardown in Destroy(). // teardown in Destroy().
...@@ -233,6 +243,16 @@ class GPU_IPC_SERVICE_EXPORT CommandBufferStub ...@@ -233,6 +243,16 @@ class GPU_IPC_SERVICE_EXPORT CommandBufferStub
static void SetContextGpuFeatureInfo(gl::GLContext* context, static void SetContextGpuFeatureInfo(gl::GLContext* context,
const GpuFeatureInfo& gpu_feature_info); const GpuFeatureInfo& gpu_feature_info);
static MemoryTrackerFactory GetMemoryTrackerFactory();
// Overrides the way CreateMemoryTracker() uses to create a MemoryTracker. If
// |factory| is base::NullCallback(), it returns the current
// MemoryTrackerFactory (initially base::NullCallback() which
// CreateMemoryTracker() should interpret as a signal to use the default).
// This is intended for mocking the MemoryTracker in tests.
static MemoryTrackerFactory SetOrGetMemoryTrackerFactory(
MemoryTrackerFactory factory);
std::unique_ptr<DecoderContext> decoder_context_; std::unique_ptr<DecoderContext> decoder_context_;
uint32_t last_flush_id_; uint32_t last_flush_id_;
......
...@@ -267,6 +267,7 @@ bool GpuChannelMessageFilter::OnMessageReceived(const IPC::Message& message) { ...@@ -267,6 +267,7 @@ bool GpuChannelMessageFilter::OnMessageReceived(const IPC::Message& message) {
static_cast<int32_t>(GpuChannelReservedRoutes::kImageDecodeAccelerator)) { static_cast<int32_t>(GpuChannelReservedRoutes::kImageDecodeAccelerator)) {
if (!image_decode_accelerator_stub_->OnMessageReceived(message)) if (!image_decode_accelerator_stub_->OnMessageReceived(message))
return MessageErrorHandler(message, "Invalid image decode request"); return MessageErrorHandler(message, "Invalid image decode request");
return true;
} }
bool handle_out_of_order = bool handle_out_of_order =
......
...@@ -15,7 +15,8 @@ namespace gpu { ...@@ -15,7 +15,8 @@ namespace gpu {
class GpuChannelManagerTest : public GpuChannelTestCommon { class GpuChannelManagerTest : public GpuChannelTestCommon {
public: public:
GpuChannelManagerTest() : GpuChannelTestCommon() {} GpuChannelManagerTest()
: GpuChannelTestCommon(true /* use_stub_bindings */) {}
~GpuChannelManagerTest() override = default; ~GpuChannelManagerTest() override = default;
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
......
...@@ -46,18 +46,22 @@ class TestGpuChannelManagerDelegate : public GpuChannelManagerDelegate { ...@@ -46,18 +46,22 @@ class TestGpuChannelManagerDelegate : public GpuChannelManagerDelegate {
DISALLOW_COPY_AND_ASSIGN(TestGpuChannelManagerDelegate); DISALLOW_COPY_AND_ASSIGN(TestGpuChannelManagerDelegate);
}; };
GpuChannelTestCommon::GpuChannelTestCommon() GpuChannelTestCommon::GpuChannelTestCommon(bool use_stub_bindings)
: GpuChannelTestCommon(std::vector<int32_t>()) {} : GpuChannelTestCommon(std::vector<int32_t>(), use_stub_bindings) {}
GpuChannelTestCommon::GpuChannelTestCommon( GpuChannelTestCommon::GpuChannelTestCommon(
std::vector<int32_t> enabled_workarounds) std::vector<int32_t> enabled_workarounds,
bool use_stub_bindings)
: task_runner_(new base::TestSimpleTaskRunner), : task_runner_(new base::TestSimpleTaskRunner),
io_task_runner_(new base::TestSimpleTaskRunner), io_task_runner_(new base::TestSimpleTaskRunner),
sync_point_manager_(new SyncPointManager()), sync_point_manager_(new SyncPointManager()),
scheduler_(new Scheduler(task_runner_, sync_point_manager_.get())), scheduler_(new Scheduler(task_runner_, sync_point_manager_.get())),
channel_manager_delegate_(new TestGpuChannelManagerDelegate()) { channel_manager_delegate_(new TestGpuChannelManagerDelegate()) {
// We need GL bindings to actually initialize command buffers. // We need GL bindings to actually initialize command buffers.
gl::GLSurfaceTestSupport::InitializeOneOffWithStubBindings(); if (use_stub_bindings)
gl::GLSurfaceTestSupport::InitializeOneOffWithStubBindings();
else
gl::GLSurfaceTestSupport::InitializeOneOff();
GpuFeatureInfo feature_info; GpuFeatureInfo feature_info;
feature_info.enabled_gpu_driver_bug_workarounds = feature_info.enabled_gpu_driver_bug_workarounds =
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define GPU_IPC_SERVICE_GPU_CHANNEL_TEST_COMMON_H_ #define GPU_IPC_SERVICE_GPU_CHANNEL_TEST_COMMON_H_
#include <memory> #include <memory>
#include <vector>
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/memory/unsafe_shared_memory_region.h" #include "base/memory/unsafe_shared_memory_region.h"
...@@ -29,9 +30,10 @@ class TestGpuChannelManagerDelegate; ...@@ -29,9 +30,10 @@ class TestGpuChannelManagerDelegate;
class GpuChannelTestCommon : public testing::Test { class GpuChannelTestCommon : public testing::Test {
public: public:
GpuChannelTestCommon(); explicit GpuChannelTestCommon(bool use_stub_bindings);
// Constructor which allows a custom set of GPU driver bug workarounds. // Constructor which allows a custom set of GPU driver bug workarounds.
explicit GpuChannelTestCommon(std::vector<int32_t> enabled_workarounds); GpuChannelTestCommon(std::vector<int32_t> enabled_workarounds,
bool use_stub_bindings);
~GpuChannelTestCommon() override; ~GpuChannelTestCommon() override;
protected: protected:
......
...@@ -12,7 +12,11 @@ ...@@ -12,7 +12,11 @@
namespace gpu { namespace gpu {
class GpuChannelTest : public GpuChannelTestCommon {}; class GpuChannelTest : public GpuChannelTestCommon {
public:
GpuChannelTest() : GpuChannelTestCommon(true /* use_stub_bindings */) {}
~GpuChannelTest() override = default;
};
#if defined(OS_WIN) #if defined(OS_WIN)
const SurfaceHandle kFakeSurfaceHandle = reinterpret_cast<SurfaceHandle>(1); const SurfaceHandle kFakeSurfaceHandle = reinterpret_cast<SurfaceHandle>(1);
...@@ -234,7 +238,8 @@ TEST_F(GpuChannelTest, CreateFailsIfSharedContextIsLost) { ...@@ -234,7 +238,8 @@ TEST_F(GpuChannelTest, CreateFailsIfSharedContextIsLost) {
class GpuChannelExitForContextLostTest : public GpuChannelTestCommon { class GpuChannelExitForContextLostTest : public GpuChannelTestCommon {
public: public:
GpuChannelExitForContextLostTest() GpuChannelExitForContextLostTest()
: GpuChannelTestCommon({EXIT_ON_CONTEXT_LOST}) {} : GpuChannelTestCommon({EXIT_ON_CONTEXT_LOST} /* enabled_workarounds */,
true /* use_stub_bindings */) {}
}; };
TEST_F(GpuChannelExitForContextLostTest, CreateFailsDuringLostContextShutdown) { TEST_F(GpuChannelExitForContextLostTest, CreateFailsDuringLostContextShutdown) {
......
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