Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
Fix UiThreadGpu initialization for video accelerator tests
Browse files Browse the repository at this point in the history
The UiThreadGpu shouldn't be initialized multiple times for the same
OzonePlatform. This fixes failing DCHECKs in the decode accelerator
unittests.

BUG=447798

Review URL: https://codereview.chromium.org/936703002

Cr-Commit-Position: refs/heads/master@{#317474}
  • Loading branch information
dnicoara authored and Commit bot committed Feb 21, 2015
1 parent c7d1f48 commit 09b7de5
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 73 deletions.
3 changes: 0 additions & 3 deletions content/common/gpu/media/rendering_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
#include "ui/display/chromeos/display_configurator.h"
#endif // defined(OS_CHROMEOS)
#include "ui/ozone/public/ozone_platform.h"
#include "ui/ozone/public/ui_thread_gpu.h"
#include "ui/platform_window/platform_window.h"
#include "ui/platform_window/platform_window_delegate.h"
#endif // defined(USE_OZONE)
Expand Down Expand Up @@ -98,7 +97,6 @@ class DisplayConfiguratorObserver : public ui::DisplayConfigurator::Observer {
class RenderingHelper::StubOzoneDelegate : public ui::PlatformWindowDelegate {
public:
StubOzoneDelegate() : accelerated_widget_(gfx::kNullAcceleratedWidget) {
ui_thread_gpu_.Initialize();
platform_window_ = ui::OzonePlatform::GetInstance()->CreatePlatformWindow(
this, gfx::Rect());
}
Expand Down Expand Up @@ -132,7 +130,6 @@ class RenderingHelper::StubOzoneDelegate : public ui::PlatformWindowDelegate {
ui::PlatformWindow* platform_window() const { return platform_window_.get(); }

private:
ui::UiThreadGpu ui_thread_gpu_;
scoped_ptr<ui::PlatformWindow> platform_window_;
gfx::AcceleratedWidget accelerated_widget_;

Expand Down
15 changes: 15 additions & 0 deletions content/common/gpu/media/video_decode_accelerator_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "base/synchronization/condition_variable.h"
#include "base/synchronization/lock.h"
#include "base/synchronization/waitable_event.h"
#include "base/thread_task_runner_handle.h"
#include "base/threading/thread.h"
#include "content/common/gpu/media/fake_video_decode_accelerator.h"
#include "content/common/gpu/media/rendering_helper.h"
Expand Down Expand Up @@ -73,6 +74,7 @@
#endif // OS_WIN

#if defined(USE_OZONE)
#include "ui/ozone/public/ozone_gpu_test_helper.h"
#include "ui/ozone/public/ozone_platform.h"
#endif // defined(USE_OZONE)

Expand Down Expand Up @@ -227,6 +229,16 @@ class VideoDecodeAcceleratorTestEnvironment : public ::testing::Environment {
rendering_thread_.task_runner()->PostTask(
FROM_HERE, base::Bind(&RenderingHelper::InitializeOneOff, &done));
done.Wait();

#if defined(USE_OZONE)
// Need to initialize after the rendering side since the rendering side
// initializes the "GPU" parts of Ozone.
//
// This also needs to be done in the test environment since this shouldn't
// be initialized multiple times for the same Ozone platform.
gpu_helper_.Initialize(base::ThreadTaskRunnerHandle::Get(),
GetRenderingTaskRunner());
#endif
}

void TearDown() override { rendering_thread_.Stop(); }
Expand All @@ -237,6 +249,9 @@ class VideoDecodeAcceleratorTestEnvironment : public ::testing::Environment {

private:
base::Thread rendering_thread_;
#if defined(USE_OZONE)
ui::OzoneGpuTestHelper gpu_helper_;
#endif

DISALLOW_COPY_AND_ASSIGN(VideoDecodeAcceleratorTestEnvironment);
};
Expand Down
4 changes: 2 additions & 2 deletions ui/ozone/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ component("ozone") {
"platform_selection.h",
"public/input_controller.cc",
"public/input_controller.h",
"public/ozone_gpu_thread_helper.cc",
"public/ozone_gpu_thread_helper.h",
"public/ozone_platform.cc",
"public/ozone_platform.h",
"public/ozone_switches.cc",
"public/ozone_switches.h",
"public/ui_thread_gpu.cc",
"public/ui_thread_gpu.h",
]

defines = [ "OZONE_IMPLEMENTATION" ]
Expand Down
8 changes: 5 additions & 3 deletions ui/ozone/demo/ozone_demo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
#include "ui/ozone/demo/software_renderer.h"
#include "ui/ozone/demo/surfaceless_gl_renderer.h"
#include "ui/ozone/gpu/gpu_memory_buffer_factory_ozone_native_buffer.h"
#include "ui/ozone/public/ozone_gpu_test_helper.h"
#include "ui/ozone/public/ozone_platform.h"
#include "ui/ozone/public/ozone_switches.h"
#include "ui/ozone/public/ui_thread_gpu.h"
#include "ui/platform_window/platform_window.h"
#include "ui/platform_window/platform_window_delegate.h"

Expand Down Expand Up @@ -59,7 +59,7 @@ class RendererFactory {
RendererType type_;

// Helper for applications that do GL on main thread.
ui::UiThreadGpu ui_thread_gpu_;
ui::OzoneGpuTestHelper gpu_helper_;

// Used by the surfaceless renderers to allocate buffers.
ui::GpuMemoryBufferFactoryOzoneNativeBuffer buffer_factory_;
Expand Down Expand Up @@ -199,7 +199,9 @@ RendererFactory::~RendererFactory() {
bool RendererFactory::Initialize() {
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
if (!command_line->HasSwitch(kDisableGpu) &&
gfx::GLSurface::InitializeOneOff() && ui_thread_gpu_.Initialize()) {
gfx::GLSurface::InitializeOneOff() &&
gpu_helper_.Initialize(base::ThreadTaskRunnerHandle::Get(),
base::ThreadTaskRunnerHandle::Get())) {
if (command_line->HasSwitch(switches::kOzoneUseSurfaceless)) {
type_ = SURFACELESS_GL;
} else {
Expand Down
4 changes: 2 additions & 2 deletions ui/ozone/ozone.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@
'platform_selection.h',
'public/input_controller.cc',
'public/input_controller.h',
'public/ozone_gpu_test_helper.cc',
'public/ozone_gpu_test_helper.h',
'public/ozone_platform.cc',
'public/ozone_platform.h',
'public/ozone_switches.cc',
'public/ozone_switches.h',
'public/ui_thread_gpu.cc',
'public/ui_thread_gpu.h',
'<@(external_ozone_platform_files)',
],
'actions': [
Expand Down
8 changes: 5 additions & 3 deletions ui/ozone/platform/dri/ozone_platform_dri.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "ui/ozone/platform/dri/ozone_platform_dri.h"

#include "base/at_exit.h"
#include "base/thread_task_runner_handle.h"
#include "ui/base/cursor/ozone/bitmap_cursor_factory_ozone.h"
#include "ui/events/ozone/device/device_manager.h"
#include "ui/events/ozone/evdev/cursor_delegate_evdev.h"
Expand All @@ -27,8 +28,8 @@
#include "ui/ozone/platform/dri/native_display_delegate_dri.h"
#include "ui/ozone/platform/dri/native_display_delegate_proxy.h"
#include "ui/ozone/platform/dri/screen_manager.h"
#include "ui/ozone/public/ozone_gpu_test_helper.h"
#include "ui/ozone/public/ozone_platform.h"
#include "ui/ozone/public/ui_thread_gpu.h"

#if defined(USE_XKBCOMMON)
#include "ui/events/ozone/layout/xkb/xkb_evdev_codes.h"
Expand Down Expand Up @@ -121,7 +122,8 @@ class OzonePlatformDri : public OzonePlatform {
cursor_.get(), device_manager_.get(),
KeyboardLayoutEngineManager::GetKeyboardLayoutEngine()));

if (!ui_thread_gpu_.Initialize())
if (!gpu_helper_.Initialize(base::ThreadTaskRunnerHandle::Get(),
base::ThreadTaskRunnerHandle::Get()))
LOG(FATAL) << "Failed to initialize dummy channel.";
}

Expand All @@ -147,7 +149,7 @@ class OzonePlatformDri : public OzonePlatform {

DriWindowDelegateManager window_delegate_manager_;

UiThreadGpu ui_thread_gpu_;
OzoneGpuTestHelper gpu_helper_;

#if defined(USE_XKBCOMMON)
XkbEvdevCodes xkb_evdev_code_converter_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ui/ozone/public/ui_thread_gpu.h"
#include "ui/ozone/public/ozone_gpu_test_helper.h"

#include "base/thread_task_runner_handle.h"
#include "ipc/ipc_listener.h"
Expand All @@ -23,12 +23,12 @@ const int kGpuProcessHostId = 1;

class FakeGpuProcess : public IPC::Sender {
public:
FakeGpuProcess() : weak_factory_(this) {}
FakeGpuProcess(
const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner)
: ui_task_runner_(ui_task_runner), weak_factory_(this) {}
~FakeGpuProcess() override {}

void Init() {
task_runner_ = base::ThreadTaskRunnerHandle::Get();

ui::OzonePlatform::GetInstance()
->GetGpuPlatformSupport()
->OnChannelEstablished(this);
Expand All @@ -42,8 +42,7 @@ class FakeGpuProcess : public IPC::Sender {
}

bool Send(IPC::Message* msg) override {
DCHECK(task_runner_->BelongsToCurrentThread());
base::MessageLoop::current()->PostTask(
ui_task_runner_->PostTask(
FROM_HERE,
base::Bind(&FakeGpuProcess::DispatchToGpuPlatformSupportHostTask,
weak_factory_.GetWeakPtr(), msg));
Expand All @@ -58,59 +57,60 @@ class FakeGpuProcess : public IPC::Sender {
delete msg;
}

scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
base::WeakPtrFactory<FakeGpuProcess> weak_factory_;
};

class FakeGpuProcessHost {
public:
FakeGpuProcessHost() : weak_factory_(this) {}
FakeGpuProcessHost(
const scoped_refptr<base::SingleThreadTaskRunner>& gpu_task_runner)
: gpu_task_runner_(gpu_task_runner), weak_factory_(this) {}
~FakeGpuProcessHost() {}

void Init() {
task_runner_ = base::ThreadTaskRunnerHandle::Get();

base::Callback<void(IPC::Message*)> sender =
base::Bind(&FakeGpuProcessHost::DispatchToGpuPlatformSupportTask,
weak_factory_.GetWeakPtr());

ui::OzonePlatform::GetInstance()
->GetGpuPlatformSupportHost()
->OnChannelEstablished(kGpuProcessHostId, task_runner_, sender);
->OnChannelEstablished(kGpuProcessHostId, gpu_task_runner_, sender);
}

private:
void DispatchToGpuPlatformSupportTask(IPC::Message* msg) {
DCHECK(task_runner_->BelongsToCurrentThread());
ui::OzonePlatform::GetInstance()
->GetGpuPlatformSupport()
->OnMessageReceived(*msg);
delete msg;
}

scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
scoped_refptr<base::SingleThreadTaskRunner> gpu_task_runner_;
base::WeakPtrFactory<FakeGpuProcessHost> weak_factory_;
};

UiThreadGpu::UiThreadGpu() {
OzoneGpuTestHelper::OzoneGpuTestHelper() {
}

UiThreadGpu::~UiThreadGpu() {
OzoneGpuTestHelper::~OzoneGpuTestHelper() {
}

bool UiThreadGpu::Initialize() {
bool OzoneGpuTestHelper::Initialize(
const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner,
const scoped_refptr<base::SingleThreadTaskRunner>& gpu_task_runner) {
io_helper_thread_.reset(new base::Thread("IOHelperThread"));
if (!io_helper_thread_->StartWithOptions(
base::Thread::Options(base::MessageLoop::TYPE_IO, 0)))
return false;

fake_gpu_process_.reset(new FakeGpuProcess);
fake_gpu_process_.reset(new FakeGpuProcess(ui_task_runner));
io_helper_thread_->task_runner()->PostTask(
FROM_HERE, base::Bind(&FakeGpuProcess::InitOnIO,
base::Unretained(fake_gpu_process_.get())));
fake_gpu_process_->Init();

fake_gpu_process_host_.reset(new FakeGpuProcessHost);
fake_gpu_process_host_.reset(new FakeGpuProcessHost(gpu_task_runner));
fake_gpu_process_host_->Init();

return true;
Expand Down
48 changes: 48 additions & 0 deletions ui/ozone/public/ozone_gpu_test_helper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UI_OZONE_PUBLIC_OZONE_GPU_THREAD_HELPER_H_
#define UI_OZONE_PUBLIC_OZONE_GPU_THREAD_HELPER_H_

#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "ui/ozone/ozone_export.h"

namespace base {
class SingleThreadTaskRunner;
class Thread;
}

namespace ui {

class FakeGpuProcess;
class FakeGpuProcessHost;

// Helper class for applications that do not have a dedicated GPU channel.
//
// This sets up message forwarding between the "gpu" and "ui" threads.
class OZONE_EXPORT OzoneGpuTestHelper {
public:
OzoneGpuTestHelper();
virtual ~OzoneGpuTestHelper();

// Start processing gpu messages. The host process will be using the
// |gpu_task_runner| to post messages intended for the GPU thread. The "gpu"
// process will be using the |ui_task_runner| to post messages intended for
// the "ui" thread.
bool Initialize(
const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner,
const scoped_refptr<base::SingleThreadTaskRunner>& gpu_task_runner);

private:
scoped_ptr<FakeGpuProcess> fake_gpu_process_;
scoped_ptr<FakeGpuProcessHost> fake_gpu_process_host_;
scoped_ptr<base::Thread> io_helper_thread_;

DISALLOW_COPY_AND_ASSIGN(OzoneGpuTestHelper);
};

} // namespace ui

#endif // UI_OZONE_PUBLIC_OZONE_GPU_THREAD_HELPER_H_
42 changes: 0 additions & 42 deletions ui/ozone/public/ui_thread_gpu.h

This file was deleted.

0 comments on commit 09b7de5

Please sign in to comment.