Reland "Non-SFI mode: Switch to newlib. (patchset #4 id:60001 of https://codereview...
[chromium-blink-merge.git] / components / view_manager / gles2 / command_buffer_driver.h
blob0fdee33641cf56c6ffed626f97731310b4dfd34a
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_VIEW_MANAGER_GLES2_COMMAND_BUFFER_DRIVER_H_
6 #define COMPONENTS_VIEW_MANAGER_GLES2_COMMAND_BUFFER_DRIVER_H_
8 #include "base/callback.h"
9 #include "base/macros.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/single_thread_task_runner.h"
13 #include "base/timer/timer.h"
14 #include "components/view_manager/public/interfaces/command_buffer.mojom.h"
15 #include "ui/gfx/geometry/size.h"
16 #include "ui/gfx/native_widget_types.h"
18 namespace gpu {
19 class CommandBufferService;
20 class GpuScheduler;
21 class GpuControlService;
22 class SyncPointManager;
23 namespace gles2 {
24 class GLES2Decoder;
25 class MailboxManager;
29 namespace gfx {
30 class GLContext;
31 class GLShareGroup;
32 class GLSurface;
35 namespace gles2 {
37 // This class receives CommandBuffer messages on the same thread as the native
38 // viewport.
39 class CommandBufferDriver {
40 public:
41 class Client {
42 public:
43 virtual ~Client();
44 virtual void UpdateVSyncParameters(base::TimeTicks timebase,
45 base::TimeDelta interval) = 0;
46 virtual void DidLoseContext() = 0;
48 // Offscreen.
49 CommandBufferDriver(gfx::GLShareGroup* share_group,
50 gpu::gles2::MailboxManager* mailbox_manager,
51 gpu::SyncPointManager* sync_point_manager);
52 // Onscreen.
53 CommandBufferDriver(
54 gfx::AcceleratedWidget widget,
55 gfx::GLShareGroup* share_group,
56 gpu::gles2::MailboxManager* mailbox_manager,
57 gpu::SyncPointManager* sync_point_manager,
58 const base::Callback<void(CommandBufferDriver*)>& destruct_callback);
59 ~CommandBufferDriver();
61 void set_client(scoped_ptr<Client> client) { client_ = client.Pass(); }
63 void Initialize(mojo::CommandBufferSyncClientPtr sync_client,
64 mojo::CommandBufferLostContextObserverPtr loss_observer,
65 mojo::ScopedSharedBufferHandle shared_state);
66 void SetGetBuffer(int32_t buffer);
67 void Flush(int32_t put_offset);
68 void MakeProgress(int32_t last_get_offset);
69 void RegisterTransferBuffer(int32_t id,
70 mojo::ScopedSharedBufferHandle transfer_buffer,
71 uint32_t size);
72 void DestroyTransferBuffer(int32_t id);
73 void Echo(const mojo::Callback<void()>& callback);
74 void CreateImage(int32_t id,
75 mojo::ScopedHandle memory_handle,
76 int32_t type,
77 mojo::SizePtr size,
78 int32_t format,
79 int32_t internal_format);
80 void DestroyImage(int32_t id);
82 // Called at shutdown to destroy the X window. This is needed when the parent
83 // window is being destroyed. Otherwise X calls for this window will fail.
84 void DestroyWindow();
86 private:
87 bool DoInitialize(mojo::ScopedSharedBufferHandle shared_state);
88 void OnResize(gfx::Size size, float scale_factor);
89 bool OnWaitSyncPoint(uint32_t sync_point);
90 void OnSyncPointRetired();
91 void OnParseError();
92 void OnContextLost(uint32_t reason);
93 void OnUpdateVSyncParameters(const base::TimeTicks timebase,
94 const base::TimeDelta interval);
95 void DestroyDecoder();
97 scoped_ptr<Client> client_;
98 mojo::CommandBufferSyncClientPtr sync_client_;
99 mojo::CommandBufferLostContextObserverPtr loss_observer_;
100 gfx::AcceleratedWidget widget_;
101 scoped_ptr<gpu::CommandBufferService> command_buffer_;
102 scoped_ptr<gpu::gles2::GLES2Decoder> decoder_;
103 scoped_ptr<gpu::GpuScheduler> scheduler_;
104 scoped_refptr<gfx::GLContext> context_;
105 scoped_refptr<gfx::GLSurface> surface_;
106 scoped_refptr<gfx::GLShareGroup> share_group_;
107 scoped_refptr<gpu::gles2::MailboxManager> mailbox_manager_;
108 scoped_refptr<gpu::SyncPointManager> sync_point_manager_;
110 scoped_refptr<base::SingleThreadTaskRunner> context_lost_task_runner_;
111 base::Callback<void(int32_t)> context_lost_callback_;
113 base::Callback<void(CommandBufferDriver*)> destruct_callback_;
115 base::WeakPtrFactory<CommandBufferDriver> weak_factory_;
117 DISALLOW_COPY_AND_ASSIGN(CommandBufferDriver);
120 } // namespace gles2
122 #endif // COMPONENTS_GLES2_COMMAND_BUFFER_DRIVER_H_