Commit 9f14d907 authored by sadrul's avatar sadrul Committed by Commit bot

mus: Use ui::ContextProviderCommandBuffer.

Remove ui::ContextProvider and ui::GLES2Context, since they are incomplete.
Instead use ui::ContextProviderCommandBuffer, which is used by chrome browser
and renderers.

BUG=643746
TBR=jam@ for content/renderer for code update for API change

Review-Url: https://codereview.chromium.org/2586323002
Cr-Commit-Position: refs/heads/master@{#439718}
parent f951dced
......@@ -11,7 +11,6 @@
#include "content/renderer/mus/compositor_mus_connection.h"
#include "content/renderer/render_thread_impl.h"
#include "content/renderer/render_view_impl.h"
#include "services/ui/public/cpp/context_provider.h"
#include "services/ui/public/cpp/window_compositor_frame_sink.h"
#include "services/ui/public/interfaces/window_tree.mojom.h"
......@@ -40,16 +39,15 @@ void RenderWidgetMusConnection::Bind(
std::unique_ptr<cc::CompositorFrameSink>
RenderWidgetMusConnection::CreateCompositorFrameSink(
scoped_refptr<gpu::GpuChannelHost> gpu_channel_host,
scoped_refptr<cc::ContextProvider> context_provider,
gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager) {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(!window_compositor_frame_sink_binding_);
std::unique_ptr<cc::CompositorFrameSink> compositor_frame_sink(
ui::WindowCompositorFrameSink::Create(
make_scoped_refptr(
new ui::ContextProvider(std::move(gpu_channel_host))),
gpu_memory_buffer_manager, &window_compositor_frame_sink_binding_));
std::move(context_provider), gpu_memory_buffer_manager,
&window_compositor_frame_sink_binding_));
if (compositor_mus_connection_) {
compositor_mus_connection_->AttachCompositorFrameSinkOnMainThread(
std::move(window_compositor_frame_sink_binding_));
......
......@@ -8,12 +8,12 @@
#include "base/macros.h"
#include "base/threading/thread_checker.h"
#include "cc/output/compositor_frame_sink.h"
#include "cc/output/context_provider.h"
#include "content/common/content_export.h"
#include "content/renderer/input/render_widget_input_handler_delegate.h"
#include "content/renderer/mus/compositor_mus_connection.h"
namespace gpu {
class GpuChannelHost;
class GpuMemoryBufferManager;
}
......@@ -28,7 +28,7 @@ class CONTENT_EXPORT RenderWidgetMusConnection
// Create a cc output surface.
std::unique_ptr<cc::CompositorFrameSink> CreateCompositorFrameSink(
scoped_refptr<gpu::GpuChannelHost> gpu_channel_host,
scoped_refptr<cc::ContextProvider> context_provider,
gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager);
static RenderWidgetMusConnection* Get(int routing_id);
......
......@@ -1931,10 +1931,9 @@ RenderThreadImpl::CreateCompositorFrameSink(
command_line.HasSwitch(switches::kUseMusInRenderer)) {
RenderWidgetMusConnection* connection =
RenderWidgetMusConnection::GetOrCreate(routing_id);
scoped_refptr<gpu::GpuChannelHost> gpu_channel_host =
EstablishGpuChannelSync();
return connection->CreateCompositorFrameSink(std::move(gpu_channel_host),
GetGpuMemoryBufferManager());
return connection->CreateCompositorFrameSink(
gpu_->CreateContextProvider(EstablishGpuChannelSync()),
GetGpuMemoryBufferManager());
}
#endif
......
......@@ -8,7 +8,6 @@ import("//build/config/ui.gni")
# implementation (and private haders) are in 'internal'.
source_set("cpp") {
sources = [
"context_provider.h",
"input_event_handler.h",
"property_type_converters.h",
"raster_thread_helper.h",
......@@ -31,11 +30,7 @@ source_set("cpp") {
"//cc",
"//cc/surfaces",
"//cc/surfaces:surface_id",
"//gpu/command_buffer/client",
"//gpu/command_buffer/client:gles2_implementation",
"//gpu/command_buffer/common",
"//mojo/public/cpp/bindings",
"//mojo/public/cpp/system",
"//services/service_manager/public/interfaces",
"//services/ui/common:mus_common",
"//services/ui/public/cpp/gpu",
......@@ -93,9 +88,6 @@ source_set("internal") {
]
sources = [
"context_provider.cc",
"gles2_context.cc",
"gles2_context.h",
"in_flight_change.cc",
"in_flight_change.h",
"property_type_converters.cc",
......@@ -117,14 +109,7 @@ source_set("internal") {
"//cc",
"//cc/surfaces",
"//cc/surfaces:surface_id",
"//gpu/command_buffer/client",
"//gpu/command_buffer/client:gles2_cmd_helper",
"//gpu/command_buffer/client:gles2_implementation",
"//gpu/command_buffer/client:gles2_interface",
"//gpu/command_buffer/common",
"//gpu/ipc/client",
"//mojo/public/cpp/bindings",
"//mojo/public/cpp/system",
"//services/service_manager/public/cpp",
"//services/service_manager/public/interfaces",
"//services/ui/common:mus_common",
......
// 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.
#include "services/ui/public/cpp/context_provider.h"
#include <stdint.h>
#include "base/logging.h"
#include "cc/output/context_cache_controller.h"
#include "gpu/ipc/client/gpu_channel_host.h"
#include "services/ui/public/cpp/gles2_context.h"
namespace ui {
ContextProvider::ContextProvider(
scoped_refptr<gpu::GpuChannelHost> gpu_channel_host)
: gpu_channel_host_(std::move(gpu_channel_host)) {}
bool ContextProvider::BindToCurrentThread() {
context_ = GLES2Context::CreateOffscreenContext(
gpu_channel_host_, base::ThreadTaskRunnerHandle::Get());
if (context_) {
cache_controller_.reset(new cc::ContextCacheController(
context_->context_support(), base::ThreadTaskRunnerHandle::Get()));
}
return !!context_;
}
gpu::gles2::GLES2Interface* ContextProvider::ContextGL() {
return context_->interface();
}
gpu::ContextSupport* ContextProvider::ContextSupport() {
if (!context_)
return NULL;
return context_->context_support();
}
class GrContext* ContextProvider::GrContext() {
return NULL;
}
cc::ContextCacheController* ContextProvider::CacheController() {
return cache_controller_.get();
}
void ContextProvider::InvalidateGrContext(uint32_t state) {}
gpu::Capabilities ContextProvider::ContextCapabilities() {
return gpu::Capabilities();
}
base::Lock* ContextProvider::GetLock() {
// This context provider is not used on multiple threads.
NOTREACHED();
return nullptr;
}
ContextProvider::~ContextProvider() {
}
} // namespace ui
// 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 SERVICES_UI_PUBLIC_CPP_CONTEXT_PROVIDER_H_
#define SERVICES_UI_PUBLIC_CPP_CONTEXT_PROVIDER_H_
#include <stdint.h>
#include <memory>
#include "base/macros.h"
#include "cc/output/context_provider.h"
#include "mojo/public/cpp/system/core.h"
namespace gpu {
class GpuChannelHost;
}
namespace ui {
class GLES2Context;
class ContextProvider : public cc::ContextProvider {
public:
explicit ContextProvider(scoped_refptr<gpu::GpuChannelHost> gpu_channel_host);
// cc::ContextProvider implementation.
bool BindToCurrentThread() override;
gpu::gles2::GLES2Interface* ContextGL() override;
gpu::ContextSupport* ContextSupport() override;
class GrContext* GrContext() override;
cc::ContextCacheController* CacheController() override;
void InvalidateGrContext(uint32_t state) override;
base::Lock* GetLock() override;
gpu::Capabilities ContextCapabilities() override;
void SetLostContextCallback(
const LostContextCallback& lost_context_callback) override {}
protected:
friend class base::RefCountedThreadSafe<ContextProvider>;
~ContextProvider() override;
private:
std::unique_ptr<GLES2Context> context_;
std::unique_ptr<cc::ContextCacheController> cache_controller_;
scoped_refptr<gpu::GpuChannelHost> gpu_channel_host_;
DISALLOW_COPY_AND_ASSIGN(ContextProvider);
};
} // namespace ui
#endif // SERVICES_UI_PUBLIC_CPP_CONTEXT_PROVIDER_H_
// 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.
#include "services/ui/public/cpp/gles2_context.h"
#include <stddef.h>
#include <stdint.h>
#include <utility>
#include "gpu/command_buffer/client/gles2_cmd_helper.h"
#include "gpu/command_buffer/client/shared_memory_limits.h"
#include "gpu/command_buffer/client/transfer_buffer.h"
#include "gpu/ipc/client/command_buffer_proxy_impl.h"
#include "gpu/ipc/client/gpu_channel_host.h"
#include "mojo/public/cpp/system/core.h"
#include "url/gurl.h"
namespace ui {
GLES2Context::GLES2Context() {}
GLES2Context::~GLES2Context() {}
bool GLES2Context::Initialize(
scoped_refptr<gpu::GpuChannelHost> gpu_channel_host,
scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
DCHECK(gpu_channel_host);
gpu::SurfaceHandle surface_handle = gfx::kNullAcceleratedWidget;
// TODO(penghuang): support shared group.
gpu::CommandBufferProxyImpl* shared_command_buffer = nullptr;
gpu::GpuStreamId stream_id = gpu::GpuStreamId::GPU_STREAM_DEFAULT;
gpu::GpuStreamPriority stream_priority = gpu::GpuStreamPriority::NORMAL;
gpu::gles2::ContextCreationAttribHelper attributes;
// TODO(penghuang): figure a useful active_url.
GURL active_url;
command_buffer_proxy_impl_ = gpu::CommandBufferProxyImpl::Create(
std::move(gpu_channel_host), surface_handle, shared_command_buffer,
stream_id, stream_priority, attributes, active_url,
std::move(task_runner));
if (!command_buffer_proxy_impl_)
return false;
gpu::CommandBuffer* command_buffer = command_buffer_proxy_impl_.get();
gpu::GpuControl* gpu_control = command_buffer_proxy_impl_.get();
constexpr gpu::SharedMemoryLimits default_limits;
gles2_helper_.reset(new gpu::gles2::GLES2CmdHelper(command_buffer));
if (!gles2_helper_->Initialize(default_limits.command_buffer_size))
return false;
gles2_helper_->SetAutomaticFlushes(false);
transfer_buffer_.reset(new gpu::TransferBuffer(gles2_helper_.get()));
gpu::Capabilities capabilities = gpu_control->GetCapabilities();
bool bind_generates_resource =
!!capabilities.bind_generates_resource_chromium;
// TODO(piman): Some contexts (such as compositor) want this to be true, so
// this needs to be a public parameter.
bool lose_context_when_out_of_memory = false;
bool support_client_side_arrays = false;
implementation_.reset(new gpu::gles2::GLES2Implementation(
gles2_helper_.get(), NULL, transfer_buffer_.get(),
bind_generates_resource, lose_context_when_out_of_memory,
support_client_side_arrays, gpu_control));
if (!implementation_->Initialize(default_limits.start_transfer_buffer_size,
default_limits.min_transfer_buffer_size,
default_limits.max_transfer_buffer_size,
default_limits.mapped_memory_reclaim_limit))
return false;
return true;
}
// static
std::unique_ptr<GLES2Context> GLES2Context::CreateOffscreenContext(
scoped_refptr<gpu::GpuChannelHost> gpu_channel_host,
scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
if (!gpu_channel_host)
return nullptr;
// Return the GLES2Context only if it is successfully initialized. If
// initialization fails, then return null.
std::unique_ptr<GLES2Context> gles2_context(new GLES2Context);
if (!gles2_context->Initialize(std::move(gpu_channel_host),
std::move(task_runner)))
gles2_context.reset();
return gles2_context;
}
} // namespace ui
// 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 SERVICES_UI_PUBLIC_CPP_GLES2_CONTEXT_H_
#define SERVICES_UI_PUBLIC_CPP_GLES2_CONTEXT_H_
#include <stdint.h>
#include <memory>
#include <vector>
#include "base/macros.h"
#include "base/single_thread_task_runner.h"
#include "gpu/command_buffer/client/gles2_implementation.h"
namespace gpu {
class CommandBufferProxyImpl;
class GpuChannelHost;
class TransferBuffer;
namespace gles2 {
class GLES2CmdHelper;
}
} // namespace gpu
namespace ui {
class GLES2Context {
public:
~GLES2Context();
gpu::gles2::GLES2Interface* interface() const {
return implementation_.get();
}
gpu::ContextSupport* context_support() const { return implementation_.get(); }
static std::unique_ptr<GLES2Context> CreateOffscreenContext(
scoped_refptr<gpu::GpuChannelHost> gpu_channel_host,
scoped_refptr<base::SingleThreadTaskRunner> task_runner);
private:
GLES2Context();
bool Initialize(scoped_refptr<gpu::GpuChannelHost> gpu_channel_host,
scoped_refptr<base::SingleThreadTaskRunner> task_runner);
std::unique_ptr<gpu::CommandBufferProxyImpl> command_buffer_proxy_impl_;
std::unique_ptr<gpu::gles2::GLES2CmdHelper> gles2_helper_;
std::unique_ptr<gpu::TransferBuffer> transfer_buffer_;
std::unique_ptr<gpu::gles2::GLES2Implementation> implementation_;
DISALLOW_COPY_AND_ASSIGN(GLES2Context);
};
} // namespace ui
#endif // SERVICES_UI_PUBLIC_CPP_GLES2_CONTEXT_H_
......@@ -120,9 +120,15 @@ void RecordContextLost(ContextType type,
case BLIMP_RENDER_COMPOSITOR_CONTEXT:
UMA_HISTOGRAM_ENUMERATION("GPU.ContextLost.BlimpRenderCompositor", reason,
CONTEXT_LOST_REASON_MAX_ENUM);
break;
case BLIMP_RENDER_WORKER_CONTEXT:
UMA_HISTOGRAM_ENUMERATION("GPU.ContextLost.BlimpRenderWorker", reason,
CONTEXT_LOST_REASON_MAX_ENUM);
break;
case MUS_CLIENT_CONTEXT:
UMA_HISTOGRAM_ENUMERATION("GPU.ContextLost.MusClient", reason,
CONTEXT_LOST_REASON_MAX_ENUM);
break;
case CONTEXT_TYPE_UNKNOWN:
UMA_HISTOGRAM_ENUMERATION("GPU.ContextLost.Unknown", reason,
CONTEXT_LOST_REASON_MAX_ENUM);
......@@ -160,6 +166,8 @@ std::string ContextTypeToString(ContextType type) {
return "BlimpRenderCompositor";
case BLIMP_RENDER_WORKER_CONTEXT:
return "BlimpRenderWorker";
case MUS_CLIENT_CONTEXT:
return "MusClientContext";
default:
NOTREACHED();
return "unknown";
......
......@@ -26,6 +26,7 @@ enum ContextType {
MEDIA_CONTEXT,
BLIMP_RENDER_COMPOSITOR_CONTEXT,
BLIMP_RENDER_WORKER_CONTEXT,
MUS_CLIENT_CONTEXT,
OFFSCREEN_CONTEXT_FOR_TESTING = CONTEXT_TYPE_UNKNOWN,
};
......
......@@ -10,6 +10,7 @@
#include "mojo/public/cpp/system/platform_handle.h"
#include "services/service_manager/public/cpp/connector.h"
#include "services/ui/public/cpp/gpu/client_gpu_memory_buffer_manager.h"
#include "services/ui/public/cpp/gpu/context_provider_command_buffer.h"
#include "services/ui/public/interfaces/constants.mojom.h"
#include "services/ui/public/interfaces/gpu.mojom.h"
......@@ -64,6 +65,27 @@ std::unique_ptr<Gpu> Gpu::Create(
return base::WrapUnique(new Gpu(nullptr, provider, std::move(task_runner)));
}
scoped_refptr<cc::ContextProvider> Gpu::CreateContextProvider(
scoped_refptr<gpu::GpuChannelHost> gpu_channel) {
constexpr bool automatic_flushes = false;
constexpr bool support_locking = false;
gpu::gles2::ContextCreationAttribHelper attributes;
attributes.alpha_size = -1;
attributes.depth_size = 0;
attributes.stencil_size = 0;
attributes.samples = 0;
attributes.sample_buffers = 0;
attributes.bind_generates_resource = false;
attributes.lose_context_when_out_of_memory = true;
constexpr ui::ContextProviderCommandBuffer* shared_context_provider = nullptr;
return make_scoped_refptr(new ui::ContextProviderCommandBuffer(
std::move(gpu_channel), gpu::GPU_STREAM_DEFAULT,
gpu::GpuStreamPriority::NORMAL, gpu::kNullSurfaceHandle,
GURL("chrome://gpu/MusContextFactory"), automatic_flushes,
support_locking, gpu::SharedMemoryLimits(), attributes,
shared_context_provider, ui::command_buffer_metrics::MUS_CLIENT_CONTEXT));
}
void Gpu::EstablishGpuChannel(
const gpu::GpuChannelEstablishedCallback& callback) {
DCHECK(IsMainThread());
......
......@@ -13,6 +13,7 @@
#include "base/single_thread_task_runner.h"
#include "base/synchronization/waitable_event.h"
#include "base/threading/thread.h"
#include "cc/output/context_provider.h"
#include "gpu/ipc/client/gpu_channel_host.h"
#include "services/ui/public/cpp/gpu/client_gpu_memory_buffer_manager.h"
#include "services/ui/public/interfaces/gpu.mojom.h"
......@@ -43,6 +44,9 @@ class Gpu : public gpu::GpuChannelHostFactory,
service_manager::InterfaceProvider*,
scoped_refptr<base::SingleThreadTaskRunner> task_runner = nullptr);
scoped_refptr<cc::ContextProvider> CreateContextProvider(
scoped_refptr<gpu::GpuChannelHost> gpu_channel);
// gpu::GpuChannelEstablishFactory:
void EstablishGpuChannel(
const gpu::GpuChannelEstablishedCallback& callback) override;
......@@ -57,7 +61,6 @@ class Gpu : public gpu::GpuChannelHostFactory,
scoped_refptr<base::SingleThreadTaskRunner> task_runner);
scoped_refptr<gpu::GpuChannelHost> GetGpuChannel();
void EstablishGpuChannelOnMainThreadSyncLocked();
void OnEstablishedGpuChannel(int client_id,
mojo::ScopedMessagePipeHandle channel_handle,
const gpu::GPUInfo& gpu_info);
......
......@@ -10,7 +10,6 @@ include_rules = [
"+mojo/public/cpp/system/buffer.h",
"+mojo/public/cpp/system/platform_handle.h",
"+services/ui/common/accelerator_util.h",
"+services/ui/public/cpp/context_provider.h",
"+services/ui/public/cpp/gpu",
"+services/ui/public/cpp/property_type_converters.h",
"+services/ui/public/cpp/raster_thread_helper.h",
......
......@@ -5,7 +5,6 @@
#include "ui/aura/mus/mus_context_factory.h"
#include "base/memory/ptr_util.h"
#include "services/ui/public/cpp/context_provider.h"
#include "services/ui/public/cpp/gpu/gpu.h"
#include "ui/aura/mus/window_port_mus.h"
#include "ui/aura/window_tree_host.h"
......@@ -13,24 +12,34 @@
namespace aura {
MusContextFactory::MusContextFactory(ui::Gpu* gpu) : gpu_(gpu) {}
MusContextFactory::MusContextFactory(ui::Gpu* gpu)
: gpu_(gpu), weak_ptr_factory_(this) {}
MusContextFactory::~MusContextFactory() {}
void MusContextFactory::CreateCompositorFrameSink(
base::WeakPtr<ui::Compositor> compositor) {
void MusContextFactory::OnEstablishedGpuChannel(
base::WeakPtr<ui::Compositor> compositor,
scoped_refptr<gpu::GpuChannelHost> gpu_channel) {
if (!compositor)
return;
WindowTreeHost* host =
WindowTreeHost::GetForAcceleratedWidget(compositor->widget());
WindowPortMus* window_port = WindowPortMus::Get(host->window());
DCHECK(window_port);
auto compositor_frame_sink = window_port->RequestCompositorFrameSink(
ui::mojom::CompositorFrameSinkType::DEFAULT,
make_scoped_refptr(
new ui::ContextProvider(gpu_->EstablishGpuChannelSync())),
gpu_->CreateContextProvider(std::move(gpu_channel)),
gpu_->gpu_memory_buffer_manager());
compositor->SetCompositorFrameSink(std::move(compositor_frame_sink));
}
void MusContextFactory::CreateCompositorFrameSink(
base::WeakPtr<ui::Compositor> compositor) {
gpu_->EstablishGpuChannel(
base::Bind(&MusContextFactory::OnEstablishedGpuChannel,
weak_ptr_factory_.GetWeakPtr(), compositor));
}
scoped_refptr<cc::ContextProvider>
MusContextFactory::SharedMainThreadContextProvider() {
// NOTIMPLEMENTED();
......
......@@ -8,12 +8,18 @@
#include <stdint.h>
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "cc/surfaces/surface_manager.h"
#include "services/ui/public/cpp/raster_thread_helper.h"
#include "services/ui/public/interfaces/window_tree.mojom.h"
#include "ui/aura/aura_export.h"
#include "ui/compositor/compositor.h"
namespace gpu {
class GpuChannelHost;
}
namespace ui {
class Gpu;
}
......@@ -27,6 +33,10 @@ class AURA_EXPORT MusContextFactory : public ui::ContextFactory {
~MusContextFactory() override;
private:
// Callback function for Gpu::EstablishGpuChannel().
void OnEstablishedGpuChannel(base::WeakPtr<ui::Compositor> compositor,
scoped_refptr<gpu::GpuChannelHost> gpu_channel);
// ContextFactory:
void CreateCompositorFrameSink(
base::WeakPtr<ui::Compositor> compositor) override;
......@@ -42,6 +52,7 @@ class AURA_EXPORT MusContextFactory : public ui::ContextFactory {
ui::RasterThreadHelper raster_thread_helper_;
ui::Gpu* gpu_;
base::WeakPtrFactory<MusContextFactory> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(MusContextFactory);
};
......
......@@ -7,7 +7,6 @@
#include "base/memory/ptr_util.h"
#include "cc/resources/shared_bitmap_manager.h"
#include "cc/surfaces/surface_id_allocator.h"
#include "services/ui/public/cpp/context_provider.h"
#include "services/ui/public/cpp/gpu/gpu.h"
#include "services/ui/public/cpp/window.h"
#include "services/ui/public/cpp/window_compositor_frame_sink.h"
......@@ -28,8 +27,8 @@ void SurfaceContextFactory::CreateCompositorFrameSink(
ui::mojom::CompositorFrameSinkType compositor_frame_sink_type =
native_widget->compositor_frame_sink_type();
auto compositor_frame_sink = window->RequestCompositorFrameSink(
compositor_frame_sink_type, make_scoped_refptr(new ui::ContextProvider(
gpu_->EstablishGpuChannelSync())),
compositor_frame_sink_type,
gpu_->CreateContextProvider(gpu_->EstablishGpuChannelSync()),
gpu_->gpu_memory_buffer_manager());
compositor->SetCompositorFrameSink(std::move(compositor_frame_sink));
}
......
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