summaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
Diffstat (limited to 'components')
-rw-r--r--components/clipboard/BUILD.gn44
-rw-r--r--components/clipboard/DEPS6
-rw-r--r--components/clipboard/clipboard_apptest.cc156
-rw-r--r--components/clipboard/clipboard_standalone_impl.cc89
-rw-r--r--components/clipboard/clipboard_standalone_impl.h62
-rw-r--r--components/clipboard/main.cc37
-rw-r--r--components/gles2/BUILD.gn59
-rw-r--r--components/gles2/DEPS8
-rw-r--r--components/gles2/command_buffer_driver.cc250
-rw-r--r--components/gles2/command_buffer_driver.h103
-rw-r--r--components/gles2/command_buffer_impl.cc160
-rw-r--r--components/gles2/command_buffer_impl.h71
-rw-r--r--components/gles2/command_buffer_type_conversions.cc170
-rw-r--r--components/gles2/command_buffer_type_conversions.h67
-rw-r--r--components/gles2/gpu_impl.cc36
-rw-r--r--components/gles2/gpu_impl.h49
-rw-r--r--components/gles2/gpu_state.cc21
-rw-r--r--components/gles2/gpu_state.h52
-rw-r--r--components/gles2/mojo_buffer_backing.cc34
-rw-r--r--components/gles2/mojo_buffer_backing.h39
20 files changed, 1513 insertions, 0 deletions
diff --git a/components/clipboard/BUILD.gn b/components/clipboard/BUILD.gn
new file mode 100644
index 0000000..cfdcb25
--- /dev/null
+++ b/components/clipboard/BUILD.gn
@@ -0,0 +1,44 @@
+# 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.
+
+import("//third_party/mojo/src/mojo/public/mojo_application.gni")
+
+mojo_native_application("clipboard") {
+ sources = [
+ "clipboard_standalone_impl.cc",
+ "clipboard_standalone_impl.h",
+ "main.cc",
+ ]
+
+ deps = [
+ "//base",
+ "//mojo/application",
+ "//mojo/common",
+ "//mojo/environment:chromium",
+ "//third_party/mojo/src/mojo/public/cpp/bindings",
+ "//third_party/mojo/src/mojo/public/cpp/bindings:callback",
+ "//third_party/mojo_services/src/clipboard/public/interfaces",
+ ]
+}
+
+mojo_native_application("apptests") {
+ output_name = "clipboard_apptests"
+
+ testonly = true
+
+ sources = [
+ "clipboard_apptest.cc",
+ ]
+
+ deps = [
+ "//base",
+ "//mojo/application",
+ "//mojo/application:test_support",
+ "//mojo/common",
+ "//third_party/mojo/src/mojo/public/cpp/bindings",
+ "//third_party/mojo_services/src/clipboard/public/interfaces",
+ ]
+
+ data_deps = [ ":clipboard($default_toolchain)" ]
+}
diff --git a/components/clipboard/DEPS b/components/clipboard/DEPS
new file mode 100644
index 0000000..6e68eac
--- /dev/null
+++ b/components/clipboard/DEPS
@@ -0,0 +1,6 @@
+include_rules = [
+ "+mojo/application",
+ "+mojo/common",
+ "+third_party/mojo_services/src/clipboard",
+ "+third_party/mojo/src/mojo/public",
+]
diff --git a/components/clipboard/clipboard_apptest.cc b/components/clipboard/clipboard_apptest.cc
new file mode 100644
index 0000000..bda9469
--- /dev/null
+++ b/components/clipboard/clipboard_apptest.cc
@@ -0,0 +1,156 @@
+// 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 "base/bind.h"
+#include "base/run_loop.h"
+#include "mojo/application/application_test_base_chromium.h"
+#include "mojo/common/common_type_converters.h"
+#include "third_party/mojo/src/mojo/public/cpp/application/application_impl.h"
+#include "third_party/mojo_services/src/clipboard/public/interfaces/clipboard.mojom.h"
+
+using mojo::Array;
+using mojo::Clipboard;
+using mojo::Map;
+using mojo::String;
+
+namespace {
+
+void CopyUint64AndEndRunloop(uint64_t* output,
+ base::RunLoop* run_loop,
+ uint64_t input) {
+ *output = input;
+ run_loop->Quit();
+}
+
+void CopyStringAndEndRunloop(std::string* output,
+ bool* string_is_null,
+ base::RunLoop* run_loop,
+ const Array<uint8_t>& input) {
+ *string_is_null = input.is_null();
+ *output = input.is_null() ? "" : input.To<std::string>();
+ run_loop->Quit();
+}
+
+void CopyVectorStringAndEndRunloop(std::vector<std::string>* output,
+ base::RunLoop* run_loop,
+ const Array<String>& input) {
+ *output = input.To<std::vector<std::string> >();
+ run_loop->Quit();
+}
+
+const char* kUninitialized = "Uninitialized data";
+const char* kPlainTextData = "Some plain data";
+const char* kHtmlData = "<html>data</html>";
+
+} // namespace
+
+namespace clipboard {
+
+class ClipboardAppTest : public mojo::test::ApplicationTestBase {
+ public:
+ ClipboardAppTest() : ApplicationTestBase() {}
+ ~ClipboardAppTest() override {}
+
+ void SetUp() override {
+ mojo::test::ApplicationTestBase::SetUp();
+ application_impl()->ConnectToService("mojo:clipboard", &clipboard_);
+ }
+
+ uint64_t GetSequenceNumber() {
+ base::RunLoop run_loop;
+ uint64_t sequence_num = 999999;
+ clipboard_->GetSequenceNumber(
+ Clipboard::TYPE_COPY_PASTE,
+ base::Bind(&CopyUint64AndEndRunloop, &sequence_num, &run_loop));
+ run_loop.Run();
+ return sequence_num;
+ }
+
+ std::vector<std::string> GetAvailableFormatMimeTypes() {
+ base::RunLoop run_loop;
+ std::vector<std::string> types;
+ types.push_back(kUninitialized);
+ clipboard_->GetAvailableMimeTypes(
+ Clipboard::TYPE_COPY_PASTE,
+ base::Bind(&CopyVectorStringAndEndRunloop, &types, &run_loop));
+ run_loop.Run();
+ return types;
+ }
+
+ bool GetDataOfType(const std::string& mime_type, std::string* data) {
+ base::RunLoop run_loop;
+ bool is_null = false;
+ clipboard_->ReadMimeType(
+ Clipboard::TYPE_COPY_PASTE, mime_type,
+ base::Bind(&CopyStringAndEndRunloop, data, &is_null, &run_loop));
+ run_loop.Run();
+ return !is_null;
+ }
+
+ void SetStringText(const std::string& data) {
+ Map<String, Array<uint8_t>> mime_data;
+ mime_data[Clipboard::MIME_TYPE_TEXT] = Array<uint8_t>::From(data);
+ clipboard_->WriteClipboardData(Clipboard::TYPE_COPY_PASTE,
+ mime_data.Pass());
+ }
+
+ protected:
+ mojo::ClipboardPtr clipboard_;
+
+ DISALLOW_COPY_AND_ASSIGN(ClipboardAppTest);
+};
+
+TEST_F(ClipboardAppTest, EmptyClipboardOK) {
+ EXPECT_EQ(0ul, GetSequenceNumber());
+ EXPECT_TRUE(GetAvailableFormatMimeTypes().empty());
+ std::string data;
+ EXPECT_FALSE(GetDataOfType(Clipboard::MIME_TYPE_TEXT, &data));
+}
+
+TEST_F(ClipboardAppTest, CanReadBackText) {
+ std::string data;
+ EXPECT_FALSE(GetDataOfType(Clipboard::MIME_TYPE_TEXT, &data));
+ EXPECT_EQ(0ul, GetSequenceNumber());
+
+ SetStringText(kPlainTextData);
+ EXPECT_EQ(1ul, GetSequenceNumber());
+
+ EXPECT_TRUE(GetDataOfType(Clipboard::MIME_TYPE_TEXT, &data));
+ EXPECT_EQ(kPlainTextData, data);
+}
+
+TEST_F(ClipboardAppTest, CanSetMultipleDataTypesAtOnce) {
+ Map<String, Array<uint8_t>> mime_data;
+ mime_data[Clipboard::MIME_TYPE_TEXT] =
+ Array<uint8_t>::From(std::string(kPlainTextData));
+ mime_data[Clipboard::MIME_TYPE_HTML] =
+ Array<uint8_t>::From(std::string(kHtmlData));
+
+ clipboard_->WriteClipboardData(Clipboard::TYPE_COPY_PASTE, mime_data.Pass());
+
+ EXPECT_EQ(1ul, GetSequenceNumber());
+
+ std::string data;
+ EXPECT_TRUE(GetDataOfType(Clipboard::MIME_TYPE_TEXT, &data));
+ EXPECT_EQ(kPlainTextData, data);
+ EXPECT_TRUE(GetDataOfType(Clipboard::MIME_TYPE_HTML, &data));
+ EXPECT_EQ(kHtmlData, data);
+}
+
+TEST_F(ClipboardAppTest, CanClearClipboardWithZeroArray) {
+ std::string data;
+ SetStringText(kPlainTextData);
+ EXPECT_EQ(1ul, GetSequenceNumber());
+
+ EXPECT_TRUE(GetDataOfType(Clipboard::MIME_TYPE_TEXT, &data));
+ EXPECT_EQ(kPlainTextData, data);
+
+ Map<String, Array<uint8_t>> mime_data;
+ clipboard_->WriteClipboardData(Clipboard::TYPE_COPY_PASTE, mime_data.Pass());
+
+ EXPECT_EQ(2ul, GetSequenceNumber());
+ EXPECT_FALSE(GetDataOfType(Clipboard::MIME_TYPE_TEXT, &data));
+}
+
+} // namespace clipboard
diff --git a/components/clipboard/clipboard_standalone_impl.cc b/components/clipboard/clipboard_standalone_impl.cc
new file mode 100644
index 0000000..2cf03c2
--- /dev/null
+++ b/components/clipboard/clipboard_standalone_impl.cc
@@ -0,0 +1,89 @@
+// 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 "components/clipboard/clipboard_standalone_impl.h"
+
+#include <string.h>
+
+#include "third_party/mojo/src/mojo/public/cpp/bindings/array.h"
+#include "third_party/mojo/src/mojo/public/cpp/bindings/callback.h"
+#include "third_party/mojo/src/mojo/public/cpp/bindings/string.h"
+
+using mojo::Array;
+using mojo::Map;
+using mojo::String;
+
+namespace clipboard {
+
+// ClipboardData contains data copied to the Clipboard for a variety of formats.
+// It mostly just provides APIs to cleanly access and manipulate this data.
+class ClipboardStandaloneImpl::ClipboardData {
+ public:
+ ClipboardData() {}
+ ~ClipboardData() {}
+
+ Array<String> GetMimeTypes() const {
+ Array<String> types(data_types_.size());
+ int i = 0;
+ for (auto it = data_types_.begin(); it != data_types_.end(); ++it, ++i)
+ types[i] = it.GetKey();
+
+ return types.Pass();
+ }
+
+ void SetData(Map<String, Array<uint8_t>> data) { data_types_ = data.Pass(); }
+
+ void GetData(const String& mime_type, Array<uint8_t>* data) const {
+ auto it = data_types_.find(mime_type);
+ if (it != data_types_.end())
+ *data = it.GetValue().Clone();
+ }
+
+ private:
+ Map<String, Array<uint8_t>> data_types_;
+
+ DISALLOW_COPY_AND_ASSIGN(ClipboardData);
+};
+
+ClipboardStandaloneImpl::ClipboardStandaloneImpl(
+ mojo::InterfaceRequest<mojo::Clipboard> request)
+ : binding_(this, request.Pass()) {
+ for (int i = 0; i < kNumClipboards; ++i) {
+ sequence_number_[i] = 0;
+ clipboard_state_[i].reset(new ClipboardData);
+ }
+}
+
+ClipboardStandaloneImpl::~ClipboardStandaloneImpl() {
+}
+
+void ClipboardStandaloneImpl::GetSequenceNumber(
+ Clipboard::Type clipboard_type,
+ const mojo::Callback<void(uint64_t)>& callback) {
+ callback.Run(sequence_number_[clipboard_type]);
+}
+
+void ClipboardStandaloneImpl::GetAvailableMimeTypes(
+ Clipboard::Type clipboard_type,
+ const mojo::Callback<void(Array<String>)>& callback) {
+ callback.Run(clipboard_state_[clipboard_type]->GetMimeTypes().Pass());
+}
+
+void ClipboardStandaloneImpl::ReadMimeType(
+ Clipboard::Type clipboard_type,
+ const String& mime_type,
+ const mojo::Callback<void(Array<uint8_t>)>& callback) {
+ Array<uint8_t> mime_data;
+ clipboard_state_[clipboard_type]->GetData(mime_type, &mime_data);
+ callback.Run(mime_data.Pass());
+}
+
+void ClipboardStandaloneImpl::WriteClipboardData(
+ Clipboard::Type clipboard_type,
+ Map<String, Array<uint8_t>> data) {
+ sequence_number_[clipboard_type]++;
+ clipboard_state_[clipboard_type]->SetData(data.Pass());
+}
+
+} // namespace clipboard
diff --git a/components/clipboard/clipboard_standalone_impl.h b/components/clipboard/clipboard_standalone_impl.h
new file mode 100644
index 0000000..eecae95
--- /dev/null
+++ b/components/clipboard/clipboard_standalone_impl.h
@@ -0,0 +1,62 @@
+// 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 COMPONENTS_CLIPBOARD_CLIPBOARD_STANDALONE_IMPL_H_
+#define COMPONENTS_CLIPBOARD_CLIPBOARD_STANDALONE_IMPL_H_
+
+#include <base/memory/scoped_ptr.h>
+#include <string>
+
+#include "third_party/mojo/src/mojo/public/cpp/bindings/strong_binding.h"
+#include "third_party/mojo_services/src/clipboard/public/interfaces/clipboard.mojom.h"
+
+namespace clipboard {
+
+// Stub clipboard implementation.
+//
+// Eventually, we'll actually want to interact with the system clipboard, but
+// that's hard today because the system clipboard is asynchronous (on X11), the
+// ui::Clipboard interface is synchronous (which is what we'd use), mojo is
+// asynchronous across processes, and the WebClipboard interface is synchronous
+// (which is at least tractable).
+class ClipboardStandaloneImpl : public mojo::Clipboard {
+ public:
+ // mojo::Clipboard exposes three possible clipboards.
+ static const int kNumClipboards = 3;
+
+ explicit ClipboardStandaloneImpl(
+ mojo::InterfaceRequest<mojo::Clipboard> request);
+ ~ClipboardStandaloneImpl() override;
+
+ // mojo::Clipboard implementation.
+ void GetSequenceNumber(
+ mojo::Clipboard::Type clipboard_type,
+ const mojo::Callback<void(uint64_t)>& callback) override;
+ void GetAvailableMimeTypes(
+ mojo::Clipboard::Type clipboard_types,
+ const mojo::Callback<void(mojo::Array<mojo::String>)>& callback) override;
+ void ReadMimeType(
+ mojo::Clipboard::Type clipboard_type,
+ const mojo::String& mime_type,
+ const mojo::Callback<void(mojo::Array<uint8_t>)>& callback) override;
+ void WriteClipboardData(
+ mojo::Clipboard::Type clipboard_type,
+ mojo::Map<mojo::String, mojo::Array<uint8_t>> data) override;
+
+ private:
+ uint64_t sequence_number_[kNumClipboards];
+
+ // Internal struct which stores the current state of the clipboard.
+ class ClipboardData;
+
+ // The current clipboard state. This is what is read from.
+ scoped_ptr<ClipboardData> clipboard_state_[kNumClipboards];
+ mojo::StrongBinding<mojo::Clipboard> binding_;
+
+ DISALLOW_COPY_AND_ASSIGN(ClipboardStandaloneImpl);
+};
+
+} // namespace clipboard
+
+#endif // COMPONENTS_CLIPBOARD_CLIPBOARD_STANDALONE_IMPL_H_
diff --git a/components/clipboard/main.cc b/components/clipboard/main.cc
new file mode 100644
index 0000000..75667d1
--- /dev/null
+++ b/components/clipboard/main.cc
@@ -0,0 +1,37 @@
+// 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 "components/clipboard/clipboard_standalone_impl.h"
+#include "mojo/application/application_runner_chromium.h"
+#include "third_party/mojo/src/mojo/public/c/system/main.h"
+#include "third_party/mojo/src/mojo/public/cpp/application/application_connection.h"
+#include "third_party/mojo/src/mojo/public/cpp/application/application_delegate.h"
+#include "third_party/mojo/src/mojo/public/cpp/application/interface_factory.h"
+
+class Delegate : public mojo::ApplicationDelegate,
+ public mojo::InterfaceFactory<mojo::Clipboard> {
+ public:
+ Delegate() {}
+ ~Delegate() override {}
+
+ // mojo::ApplicationDelegate implementation.
+ bool ConfigureIncomingConnection(
+ mojo::ApplicationConnection* connection) override {
+ connection->AddService(this);
+ return true;
+ }
+
+ // mojo::InterfaceFactory<mojo::Clipboard> implementation.
+ void Create(mojo::ApplicationConnection* connection,
+ mojo::InterfaceRequest<mojo::Clipboard> request) override {
+ // TODO(erg): Write native implementations of the clipboard. For now, we
+ // just build a clipboard which doesn't interact with the system.
+ new clipboard::ClipboardStandaloneImpl(request.Pass());
+ }
+};
+
+MojoResult MojoMain(MojoHandle shell_handle) {
+ mojo::ApplicationRunnerChromium runner(new Delegate);
+ return runner.Run(shell_handle);
+}
diff --git a/components/gles2/BUILD.gn b/components/gles2/BUILD.gn
new file mode 100644
index 0000000..c429972
--- /dev/null
+++ b/components/gles2/BUILD.gn
@@ -0,0 +1,59 @@
+# 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.
+
+import("//third_party/mojo/src/mojo/public/tools/bindings/mojom.gni")
+
+source_set("gles2") {
+ visibility = [
+ "//mojo/shell:lib", # For android
+ "//mojo/services/native_viewport:*",
+ ]
+
+ sources = [
+ "command_buffer_driver.cc",
+ "command_buffer_driver.h",
+ "command_buffer_impl.cc",
+ "command_buffer_impl.h",
+ "gpu_impl.cc",
+ "gpu_impl.h",
+ "gpu_state.cc",
+ "gpu_state.h",
+ ]
+
+ public_deps = [
+ ":lib",
+ ]
+ deps = [
+ "//base",
+ "//gpu/command_buffer/service",
+ "//mojo/converters/geometry",
+ "//third_party/mojo/src/mojo/public/cpp/bindings",
+ "//third_party/mojo_services/src/geometry/public/interfaces",
+ "//third_party/mojo_services/src/gpu/public/interfaces",
+ "//ui/gfx",
+ "//ui/gfx/geometry",
+ "//ui/gl",
+ ]
+
+ include_dirs = [ "../.." ]
+}
+
+source_set("lib") {
+ sources = [
+ "command_buffer_type_conversions.cc",
+ "command_buffer_type_conversions.h",
+ "mojo_buffer_backing.cc",
+ "mojo_buffer_backing.h",
+ ]
+
+ deps = [
+ "//base",
+ "//gpu/command_buffer/common",
+ "//third_party/mojo/src/mojo/public/cpp/bindings",
+ "//third_party/mojo/src/mojo/public/cpp/system",
+ "//third_party/mojo_services/src/gpu/public/interfaces",
+ ]
+
+ include_dirs = [ "../.." ]
+}
diff --git a/components/gles2/DEPS b/components/gles2/DEPS
new file mode 100644
index 0000000..916b0dc
--- /dev/null
+++ b/components/gles2/DEPS
@@ -0,0 +1,8 @@
+include_rules = [
+ "+gpu",
+ "+mojo/converters",
+ "+third_party/mojo/src/mojo/public",
+ "+third_party/mojo_services/src/geometry",
+ "+third_party/mojo_services/src/gpu",
+ "+ui",
+]
diff --git a/components/gles2/command_buffer_driver.cc b/components/gles2/command_buffer_driver.cc
new file mode 100644
index 0000000..cfd2a7d
--- /dev/null
+++ b/components/gles2/command_buffer_driver.cc
@@ -0,0 +1,250 @@
+// Copyright 2013 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 "components/gles2/command_buffer_driver.h"
+
+#include "base/bind.h"
+#include "base/macros.h"
+#include "base/memory/shared_memory.h"
+#include "components/gles2/command_buffer_type_conversions.h"
+#include "components/gles2/mojo_buffer_backing.h"
+#include "gpu/command_buffer/common/constants.h"
+#include "gpu/command_buffer/common/value_state.h"
+#include "gpu/command_buffer/service/command_buffer_service.h"
+#include "gpu/command_buffer/service/context_group.h"
+#include "gpu/command_buffer/service/gles2_cmd_decoder.h"
+#include "gpu/command_buffer/service/gpu_scheduler.h"
+#include "gpu/command_buffer/service/image_manager.h"
+#include "gpu/command_buffer/service/mailbox_manager.h"
+#include "gpu/command_buffer/service/memory_tracking.h"
+#include "gpu/command_buffer/service/sync_point_manager.h"
+#include "gpu/command_buffer/service/valuebuffer_manager.h"
+#include "ui/gfx/vsync_provider.h"
+#include "ui/gl/gl_context.h"
+#include "ui/gl/gl_surface.h"
+
+namespace gles2 {
+
+namespace {
+
+class MemoryTrackerStub : public gpu::gles2::MemoryTracker {
+ public:
+ MemoryTrackerStub() {}
+
+ void TrackMemoryAllocatedChange(
+ size_t old_size,
+ size_t new_size,
+ gpu::gles2::MemoryTracker::Pool pool) override {}
+
+ bool EnsureGPUMemoryAvailable(size_t size_needed) override { return true; };
+
+ private:
+ ~MemoryTrackerStub() override {}
+
+ DISALLOW_COPY_AND_ASSIGN(MemoryTrackerStub);
+};
+
+} // anonymous namespace
+
+CommandBufferDriver::Client::~Client() {
+}
+
+CommandBufferDriver::CommandBufferDriver(
+ gfx::GLShareGroup* share_group,
+ gpu::gles2::MailboxManager* mailbox_manager,
+ gpu::SyncPointManager* sync_point_manager)
+ : CommandBufferDriver(gfx::kNullAcceleratedWidget,
+ share_group,
+ mailbox_manager,
+ sync_point_manager) {
+}
+
+CommandBufferDriver::CommandBufferDriver(
+ gfx::AcceleratedWidget widget,
+ gfx::GLShareGroup* share_group,
+ gpu::gles2::MailboxManager* mailbox_manager,
+ gpu::SyncPointManager* sync_point_manager)
+ : client_(nullptr),
+ widget_(widget),
+ share_group_(share_group),
+ mailbox_manager_(mailbox_manager),
+ sync_point_manager_(sync_point_manager),
+ weak_factory_(this) {
+}
+
+CommandBufferDriver::~CommandBufferDriver() {
+ if (decoder_) {
+ bool have_context = decoder_->MakeCurrent();
+ decoder_->Destroy(have_context);
+ }
+}
+
+void CommandBufferDriver::Initialize(
+ mojo::CommandBufferSyncClientPtr sync_client,
+ mojo::CommandBufferLostContextObserverPtr loss_observer,
+ mojo::ScopedSharedBufferHandle shared_state) {
+ sync_client_ = sync_client.Pass();
+ loss_observer_ = loss_observer.Pass();
+ bool success = DoInitialize(shared_state.Pass());
+ mojo::GpuCapabilitiesPtr capabilities =
+ success ? mojo::GpuCapabilities::From(decoder_->GetCapabilities())
+ : mojo::GpuCapabilities::New();
+ sync_client_->DidInitialize(success, capabilities.Pass());
+}
+
+bool CommandBufferDriver::DoInitialize(
+ mojo::ScopedSharedBufferHandle shared_state) {
+ if (widget_ == gfx::kNullAcceleratedWidget)
+ surface_ = gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size(1, 1));
+ else {
+ surface_ = gfx::GLSurface::CreateViewGLSurface(widget_);
+ if (auto vsync_provider = surface_->GetVSyncProvider()) {
+ vsync_provider->GetVSyncParameters(
+ base::Bind(&CommandBufferDriver::OnUpdateVSyncParameters,
+ weak_factory_.GetWeakPtr()));
+ }
+ }
+
+ if (!surface_.get())
+ return false;
+
+ // TODO(piman): virtual contexts, gpu preference.
+ context_ = gfx::GLContext::CreateGLContext(share_group_.get(), surface_.get(),
+ gfx::PreferIntegratedGpu);
+ if (!context_.get())
+ return false;
+
+ if (!context_->MakeCurrent(surface_.get()))
+ return false;
+
+ // TODO(piman): ShaderTranslatorCache is currently per-ContextGroup but
+ // only needs to be per-thread.
+ bool bind_generates_resource = false;
+ scoped_refptr<gpu::gles2::ContextGroup> context_group =
+ new gpu::gles2::ContextGroup(
+ mailbox_manager_.get(), new MemoryTrackerStub,
+ new gpu::gles2::ShaderTranslatorCache, nullptr, nullptr, nullptr,
+ bind_generates_resource);
+
+ command_buffer_.reset(
+ new gpu::CommandBufferService(context_group->transfer_buffer_manager()));
+ bool result = command_buffer_->Initialize();
+ DCHECK(result);
+
+ decoder_.reset(::gpu::gles2::GLES2Decoder::Create(context_group.get()));
+ scheduler_.reset(new gpu::GpuScheduler(command_buffer_.get(), decoder_.get(),
+ decoder_.get()));
+ decoder_->set_engine(scheduler_.get());
+ decoder_->SetResizeCallback(
+ base::Bind(&CommandBufferDriver::OnResize, base::Unretained(this)));
+ decoder_->SetWaitSyncPointCallback(base::Bind(
+ &CommandBufferDriver::OnWaitSyncPoint, base::Unretained(this)));
+
+ gpu::gles2::DisallowedFeatures disallowed_features;
+
+ // TODO(piman): attributes.
+ std::vector<int32> attrib_vector;
+ if (!decoder_->Initialize(surface_, context_, false /* offscreen */,
+ gfx::Size(1, 1), disallowed_features,
+ attrib_vector))
+ return false;
+
+ command_buffer_->SetPutOffsetChangeCallback(base::Bind(
+ &gpu::GpuScheduler::PutChanged, base::Unretained(scheduler_.get())));
+ command_buffer_->SetGetBufferChangeCallback(base::Bind(
+ &gpu::GpuScheduler::SetGetBuffer, base::Unretained(scheduler_.get())));
+ command_buffer_->SetParseErrorCallback(
+ base::Bind(&CommandBufferDriver::OnParseError, base::Unretained(this)));
+
+ // TODO(piman): other callbacks
+
+ const size_t kSize = sizeof(gpu::CommandBufferSharedState);
+ scoped_ptr<gpu::BufferBacking> backing(
+ gles2::MojoBufferBacking::Create(shared_state.Pass(), kSize));
+ if (!backing)
+ return false;
+
+ command_buffer_->SetSharedStateBuffer(backing.Pass());
+ return true;
+}
+
+void CommandBufferDriver::SetGetBuffer(int32_t buffer) {
+ command_buffer_->SetGetBuffer(buffer);
+}
+
+void CommandBufferDriver::Flush(int32_t put_offset) {
+ if (!context_->MakeCurrent(surface_.get())) {
+ DLOG(WARNING) << "Context lost";
+ OnContextLost(gpu::error::kUnknown);
+ return;
+ }
+ command_buffer_->Flush(put_offset);
+}
+
+void CommandBufferDriver::MakeProgress(int32_t last_get_offset) {
+ // TODO(piman): handle out-of-order.
+ sync_client_->DidMakeProgress(
+ mojo::CommandBufferState::From(command_buffer_->GetLastState()));
+}
+
+void CommandBufferDriver::RegisterTransferBuffer(
+ int32_t id,
+ mojo::ScopedSharedBufferHandle transfer_buffer,
+ uint32_t size) {
+ // Take ownership of the memory and map it into this process.
+ // This validates the size.
+ scoped_ptr<gpu::BufferBacking> backing(
+ gles2::MojoBufferBacking::Create(transfer_buffer.Pass(), size));
+ if (!backing) {
+ DVLOG(0) << "Failed to map shared memory.";
+ return;
+ }
+ command_buffer_->RegisterTransferBuffer(id, backing.Pass());
+}
+
+void CommandBufferDriver::DestroyTransferBuffer(int32_t id) {
+ command_buffer_->DestroyTransferBuffer(id);
+}
+
+void CommandBufferDriver::Echo(const mojo::Callback<void()>& callback) {
+ callback.Run();
+}
+
+void CommandBufferDriver::OnParseError() {
+ gpu::CommandBuffer::State state = command_buffer_->GetLastState();
+ OnContextLost(state.context_lost_reason);
+}
+
+void CommandBufferDriver::OnResize(gfx::Size size, float scale_factor) {
+ surface_->Resize(size);
+}
+
+bool CommandBufferDriver::OnWaitSyncPoint(uint32_t sync_point) {
+ if (!sync_point)
+ return true;
+ if (sync_point_manager_->IsSyncPointRetired(sync_point))
+ return true;
+ scheduler_->SetScheduled(false);
+ sync_point_manager_->AddSyncPointCallback(
+ sync_point, base::Bind(&CommandBufferDriver::OnSyncPointRetired,
+ weak_factory_.GetWeakPtr()));
+ return scheduler_->IsScheduled();
+}
+
+void CommandBufferDriver::OnSyncPointRetired() {
+ scheduler_->SetScheduled(true);
+}
+
+void CommandBufferDriver::OnContextLost(uint32_t reason) {
+ loss_observer_->DidLoseContext(reason);
+ client_->DidLoseContext();
+}
+
+void CommandBufferDriver::OnUpdateVSyncParameters(
+ const base::TimeTicks timebase,
+ const base::TimeDelta interval) {
+ client_->UpdateVSyncParameters(timebase, interval);
+}
+
+} // namespace gles2
diff --git a/components/gles2/command_buffer_driver.h b/components/gles2/command_buffer_driver.h
new file mode 100644
index 0000000..d5627f8
--- /dev/null
+++ b/components/gles2/command_buffer_driver.h
@@ -0,0 +1,103 @@
+// Copyright 2013 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 COMPONENTS_GLES2_COMMAND_BUFFER_DRIVER_H_
+#define COMPONENTS_GLES2_COMMAND_BUFFER_DRIVER_H_
+
+#include "base/callback.h"
+#include "base/macros.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/single_thread_task_runner.h"
+#include "base/timer/timer.h"
+#include "third_party/mojo_services/src/gpu/public/interfaces/command_buffer.mojom.h"
+#include "ui/gfx/geometry/size.h"
+#include "ui/gfx/native_widget_types.h"
+
+namespace gpu {
+class CommandBufferService;
+class GpuScheduler;
+class GpuControlService;
+class SyncPointManager;
+namespace gles2 {
+class GLES2Decoder;
+class MailboxManager;
+}
+}
+
+namespace gfx {
+class GLContext;
+class GLShareGroup;
+class GLSurface;
+}
+
+namespace gles2 {
+
+class CommandBufferDriver {
+ public:
+ class Client {
+ public:
+ virtual ~Client();
+ virtual void UpdateVSyncParameters(base::TimeTicks timebase,
+ base::TimeDelta interval) = 0;
+ virtual void DidLoseContext() = 0;
+ };
+ // Offscreen.
+ CommandBufferDriver(gfx::GLShareGroup* share_group,
+ gpu::gles2::MailboxManager* mailbox_manager,
+ gpu::SyncPointManager* sync_point_manager);
+ // Onscreen.
+ CommandBufferDriver(gfx::AcceleratedWidget widget,
+ gfx::GLShareGroup* share_group,
+ gpu::gles2::MailboxManager* mailbox_manager,
+ gpu::SyncPointManager* sync_point_manager);
+ ~CommandBufferDriver();
+
+ void set_client(scoped_ptr<Client> client) { client_ = client.Pass(); }
+
+ void Initialize(mojo::CommandBufferSyncClientPtr sync_client,
+ mojo::CommandBufferLostContextObserverPtr loss_observer,
+ mojo::ScopedSharedBufferHandle shared_state);
+ void SetGetBuffer(int32_t buffer);
+ void Flush(int32_t put_offset);
+ void MakeProgress(int32_t last_get_offset);
+ void RegisterTransferBuffer(int32_t id,
+ mojo::ScopedSharedBufferHandle transfer_buffer,
+ uint32_t size);
+ void DestroyTransferBuffer(int32_t id);
+ void Echo(const mojo::Callback<void()>& callback);
+
+ private:
+ bool DoInitialize(mojo::ScopedSharedBufferHandle shared_state);
+ void OnResize(gfx::Size size, float scale_factor);
+ bool OnWaitSyncPoint(uint32_t sync_point);
+ void OnSyncPointRetired();
+ void OnParseError();
+ void OnContextLost(uint32_t reason);
+ void OnUpdateVSyncParameters(const base::TimeTicks timebase,
+ const base::TimeDelta interval);
+
+ scoped_ptr<Client> client_;
+ mojo::CommandBufferSyncClientPtr sync_client_;
+ mojo::CommandBufferLostContextObserverPtr loss_observer_;
+ gfx::AcceleratedWidget widget_;
+ scoped_ptr<gpu::CommandBufferService> command_buffer_;
+ scoped_ptr<gpu::gles2::GLES2Decoder> decoder_;
+ scoped_ptr<gpu::GpuScheduler> scheduler_;
+ scoped_refptr<gfx::GLContext> context_;
+ scoped_refptr<gfx::GLSurface> surface_;
+ scoped_refptr<gfx::GLShareGroup> share_group_;
+ scoped_refptr<gpu::gles2::MailboxManager> mailbox_manager_;
+ scoped_refptr<gpu::SyncPointManager> sync_point_manager_;
+
+ scoped_refptr<base::SingleThreadTaskRunner> context_lost_task_runner_;
+ base::Callback<void(int32_t)> context_lost_callback_;
+
+ base::WeakPtrFactory<CommandBufferDriver> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(CommandBufferDriver);
+};
+
+} // namespace gles2
+
+#endif // COMPONENTS_GLES2_COMMAND_BUFFER_DRIVER_H_
diff --git a/components/gles2/command_buffer_impl.cc b/components/gles2/command_buffer_impl.cc
new file mode 100644
index 0000000..358bcbf
--- /dev/null
+++ b/components/gles2/command_buffer_impl.cc
@@ -0,0 +1,160 @@
+// 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 "components/gles2/command_buffer_impl.h"
+
+#include "base/bind.h"
+#include "base/message_loop/message_loop.h"
+#include "components/gles2/command_buffer_driver.h"
+#include "gpu/command_buffer/service/sync_point_manager.h"
+
+namespace gles2 {
+namespace {
+void DestroyDriver(scoped_ptr<CommandBufferDriver> driver) {
+ // Just let ~scoped_ptr run.
+}
+
+void RunCallback(const mojo::Callback<void()>& callback) {
+ callback.Run();
+}
+
+class CommandBufferDriverClientImpl : public CommandBufferDriver::Client {
+ public:
+ CommandBufferDriverClientImpl(
+ base::WeakPtr<CommandBufferImpl> command_buffer,
+ scoped_refptr<base::SingleThreadTaskRunner> control_task_runner)
+ : command_buffer_(command_buffer),
+ control_task_runner_(control_task_runner) {}
+
+ private:
+ void UpdateVSyncParameters(base::TimeTicks timebase,
+ base::TimeDelta interval) override {
+ control_task_runner_->PostTask(
+ FROM_HERE, base::Bind(&CommandBufferImpl::UpdateVSyncParameters,
+ command_buffer_, timebase, interval));
+ }
+
+ void DidLoseContext() override {
+ control_task_runner_->PostTask(
+ FROM_HERE, base::Bind(&CommandBufferImpl::DidLoseContext,
+ command_buffer_));
+ }
+
+ base::WeakPtr<CommandBufferImpl> command_buffer_;
+ scoped_refptr<base::SingleThreadTaskRunner> control_task_runner_;
+};
+}
+
+CommandBufferImpl::CommandBufferImpl(
+ mojo::InterfaceRequest<mojo::CommandBuffer> request,
+ mojo::ViewportParameterListenerPtr listener,
+ scoped_refptr<base::SingleThreadTaskRunner> control_task_runner,
+ gpu::SyncPointManager* sync_point_manager,
+ scoped_ptr<CommandBufferDriver> driver)
+ : sync_point_manager_(sync_point_manager),
+ driver_task_runner_(base::MessageLoop::current()->task_runner()),
+ driver_(driver.Pass()),
+ viewport_parameter_listener_(listener.Pass()),
+ binding_(this),
+ weak_factory_(this) {
+ driver_->set_client(make_scoped_ptr(new CommandBufferDriverClientImpl(
+ weak_factory_.GetWeakPtr(), control_task_runner)));
+
+ control_task_runner->PostTask(
+ FROM_HERE, base::Bind(&CommandBufferImpl::BindToRequest,
+ base::Unretained(this), base::Passed(&request)));
+}
+
+CommandBufferImpl::~CommandBufferImpl() {
+ driver_task_runner_->PostTask(
+ FROM_HERE, base::Bind(&DestroyDriver, base::Passed(&driver_)));
+}
+
+void CommandBufferImpl::Initialize(
+ mojo::CommandBufferSyncClientPtr sync_client,
+ mojo::CommandBufferSyncPointClientPtr sync_point_client,
+ mojo::CommandBufferLostContextObserverPtr loss_observer,
+ mojo::ScopedSharedBufferHandle shared_state) {
+ sync_point_client_ = sync_point_client.Pass();
+ driver_task_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(&CommandBufferDriver::Initialize,
+ base::Unretained(driver_.get()), base::Passed(&sync_client),
+ base::Passed(&loss_observer),
+ base::Passed(&shared_state)));
+}
+
+void CommandBufferImpl::SetGetBuffer(int32_t buffer) {
+ driver_task_runner_->PostTask(
+ FROM_HERE, base::Bind(&CommandBufferDriver::SetGetBuffer,
+ base::Unretained(driver_.get()), buffer));
+}
+
+void CommandBufferImpl::Flush(int32_t put_offset) {
+ driver_task_runner_->PostTask(
+ FROM_HERE, base::Bind(&CommandBufferDriver::Flush,
+ base::Unretained(driver_.get()), put_offset));
+}
+
+void CommandBufferImpl::MakeProgress(int32_t last_get_offset) {
+ driver_task_runner_->PostTask(
+ FROM_HERE, base::Bind(&CommandBufferDriver::MakeProgress,
+ base::Unretained(driver_.get()), last_get_offset));
+}
+
+void CommandBufferImpl::RegisterTransferBuffer(
+ int32_t id,
+ mojo::ScopedSharedBufferHandle transfer_buffer,
+ uint32_t size) {
+ driver_task_runner_->PostTask(
+ FROM_HERE, base::Bind(&CommandBufferDriver::RegisterTransferBuffer,
+ base::Unretained(driver_.get()), id,
+ base::Passed(&transfer_buffer), size));
+}
+
+void CommandBufferImpl::DestroyTransferBuffer(int32_t id) {
+ driver_task_runner_->PostTask(
+ FROM_HERE, base::Bind(&CommandBufferDriver::DestroyTransferBuffer,
+ base::Unretained(driver_.get()), id));
+}
+
+void CommandBufferImpl::InsertSyncPoint(bool retire) {
+ uint32_t sync_point = sync_point_manager_->GenerateSyncPoint();
+ sync_point_client_->DidInsertSyncPoint(sync_point);
+ if (retire) {
+ driver_task_runner_->PostTask(
+ FROM_HERE, base::Bind(&gpu::SyncPointManager::RetireSyncPoint,
+ sync_point_manager_, sync_point));
+ }
+}
+
+void CommandBufferImpl::RetireSyncPoint(uint32_t sync_point) {
+ driver_task_runner_->PostTask(
+ FROM_HERE, base::Bind(&gpu::SyncPointManager::RetireSyncPoint,
+ sync_point_manager_, sync_point));
+}
+
+void CommandBufferImpl::Echo(const mojo::Callback<void()>& callback) {
+ driver_task_runner_->PostTaskAndReply(FROM_HERE, base::Bind(&base::DoNothing),
+ base::Bind(&RunCallback, callback));
+}
+
+void CommandBufferImpl::BindToRequest(
+ mojo::InterfaceRequest<mojo::CommandBuffer> request) {
+ binding_.Bind(request.Pass());
+}
+
+void CommandBufferImpl::DidLoseContext() {
+ binding_.OnConnectionError();
+}
+
+void CommandBufferImpl::UpdateVSyncParameters(base::TimeTicks timebase,
+ base::TimeDelta interval) {
+ if (!viewport_parameter_listener_)
+ return;
+ viewport_parameter_listener_->OnVSyncParametersUpdated(
+ timebase.ToInternalValue(), interval.ToInternalValue());
+}
+
+} // namespace gles2
diff --git a/components/gles2/command_buffer_impl.h b/components/gles2/command_buffer_impl.h
new file mode 100644
index 0000000..8d8c9e9
--- /dev/null
+++ b/components/gles2/command_buffer_impl.h
@@ -0,0 +1,71 @@
+// 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 COMPONENTS_GLES2_COMMAND_BUFFER_IMPL_H_
+#define COMPONENTS_GLES2_COMMAND_BUFFER_IMPL_H_
+
+#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
+#include "base/single_thread_task_runner.h"
+#include "third_party/mojo/src/mojo/public/cpp/bindings/strong_binding.h"
+#include "third_party/mojo_services/src/gpu/public/interfaces/command_buffer.mojom.h"
+#include "third_party/mojo_services/src/gpu/public/interfaces/viewport_parameter_listener.mojom.h"
+
+namespace gpu {
+class SyncPointManager;
+}
+
+namespace gles2 {
+class CommandBufferDriver;
+
+// This class listens to the CommandBuffer message pipe on a low-latency thread
+// so that we can insert sync points without blocking on the GL driver. It
+// forwards most method calls to the CommandBufferDriver, which runs on the
+// same thread as the native viewport.
+class CommandBufferImpl : public mojo::CommandBuffer {
+ public:
+ CommandBufferImpl(
+ mojo::InterfaceRequest<CommandBuffer> request,
+ mojo::ViewportParameterListenerPtr listener,
+ scoped_refptr<base::SingleThreadTaskRunner> control_task_runner,
+ gpu::SyncPointManager* sync_point_manager,
+ scoped_ptr<CommandBufferDriver> driver);
+ ~CommandBufferImpl() override;
+
+ void Initialize(mojo::CommandBufferSyncClientPtr sync_client,
+ mojo::CommandBufferSyncPointClientPtr sync_point_client,
+ mojo::CommandBufferLostContextObserverPtr loss_observer,
+ mojo::ScopedSharedBufferHandle shared_state) override;
+ void SetGetBuffer(int32_t buffer) override;
+ void Flush(int32_t put_offset) override;
+ void MakeProgress(int32_t last_get_offset) override;
+ void RegisterTransferBuffer(int32_t id,
+ mojo::ScopedSharedBufferHandle transfer_buffer,
+ uint32_t size) override;
+ void DestroyTransferBuffer(int32_t id) override;
+ void InsertSyncPoint(bool retire) override;
+ void RetireSyncPoint(uint32_t sync_point) override;
+ void Echo(const mojo::Callback<void()>& callback) override;
+
+ void DidLoseContext();
+ void UpdateVSyncParameters(base::TimeTicks timebase,
+ base::TimeDelta interval);
+
+ private:
+ void BindToRequest(mojo::InterfaceRequest<CommandBuffer> request);
+
+ scoped_refptr<gpu::SyncPointManager> sync_point_manager_;
+ scoped_refptr<base::SingleThreadTaskRunner> driver_task_runner_;
+ scoped_ptr<CommandBufferDriver> driver_;
+ mojo::CommandBufferSyncPointClientPtr sync_point_client_;
+ mojo::ViewportParameterListenerPtr viewport_parameter_listener_;
+ mojo::StrongBinding<CommandBuffer> binding_;
+
+ base::WeakPtrFactory<CommandBufferImpl> weak_factory_;
+ DISALLOW_COPY_AND_ASSIGN(CommandBufferImpl);
+};
+
+} // namespace gles2
+
+#endif // COMPONENTS_GLES2_COMMAND_BUFFER_IMPL_H_
diff --git a/components/gles2/command_buffer_type_conversions.cc b/components/gles2/command_buffer_type_conversions.cc
new file mode 100644
index 0000000..35de081
--- /dev/null
+++ b/components/gles2/command_buffer_type_conversions.cc
@@ -0,0 +1,170 @@
+// 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 "components/gles2/command_buffer_type_conversions.h"
+
+#include "third_party/mojo_services/src/gpu/public/interfaces/command_buffer.mojom.h"
+
+namespace mojo {
+
+CommandBufferStatePtr
+TypeConverter<CommandBufferStatePtr, gpu::CommandBuffer::State>::Convert(
+ const gpu::CommandBuffer::State& input) {
+ CommandBufferStatePtr result(CommandBufferState::New());
+ result->get_offset = input.get_offset;
+ result->token = input.token;
+ result->error = input.error;
+ result->context_lost_reason = input.context_lost_reason;
+ result->generation = input.generation;
+ return result.Pass();
+}
+
+gpu::CommandBuffer::State
+TypeConverter<gpu::CommandBuffer::State, CommandBufferStatePtr>::Convert(
+ const CommandBufferStatePtr& input) {
+ gpu::CommandBuffer::State state;
+ state.get_offset = input->get_offset;
+ state.token = input->token;
+ state.error = static_cast<gpu::error::Error>(input->error);
+ state.context_lost_reason =
+ static_cast<gpu::error::ContextLostReason>(input->context_lost_reason);
+ state.generation = input->generation;
+ return state;
+}
+
+GpuShaderPrecisionPtr
+TypeConverter<GpuShaderPrecisionPtr, gpu::Capabilities::ShaderPrecision>::
+ Convert(const gpu::Capabilities::ShaderPrecision& input) {
+ GpuShaderPrecisionPtr result(GpuShaderPrecision::New());
+ result->min_range = input.min_range;
+ result->max_range = input.max_range;
+ result->precision = input.precision;
+ return result.Pass();
+}
+
+gpu::Capabilities::ShaderPrecision TypeConverter<
+ gpu::Capabilities::ShaderPrecision,
+ GpuShaderPrecisionPtr>::Convert(const GpuShaderPrecisionPtr& input) {
+ gpu::Capabilities::ShaderPrecision result;
+ result.min_range = input->min_range;
+ result.max_range = input->max_range;
+ result.precision = input->precision;
+ return result;
+}
+
+GpuPerStagePrecisionsPtr
+TypeConverter<GpuPerStagePrecisionsPtr, gpu::Capabilities::PerStagePrecisions>::
+ Convert(const gpu::Capabilities::PerStagePrecisions& input) {
+ GpuPerStagePrecisionsPtr result(GpuPerStagePrecisions::New());
+ result->low_int = GpuShaderPrecision::From(input.low_int);
+ result->medium_int = GpuShaderPrecision::From(input.medium_int);
+ result->high_int = GpuShaderPrecision::From(input.high_int);
+ result->low_float = GpuShaderPrecision::From(input.low_float);
+ result->medium_float = GpuShaderPrecision::From(input.medium_float);
+ result->high_float = GpuShaderPrecision::From(input.high_float);
+ return result.Pass();
+}
+
+gpu::Capabilities::PerStagePrecisions TypeConverter<
+ gpu::Capabilities::PerStagePrecisions,
+ GpuPerStagePrecisionsPtr>::Convert(const GpuPerStagePrecisionsPtr& input) {
+ gpu::Capabilities::PerStagePrecisions result;
+ result.low_int = input->low_int.To<gpu::Capabilities::ShaderPrecision>();
+ result.medium_int =
+ input->medium_int.To<gpu::Capabilities::ShaderPrecision>();
+ result.high_int = input->high_int.To<gpu::Capabilities::ShaderPrecision>();
+ result.low_float = input->low_float.To<gpu::Capabilities::ShaderPrecision>();
+ result.medium_float =
+ input->medium_float.To<gpu::Capabilities::ShaderPrecision>();
+ result.high_float =
+ input->high_float.To<gpu::Capabilities::ShaderPrecision>();
+ return result;
+}
+
+GpuCapabilitiesPtr
+TypeConverter<GpuCapabilitiesPtr, gpu::Capabilities>::Convert(
+ const gpu::Capabilities& input) {
+ GpuCapabilitiesPtr result(GpuCapabilities::New());
+ result->vertex_shader_precisions =
+ GpuPerStagePrecisions::From(input.vertex_shader_precisions);
+ result->fragment_shader_precisions =
+ GpuPerStagePrecisions::From(input.fragment_shader_precisions);
+ result->max_combined_texture_image_units =
+ input.max_combined_texture_image_units;
+ result->max_cube_map_texture_size = input.max_cube_map_texture_size;
+ result->max_fragment_uniform_vectors = input.max_fragment_uniform_vectors;
+ result->max_renderbuffer_size = input.max_renderbuffer_size;
+ result->max_texture_image_units = input.max_texture_image_units;
+ result->max_texture_size = input.max_texture_size;
+ result->max_varying_vectors = input.max_varying_vectors;
+ result->max_vertex_attribs = input.max_vertex_attribs;
+ result->max_vertex_texture_image_units = input.max_vertex_texture_image_units;
+ result->max_vertex_uniform_vectors = input.max_vertex_uniform_vectors;
+ result->num_compressed_texture_formats = input.num_compressed_texture_formats;
+ result->num_shader_binary_formats = input.num_shader_binary_formats;
+ result->bind_generates_resource_chromium =
+ input.bind_generates_resource_chromium;
+ result->post_sub_buffer = input.post_sub_buffer;
+ result->egl_image_external = input.egl_image_external;
+ result->texture_format_bgra8888 = input.texture_format_bgra8888;
+ result->texture_format_etc1 = input.texture_format_etc1;
+ result->texture_format_etc1_npot = input.texture_format_etc1_npot;
+ result->texture_rectangle = input.texture_rectangle;
+ result->iosurface = input.iosurface;
+ result->texture_usage = input.texture_usage;
+ result->texture_storage = input.texture_storage;
+ result->discard_framebuffer = input.discard_framebuffer;
+ result->sync_query = input.sync_query;
+ result->image = input.image;
+ result->future_sync_points = input.future_sync_points;
+ result->blend_equation_advanced = input.blend_equation_advanced;
+ result->blend_equation_advanced_coherent =
+ input.blend_equation_advanced_coherent;
+ return result.Pass();
+}
+
+gpu::Capabilities TypeConverter<gpu::Capabilities, GpuCapabilitiesPtr>::Convert(
+ const GpuCapabilitiesPtr& input) {
+ gpu::Capabilities result;
+ result.vertex_shader_precisions =
+ input->vertex_shader_precisions
+ .To<gpu::Capabilities::PerStagePrecisions>();
+ result.fragment_shader_precisions =
+ input->fragment_shader_precisions
+ .To<gpu::Capabilities::PerStagePrecisions>();
+ result.max_combined_texture_image_units =
+ input->max_combined_texture_image_units;
+ result.max_cube_map_texture_size = input->max_cube_map_texture_size;
+ result.max_fragment_uniform_vectors = input->max_fragment_uniform_vectors;
+ result.max_renderbuffer_size = input->max_renderbuffer_size;
+ result.max_texture_image_units = input->max_texture_image_units;
+ result.max_texture_size = input->max_texture_size;
+ result.max_varying_vectors = input->max_varying_vectors;
+ result.max_vertex_attribs = input->max_vertex_attribs;
+ result.max_vertex_texture_image_units = input->max_vertex_texture_image_units;
+ result.max_vertex_uniform_vectors = input->max_vertex_uniform_vectors;
+ result.num_compressed_texture_formats = input->num_compressed_texture_formats;
+ result.num_shader_binary_formats = input->num_shader_binary_formats;
+ result.bind_generates_resource_chromium =
+ input->bind_generates_resource_chromium;
+ result.post_sub_buffer = input->post_sub_buffer;
+ result.egl_image_external = input->egl_image_external;
+ result.texture_format_bgra8888 = input->texture_format_bgra8888;
+ result.texture_format_etc1 = input->texture_format_etc1;
+ result.texture_format_etc1_npot = input->texture_format_etc1_npot;
+ result.texture_rectangle = input->texture_rectangle;
+ result.iosurface = input->iosurface;
+ result.texture_usage = input->texture_usage;
+ result.texture_storage = input->texture_storage;
+ result.discard_framebuffer = input->discard_framebuffer;
+ result.sync_query = input->sync_query;
+ result.image = input->image;
+ result.future_sync_points = input->future_sync_points;
+ result.blend_equation_advanced = input->blend_equation_advanced;
+ result.blend_equation_advanced_coherent =
+ input->blend_equation_advanced_coherent;
+ return result;
+}
+
+} // namespace gles2
diff --git a/components/gles2/command_buffer_type_conversions.h b/components/gles2/command_buffer_type_conversions.h
new file mode 100644
index 0000000..1ac166f
--- /dev/null
+++ b/components/gles2/command_buffer_type_conversions.h
@@ -0,0 +1,67 @@
+// 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 COMPONENTS_GLES2_COMMAND_BUFFER_TYPE_CONVERSIONS_H_
+#define COMPONENTS_GLES2_COMMAND_BUFFER_TYPE_CONVERSIONS_H_
+
+#include "gpu/command_buffer/common/capabilities.h"
+#include "gpu/command_buffer/common/command_buffer.h"
+#include "third_party/mojo/src/mojo/public/cpp/bindings/type_converter.h"
+#include "third_party/mojo_services/src/gpu/public/interfaces/command_buffer.mojom.h"
+
+namespace mojo {
+
+class CommandBufferState;
+
+template <>
+struct TypeConverter<CommandBufferStatePtr, gpu::CommandBuffer::State> {
+ static CommandBufferStatePtr Convert(const gpu::CommandBuffer::State& input);
+};
+
+template <>
+struct TypeConverter<gpu::CommandBuffer::State, CommandBufferStatePtr> {
+ static gpu::CommandBuffer::State Convert(const CommandBufferStatePtr& input);
+};
+
+template <>
+struct TypeConverter<GpuShaderPrecisionPtr,
+ gpu::Capabilities::ShaderPrecision> {
+ static GpuShaderPrecisionPtr Convert(
+ const gpu::Capabilities::ShaderPrecision& input);
+};
+
+template <>
+struct TypeConverter<gpu::Capabilities::ShaderPrecision,
+ GpuShaderPrecisionPtr> {
+ static gpu::Capabilities::ShaderPrecision Convert(
+ const GpuShaderPrecisionPtr& input);
+};
+
+template <>
+struct TypeConverter<GpuPerStagePrecisionsPtr,
+ gpu::Capabilities::PerStagePrecisions> {
+ static GpuPerStagePrecisionsPtr Convert(
+ const gpu::Capabilities::PerStagePrecisions& input);
+};
+
+template <>
+struct TypeConverter<gpu::Capabilities::PerStagePrecisions,
+ GpuPerStagePrecisionsPtr> {
+ static gpu::Capabilities::PerStagePrecisions Convert(
+ const GpuPerStagePrecisionsPtr& input);
+};
+
+template <>
+struct TypeConverter<GpuCapabilitiesPtr, gpu::Capabilities> {
+ static GpuCapabilitiesPtr Convert(const gpu::Capabilities& input);
+};
+
+template <>
+struct TypeConverter<gpu::Capabilities, GpuCapabilitiesPtr> {
+ static gpu::Capabilities Convert(const GpuCapabilitiesPtr& input);
+};
+
+} // namespace gles2
+
+#endif // COMPONENTS_GLES2_COMMAND_BUFFER_TYPE_CONVERSIONS_H_
diff --git a/components/gles2/gpu_impl.cc b/components/gles2/gpu_impl.cc
new file mode 100644
index 0000000..ef90f02
--- /dev/null
+++ b/components/gles2/gpu_impl.cc
@@ -0,0 +1,36 @@
+// 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 "components/gles2/gpu_impl.h"
+
+#include "components/gles2/command_buffer_driver.h"
+#include "components/gles2/command_buffer_impl.h"
+#include "gpu/command_buffer/service/mailbox_manager.h"
+#include "gpu/command_buffer/service/mailbox_manager_impl.h"
+#include "gpu/command_buffer/service/sync_point_manager.h"
+#include "mojo/converters/geometry/geometry_type_converters.h"
+#include "ui/gl/gl_share_group.h"
+#include "ui/gl/gl_surface.h"
+
+namespace gles2 {
+
+GpuImpl::GpuImpl(mojo::InterfaceRequest<Gpu> request,
+ const scoped_refptr<GpuState>& state)
+ : binding_(this, request.Pass()), state_(state) {
+}
+
+GpuImpl::~GpuImpl() {
+}
+
+void GpuImpl::CreateOffscreenGLES2Context(
+ mojo::InterfaceRequest<mojo::CommandBuffer> request) {
+ new CommandBufferImpl(request.Pass(), mojo::ViewportParameterListenerPtr(),
+ state_->control_task_runner(),
+ state_->sync_point_manager(),
+ make_scoped_ptr(new CommandBufferDriver(
+ state_->share_group(), state_->mailbox_manager(),
+ state_->sync_point_manager())));
+}
+
+} // namespace gles2
diff --git a/components/gles2/gpu_impl.h b/components/gles2/gpu_impl.h
new file mode 100644
index 0000000..c270076
--- /dev/null
+++ b/components/gles2/gpu_impl.h
@@ -0,0 +1,49 @@
+// 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 COMPONENTS_GLES2_GPU_IMPL_H_
+#define COMPONENTS_GLES2_GPU_IMPL_H_
+
+#include "base/macros.h"
+#include "base/memory/ref_counted.h"
+#include "base/threading/thread.h"
+#include "components/gles2/gpu_state.h"
+#include "third_party/mojo/src/mojo/public/cpp/bindings/interface_request.h"
+#include "third_party/mojo/src/mojo/public/cpp/bindings/strong_binding.h"
+#include "third_party/mojo_services/src/geometry/public/interfaces/geometry.mojom.h"
+#include "third_party/mojo_services/src/gpu/public/interfaces/command_buffer.mojom.h"
+#include "third_party/mojo_services/src/gpu/public/interfaces/gpu.mojom.h"
+
+namespace gfx {
+class GLShareGroup;
+}
+
+namespace gpu {
+class SyncPointManager;
+namespace gles2 {
+class MailboxManager;
+}
+}
+
+namespace gles2 {
+
+class GpuImpl : public mojo::Gpu {
+ public:
+ GpuImpl(mojo::InterfaceRequest<mojo::Gpu> request,
+ const scoped_refptr<GpuState>& state);
+ ~GpuImpl() override;
+
+ private:
+ void CreateOffscreenGLES2Context(mojo::InterfaceRequest<mojo::CommandBuffer>
+ command_buffer_request) override;
+
+ mojo::StrongBinding<Gpu> binding_;
+ scoped_refptr<GpuState> state_;
+
+ DISALLOW_COPY_AND_ASSIGN(GpuImpl);
+};
+
+} // namespace gles2
+
+#endif // COMPONENTS_GLES2_GPU_IMPL_H_
diff --git a/components/gles2/gpu_state.cc b/components/gles2/gpu_state.cc
new file mode 100644
index 0000000..6468a26
--- /dev/null
+++ b/components/gles2/gpu_state.cc
@@ -0,0 +1,21 @@
+// Copyright 2015 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 "components/gles2/gpu_state.h"
+
+namespace gles2 {
+
+GpuState::GpuState()
+ : control_thread_("gpu_command_buffer_control"),
+ sync_point_manager_(gpu::SyncPointManager::Create(true)),
+ share_group_(new gfx::GLShareGroup),
+ mailbox_manager_(new gpu::gles2::MailboxManagerImpl) {
+ control_thread_.Start();
+}
+
+GpuState::~GpuState() {
+}
+
+} // namespace gles2
diff --git a/components/gles2/gpu_state.h b/components/gles2/gpu_state.h
new file mode 100644
index 0000000..a9f9c59
--- /dev/null
+++ b/components/gles2/gpu_state.h
@@ -0,0 +1,52 @@
+// Copyright 2015 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 COMPONENTS_GLES2_GPU_STATE_H_
+#define COMPONENTS_GLES2_GPU_STATE_H_
+
+#include "base/memory/ref_counted.h"
+#include "base/single_thread_task_runner.h"
+#include "base/threading/thread.h"
+#include "gpu/command_buffer/service/mailbox_manager_impl.h"
+#include "gpu/command_buffer/service/sync_point_manager.h"
+#include "ui/gl/gl_share_group.h"
+
+namespace gles2 {
+
+// We need to share these across all CommandBuffer instances so that contexts
+// they create can share resources with each other via mailboxes.
+class GpuState : public base::RefCounted<GpuState> {
+ public:
+ GpuState();
+
+ // We run the CommandBufferImpl on the control_task_runner, which forwards
+ // most method class to the CommandBufferDriver, which runs on the "driver",
+ // thread (i.e., the thread on which GpuImpl instances are created).
+ scoped_refptr<base::SingleThreadTaskRunner> control_task_runner() {
+ return control_thread_.task_runner();
+ }
+
+ // These objects are intended to be used on the "driver" thread (i.e., the
+ // thread on which GpuImpl instances are created).
+ gfx::GLShareGroup* share_group() const { return share_group_.get(); }
+ gpu::gles2::MailboxManager* mailbox_manager() const {
+ return mailbox_manager_.get();
+ }
+ gpu::SyncPointManager* sync_point_manager() const {
+ return sync_point_manager_.get();
+ }
+
+ private:
+ friend class base::RefCounted<GpuState>;
+ ~GpuState();
+
+ base::Thread control_thread_;
+ scoped_refptr<gpu::SyncPointManager> sync_point_manager_;
+ scoped_refptr<gfx::GLShareGroup> share_group_;
+ scoped_refptr<gpu::gles2::MailboxManager> mailbox_manager_;
+};
+
+} // namespace gles2
+
+#endif // COMPONENTS_GLES2_GPU_STATE_H_
diff --git a/components/gles2/mojo_buffer_backing.cc b/components/gles2/mojo_buffer_backing.cc
new file mode 100644
index 0000000..f6e10da
--- /dev/null
+++ b/components/gles2/mojo_buffer_backing.cc
@@ -0,0 +1,34 @@
+// 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 "components/gles2/mojo_buffer_backing.h"
+
+#include "base/logging.h"
+
+namespace gles2 {
+
+MojoBufferBacking::MojoBufferBacking(mojo::ScopedSharedBufferHandle handle,
+ void* memory,
+ size_t size)
+ : handle_(handle.Pass()), memory_(memory), size_(size) {}
+
+MojoBufferBacking::~MojoBufferBacking() { mojo::UnmapBuffer(memory_); }
+
+// static
+scoped_ptr<gpu::BufferBacking> MojoBufferBacking::Create(
+ mojo::ScopedSharedBufferHandle handle,
+ size_t size) {
+ void* memory = NULL;
+ MojoResult result = mojo::MapBuffer(
+ handle.get(), 0, size, &memory, MOJO_MAP_BUFFER_FLAG_NONE);
+ if (result != MOJO_RESULT_OK)
+ return scoped_ptr<BufferBacking>();
+ DCHECK(memory);
+ return scoped_ptr<BufferBacking>(
+ new MojoBufferBacking(handle.Pass(), memory, size));
+}
+void* MojoBufferBacking::GetMemory() const { return memory_; }
+size_t MojoBufferBacking::GetSize() const { return size_; }
+
+} // namespace gles2
diff --git a/components/gles2/mojo_buffer_backing.h b/components/gles2/mojo_buffer_backing.h
new file mode 100644
index 0000000..6aa866d
--- /dev/null
+++ b/components/gles2/mojo_buffer_backing.h
@@ -0,0 +1,39 @@
+// 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 COMPONENTS_GLES2_MOJO_BUFFER_BACKING_H_
+#define COMPONENTS_GLES2_MOJO_BUFFER_BACKING_H_
+
+#include "base/macros.h"
+#include "base/memory/scoped_ptr.h"
+#include "gpu/command_buffer/common/buffer.h"
+#include "third_party/mojo/src/mojo/public/cpp/system/core.h"
+
+namespace gles2 {
+
+class MojoBufferBacking : public gpu::BufferBacking {
+ public:
+ MojoBufferBacking(mojo::ScopedSharedBufferHandle handle,
+ void* memory,
+ size_t size);
+ ~MojoBufferBacking() override;
+
+ static scoped_ptr<gpu::BufferBacking> Create(
+ mojo::ScopedSharedBufferHandle handle,
+ size_t size);
+
+ void* GetMemory() const override;
+ size_t GetSize() const override;
+
+ private:
+ mojo::ScopedSharedBufferHandle handle_;
+ void* memory_;
+ size_t size_;
+
+ DISALLOW_COPY_AND_ASSIGN(MojoBufferBacking);
+};
+
+} // namespace gles2
+
+#endif // COMPONENTS_GLES2_MOJO_BUFFER_BACKING_H_