OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef GPU_GLES2_CONFORM_SUPPORT_EGL_DISPLAY_H_ | 5 #ifndef GPU_GLES2_CONFORM_SUPPORT_EGL_DISPLAY_H_ |
6 #define GPU_GLES2_CONFORM_SUPPORT_EGL_DISPLAY_H_ | 6 #define GPU_GLES2_CONFORM_SUPPORT_EGL_DISPLAY_H_ |
7 | 7 |
8 #include <EGL/egl.h> | 8 #include <EGL/egl.h> |
9 #include <stddef.h> | 9 #include <stddef.h> |
10 #include <stdint.h> | 10 #include <stdint.h> |
11 | 11 |
| 12 #include <vector> |
| 13 |
12 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ref_counted.h" |
13 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
14 #include "gpu/command_buffer/client/gles2_cmd_helper.h" | 17 #include "base/synchronization/lock.h" |
15 #include "gpu/command_buffer/client/gpu_control.h" | |
16 #include "gpu/command_buffer/service/command_buffer_service.h" | |
17 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | |
18 #include "gpu/command_buffer/service/gpu_scheduler.h" | |
19 #include "ui/gfx/native_widget_types.h" | |
20 #include "ui/gl/gl_context.h" | |
21 #include "ui/gl/gl_surface.h" | |
22 | |
23 namespace gpu { | |
24 class CommandBufferService; | |
25 class GpuControl; | |
26 class GpuScheduler; | |
27 class TransferBuffer; | |
28 class TransferBufferManagerInterface; | |
29 | |
30 namespace gles2 { | |
31 class GLES2CmdHelper; | |
32 class GLES2Implementation; | |
33 } // namespace gles2 | |
34 } // namespace gpu | |
35 | 18 |
36 namespace egl { | 19 namespace egl { |
37 | 20 |
38 class Config; | 21 class Config; |
| 22 class Context; |
39 class Surface; | 23 class Surface; |
| 24 class ThreadState; |
40 | 25 |
41 class Display : private gpu::GpuControl { | 26 class Display { |
42 public: | 27 public: |
43 explicit Display(EGLNativeDisplayType display_id); | 28 explicit Display(); |
44 ~Display() override; | 29 ~Display(); |
45 | |
46 void SetCreateOffscreen(int width, int height) { | |
47 create_offscreen_ = true; | |
48 create_offscreen_width_ = width; | |
49 create_offscreen_height_ = height; | |
50 } | |
51 | 30 |
52 bool is_initialized() const { return is_initialized_; } | 31 bool is_initialized() const { return is_initialized_; } |
53 bool Initialize(); | 32 EGLBoolean Initialize(ThreadState* ts, EGLint* major, EGLint* minor); |
| 33 EGLBoolean Terminate(ThreadState* ts); |
| 34 const char* QueryString(ThreadState* ts, EGLint name); |
54 | 35 |
55 // Config routines. | 36 // Config routines. |
56 bool IsValidConfig(EGLConfig config); | 37 EGLBoolean GetConfigAttrib(ThreadState* ts, |
57 bool ChooseConfigs( | 38 EGLConfig cfg, |
58 EGLConfig* configs, EGLint config_size, EGLint* num_config); | 39 EGLint attribute, |
59 bool GetConfigs(EGLConfig* configs, EGLint config_size, EGLint* num_config); | 40 EGLint* value); |
60 bool GetConfigAttrib(EGLConfig config, EGLint attribute, EGLint* value); | 41 EGLBoolean ChooseConfig(ThreadState* ts, |
| 42 const EGLint* attrib_list, |
| 43 EGLConfig* configs, |
| 44 EGLint config_size, |
| 45 EGLint* num_config); |
| 46 EGLBoolean GetConfigs(ThreadState*, |
| 47 EGLConfig*, |
| 48 EGLint config_size, |
| 49 EGLint* num_config); |
61 | 50 |
62 // Surface routines. | 51 // Surface routines. |
63 bool IsValidNativeWindow(EGLNativeWindowType win); | 52 static bool IsValidNativeWindow(EGLNativeWindowType); |
64 bool IsValidSurface(EGLSurface surface); | 53 EGLSurface CreatePbufferSurface(ThreadState*, |
65 EGLSurface CreateWindowSurface(EGLConfig config, | 54 EGLConfig, |
| 55 const EGLint* attrib_list); |
| 56 EGLSurface CreateWindowSurface(ThreadState*, |
| 57 EGLConfig, |
66 EGLNativeWindowType win, | 58 EGLNativeWindowType win, |
67 const EGLint* attrib_list); | 59 const EGLint* attrib_list); |
68 void DestroySurface(EGLSurface surface); | 60 EGLBoolean DestroySurface(ThreadState*, EGLSurface); |
69 void SwapBuffers(EGLSurface surface); | 61 EGLBoolean SwapBuffers(ThreadState*, EGLSurface); |
70 | 62 |
71 // Context routines. | 63 // Context routines. |
72 bool IsValidContext(EGLContext ctx); | 64 EGLContext CreateContext(ThreadState*, |
73 EGLContext CreateContext(EGLConfig config, | 65 EGLConfig, |
74 EGLContext share_ctx, | 66 EGLSurface share_ctx, |
75 const EGLint* attrib_list); | 67 const EGLint* attrib_list); |
76 void DestroyContext(EGLContext ctx); | 68 EGLBoolean DestroyContext(ThreadState*, EGLContext); |
77 bool MakeCurrent(EGLSurface draw, EGLSurface read, EGLContext ctx); | |
78 | 69 |
79 // GpuControl implementation. | 70 EGLBoolean ReleaseCurrent(ThreadState*); |
80 gpu::Capabilities GetCapabilities() override; | 71 EGLBoolean MakeCurrent(ThreadState*, EGLSurface, EGLSurface, EGLContext); |
81 int32_t CreateImage(ClientBuffer buffer, | 72 |
82 size_t width, | 73 uint64_t GenerateFenceSyncRelease(); |
83 size_t height, | 74 bool IsFenceSyncRelease(uint64_t release); |
84 unsigned internalformat) override; | 75 bool IsFenceSyncFlushed(uint64_t release); |
85 void DestroyImage(int32_t id) override; | 76 bool IsFenceSyncFlushReceived(uint64_t release); |
86 int32_t CreateGpuMemoryBufferImage(size_t width, | |
87 size_t height, | |
88 unsigned internalformat, | |
89 unsigned usage) override; | |
90 void SignalQuery(uint32_t query, const base::Closure& callback) override; | |
91 void SetLock(base::Lock*) override; | |
92 bool IsGpuChannelLost() override; | |
93 void EnsureWorkVisible() override; | |
94 gpu::CommandBufferNamespace GetNamespaceID() const override; | |
95 uint64_t GetCommandBufferID() const override; | |
96 int32_t GetExtraCommandBufferData() const override; | |
97 uint64_t GenerateFenceSyncRelease() override; | |
98 bool IsFenceSyncRelease(uint64_t release) override; | |
99 bool IsFenceSyncFlushed(uint64_t release) override; | |
100 bool IsFenceSyncFlushReceived(uint64_t release) override; | |
101 void SignalSyncToken(const gpu::SyncToken& sync_token, | |
102 const base::Closure& callback) override; | |
103 bool CanWaitUnverifiedSyncToken(const gpu::SyncToken* sync_token) override; | |
104 | 77 |
105 private: | 78 private: |
106 EGLNativeDisplayType display_id_; | 79 void InitializeConfigsIfNeeded(); |
| 80 const Config* GetConfig(EGLConfig); |
| 81 Surface* GetSurface(EGLSurface); |
| 82 Context* GetContext(EGLContext); |
107 | 83 |
| 84 base::Lock lock_; |
108 bool is_initialized_; | 85 bool is_initialized_; |
109 | |
110 bool create_offscreen_; | |
111 int create_offscreen_width_; | |
112 int create_offscreen_height_; | |
113 uint64_t next_fence_sync_release_; | 86 uint64_t next_fence_sync_release_; |
114 | 87 std::vector<scoped_refptr<Surface>> surfaces_; |
115 scoped_refptr<gpu::TransferBufferManagerInterface> transfer_buffer_manager_; | 88 std::vector<scoped_refptr<Context>> contexts_; |
116 scoped_ptr<gpu::CommandBufferService> command_buffer_; | 89 Config* configs_[2]; |
117 scoped_ptr<gpu::GpuScheduler> gpu_scheduler_; | |
118 scoped_ptr<gpu::gles2::GLES2Decoder> decoder_; | |
119 scoped_refptr<gfx::GLContext> gl_context_; | |
120 scoped_refptr<gfx::GLSurface> gl_surface_; | |
121 scoped_ptr<gpu::gles2::GLES2CmdHelper> gles2_cmd_helper_; | |
122 scoped_ptr<gpu::TransferBuffer> transfer_buffer_; | |
123 | |
124 // TODO(alokp): Support more than one config, surface, and context. | |
125 scoped_ptr<Config> config_; | |
126 scoped_ptr<Surface> surface_; | |
127 scoped_ptr<gpu::gles2::GLES2Implementation> context_; | |
128 | 90 |
129 DISALLOW_COPY_AND_ASSIGN(Display); | 91 DISALLOW_COPY_AND_ASSIGN(Display); |
130 }; | 92 }; |
131 | 93 |
132 } // namespace egl | 94 } // namespace egl |
133 | 95 |
134 #endif // GPU_GLES2_CONFORM_SUPPORT_EGL_DISPLAY_H_ | 96 #endif // GPU_GLES2_CONFORM_SUPPORT_EGL_DISPLAY_H_ |
OLD | NEW |