Add a Display and ContextProvider concept to mojom, use to recreate
This introduces two new concepts to make initializing and reinitializing
the objects needed to draw onscreen easier. This makes it easier to draw
things and will make recovering from lost contexts simpler.
The first is ContextProvider which is an interface for creating contexts
(in the GPU command buffer sense) associated with a piece of state (such
as drawing to a particular native viewport). This allows code to request
command buffer contexts associated with a particular native viewport
multiple times without requiring passing identifiers around since the
identity of the native viewport in question is contained in the identity
of the message pipe that the interface is bound to. This also makes it
possible for the gpu mojoms to produce viewport-bound contexts without
needing to be aware of the native viewport interfaces explicitly or
through opaque ID side channels.
The second is Display which is an interface used to submit frames that
should be drawn onscreen. A Display is somewhat like a Surface with a
few differences that make interacting with one simpler than interacting
with a Surface in general. Display is only drawn to and never embedded
in another frame so it does not need to have an explicit size or global
ID as those are only used when embedding one Surface's frame into
another. The only operations a Display has to support is receiving
frames, ACKing them and returning resources when unused.
A Display needs to know how to draw to a particular context so it can be
constructed from a ContextProvider if that ContextProvider is associated
with the desired native viewport. This means that in turn the native
viewport service doesn't have to know anything about surfaces, it only
needs to provide appropriate ContextProvider implementations to whomever
asks.
R=qsr@chromium.org
Review URL: https://codereview.chromium.org/940293003
diff --git a/services/gles2/gpu_state.h b/services/gles2/gpu_state.h
new file mode 100644
index 0000000..1d75318
--- /dev/null
+++ b/services/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 SERVICES_GLES2_GPU_STATE_H_
+#define SERVICES_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 // SERVICES_GLES2_GPU_STATE_H_