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 |
| 33 void ReleaseCurrentForReleaseThread(ThreadState*); |
| 34 |
| 35 EGLBoolean Initialize(ThreadState* ts, EGLint* major, EGLint* minor); |
| 36 EGLBoolean Terminate(ThreadState* ts); |
| 37 const char* QueryString(ThreadState* ts, EGLint name); |
54 | 38 |
55 // Config routines. | 39 // Config routines. |
56 bool IsValidConfig(EGLConfig config); | 40 EGLBoolean GetConfigAttrib(ThreadState* ts, |
57 bool ChooseConfigs( | 41 EGLConfig cfg, |
58 EGLConfig* configs, EGLint config_size, EGLint* num_config); | 42 EGLint attribute, |
59 bool GetConfigs(EGLConfig* configs, EGLint config_size, EGLint* num_config); | 43 EGLint* value); |
60 bool GetConfigAttrib(EGLConfig config, EGLint attribute, EGLint* value); | 44 EGLBoolean ChooseConfig(ThreadState* ts, |
| 45 const EGLint* attrib_list, |
| 46 EGLConfig* configs, |
| 47 EGLint config_size, |
| 48 EGLint* num_config); |
| 49 EGLBoolean GetConfigs(ThreadState*, |
| 50 EGLConfig*, |
| 51 EGLint config_size, |
| 52 EGLint* num_config); |
61 | 53 |
62 // Surface routines. | 54 // Surface routines. |
63 bool IsValidNativeWindow(EGLNativeWindowType win); | 55 static bool IsValidNativeWindow(EGLNativeWindowType); |
64 bool IsValidSurface(EGLSurface surface); | 56 EGLSurface CreatePbufferSurface(ThreadState*, |
65 EGLSurface CreateWindowSurface(EGLConfig config, | 57 EGLConfig, |
| 58 const EGLint* attrib_list); |
| 59 EGLSurface CreateWindowSurface(ThreadState*, |
| 60 EGLConfig, |
66 EGLNativeWindowType win, | 61 EGLNativeWindowType win, |
67 const EGLint* attrib_list); | 62 const EGLint* attrib_list); |
68 void DestroySurface(EGLSurface surface); | 63 EGLBoolean DestroySurface(ThreadState*, EGLSurface); |
69 void SwapBuffers(EGLSurface surface); | 64 EGLBoolean SwapBuffers(ThreadState*, EGLSurface); |
70 | 65 |
71 // Context routines. | 66 // Context routines. |
72 bool IsValidContext(EGLContext ctx); | 67 EGLContext CreateContext(ThreadState*, |
73 EGLContext CreateContext(EGLConfig config, | 68 EGLConfig, |
74 EGLContext share_ctx, | 69 EGLSurface share_ctx, |
75 const EGLint* attrib_list); | 70 const EGLint* attrib_list); |
76 void DestroyContext(EGLContext ctx); | 71 EGLBoolean DestroyContext(ThreadState*, EGLContext); |
77 bool MakeCurrent(EGLSurface draw, EGLSurface read, EGLContext ctx); | |
78 | 72 |
79 // GpuControl implementation. | 73 EGLBoolean ReleaseCurrent(ThreadState*); |
80 gpu::Capabilities GetCapabilities() override; | 74 EGLBoolean MakeCurrent(ThreadState*, EGLSurface, EGLSurface, EGLContext); |
81 int32_t CreateImage(ClientBuffer buffer, | 75 |
82 size_t width, | 76 uint64_t GenerateFenceSyncRelease(); |
83 size_t height, | 77 bool IsFenceSyncRelease(uint64_t release); |
84 unsigned internalformat) override; | 78 bool IsFenceSyncFlushed(uint64_t release); |
85 void DestroyImage(int32_t id) override; | 79 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 gpu::CommandBufferId 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 | 80 |
105 private: | 81 private: |
106 EGLNativeDisplayType display_id_; | 82 void InitializeConfigsIfNeeded(); |
| 83 const Config* GetConfig(EGLConfig); |
| 84 Surface* GetSurface(EGLSurface); |
| 85 Context* GetContext(EGLContext); |
107 | 86 |
| 87 base::Lock lock_; |
108 bool is_initialized_; | 88 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_; | 89 uint64_t next_fence_sync_release_; |
114 | 90 std::vector<scoped_refptr<Surface>> surfaces_; |
115 scoped_refptr<gpu::TransferBufferManagerInterface> transfer_buffer_manager_; | 91 std::vector<scoped_refptr<Context>> contexts_; |
116 scoped_ptr<gpu::CommandBufferService> command_buffer_; | 92 scoped_ptr<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 | 93 |
129 DISALLOW_COPY_AND_ASSIGN(Display); | 94 DISALLOW_COPY_AND_ASSIGN(Display); |
130 }; | 95 }; |
131 | 96 |
132 } // namespace egl | 97 } // namespace egl |
133 | 98 |
134 #endif // GPU_GLES2_CONFORM_SUPPORT_EGL_DISPLAY_H_ | 99 #endif // GPU_GLES2_CONFORM_SUPPORT_EGL_DISPLAY_H_ |
OLD | NEW |