OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_TEST_CONTEXT_H_ |
6 #define GPU_GLES2_CONFORM_SUPPORT_EGL_DISPLAY_H_ | 6 #define GPU_GLES2_CONFORM_TEST_CONTEXT_H_ |
7 | |
8 #include <EGL/egl.h> | |
9 #include <stddef.h> | |
10 #include <stdint.h> | |
11 | 7 |
12 #include "base/macros.h" | 8 #include "base/macros.h" |
13 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/ref_counted.h" |
14 #include "gpu/command_buffer/client/gles2_cmd_helper.h" | 10 #include "gpu/command_buffer/client/gles2_cmd_helper.h" |
15 #include "gpu/command_buffer/client/gpu_control.h" | 11 #include "gpu/command_buffer/client/gpu_control.h" |
16 #include "gpu/command_buffer/service/command_buffer_service.h" | 12 #include "gpu/command_buffer/service/command_buffer_service.h" |
17 #include "gpu/command_buffer/service/command_executor.h" | 13 #include "gpu/command_buffer/service/command_executor.h" |
18 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 14 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
19 #include "gpu/command_buffer/service/gpu_preferences.h" | 15 #include "gpu/command_buffer/service/gpu_preferences.h" |
20 #include "ui/gfx/native_widget_types.h" | 16 #include "ui/gfx/native_widget_types.h" |
21 #include "ui/gl/gl_context.h" | 17 #include "ui/gl/gl_context.h" |
| 18 #include "ui/gl/gl_context.h" |
22 #include "ui/gl/gl_surface.h" | 19 #include "ui/gl/gl_surface.h" |
| 20 #include "ui/gl/gl_surface.h" |
| 21 #include <EGL/egl.h> |
23 | 22 |
24 namespace gpu { | 23 namespace gpu { |
25 class CommandBufferService; | |
26 class GpuControl; | |
27 class CommandExecutor; | |
28 class TransferBuffer; | 24 class TransferBuffer; |
29 class TransferBufferManagerInterface; | 25 class TransferBufferManagerInterface; |
30 | 26 |
31 namespace gles2 { | 27 namespace gles2 { |
32 class GLES2CmdHelper; | 28 class GLES2CmdHelper; |
33 class GLES2Implementation; | 29 class GLES2Interface; |
34 } // namespace gles2 | 30 } // namespace gles2 |
35 } // namespace gpu | 31 } // namespace gpu |
36 | 32 |
37 namespace egl { | 33 namespace egl { |
| 34 class Display; |
| 35 class Surface; |
| 36 class Config; |
38 | 37 |
39 class Config; | 38 class Context : public base::RefCountedThreadSafe<Context>, |
40 class Surface; | 39 private gpu::GpuControl { |
| 40 public: |
| 41 Context(Display* display, const Config* config); |
| 42 bool is_current_in_some_thread() const { return is_current_in_some_thread_; } |
| 43 void set_is_current_in_some_thread(bool flag) { |
| 44 is_current_in_some_thread_ = flag; |
| 45 } |
| 46 void MarkDestroyed(); |
| 47 void FlushAndSwapBuffers(gfx::GLSurface* current_surface); |
41 | 48 |
42 class Display : private gpu::GpuControl { | 49 static bool MakeCurrent(Context* current_context, |
43 public: | 50 gfx::GLSurface* current_surface, |
44 explicit Display(EGLNativeDisplayType display_id); | 51 Context* new_context, |
45 ~Display() override; | 52 gfx::GLSurface* new_surface); |
46 | 53 |
47 void SetCreateOffscreen(int width, int height) { | 54 static bool ValidateAttributeList(const EGLint* attrib_list); |
48 create_offscreen_ = true; | |
49 create_offscreen_width_ = width; | |
50 create_offscreen_height_ = height; | |
51 } | |
52 | |
53 bool is_initialized() const { return is_initialized_; } | |
54 bool Initialize(); | |
55 | |
56 // Config routines. | |
57 bool IsValidConfig(EGLConfig config); | |
58 bool ChooseConfigs( | |
59 EGLConfig* configs, EGLint config_size, EGLint* num_config); | |
60 bool GetConfigs(EGLConfig* configs, EGLint config_size, EGLint* num_config); | |
61 bool GetConfigAttrib(EGLConfig config, EGLint attribute, EGLint* value); | |
62 | |
63 // Surface routines. | |
64 bool IsValidNativeWindow(EGLNativeWindowType win); | |
65 bool IsValidSurface(EGLSurface surface); | |
66 EGLSurface CreateWindowSurface(EGLConfig config, | |
67 EGLNativeWindowType win, | |
68 const EGLint* attrib_list); | |
69 void DestroySurface(EGLSurface surface); | |
70 void SwapBuffers(EGLSurface surface); | |
71 | |
72 // Context routines. | |
73 bool IsValidContext(EGLContext ctx); | |
74 EGLContext CreateContext(EGLConfig config, | |
75 EGLContext share_ctx, | |
76 const EGLint* attrib_list); | |
77 void DestroyContext(EGLContext ctx); | |
78 bool MakeCurrent(EGLSurface draw, EGLSurface read, EGLContext ctx); | |
79 | 55 |
80 // GpuControl implementation. | 56 // GpuControl implementation. |
81 gpu::Capabilities GetCapabilities() override; | 57 gpu::Capabilities GetCapabilities() override; |
82 int32_t CreateImage(ClientBuffer buffer, | 58 int32_t CreateImage(ClientBuffer buffer, |
83 size_t width, | 59 size_t width, |
84 size_t height, | 60 size_t height, |
85 unsigned internalformat) override; | 61 unsigned internalformat) override; |
86 void DestroyImage(int32_t id) override; | 62 void DestroyImage(int32_t id) override; |
87 int32_t CreateGpuMemoryBufferImage(size_t width, | 63 int32_t CreateGpuMemoryBufferImage(size_t width, |
88 size_t height, | 64 size_t height, |
89 unsigned internalformat, | 65 unsigned internalformat, |
90 unsigned usage) override; | 66 unsigned usage) override; |
91 void SignalQuery(uint32_t query, const base::Closure& callback) override; | 67 void SignalQuery(uint32_t query, const base::Closure& callback) override; |
92 void SetLock(base::Lock*) override; | 68 void SetLock(base::Lock*) override; |
93 bool IsGpuChannelLost() override; | 69 bool IsGpuChannelLost() override; |
94 void EnsureWorkVisible() override; | 70 void EnsureWorkVisible() override; |
95 gpu::CommandBufferNamespace GetNamespaceID() const override; | 71 gpu::CommandBufferNamespace GetNamespaceID() const override; |
96 gpu::CommandBufferId GetCommandBufferID() const override; | 72 gpu::CommandBufferId GetCommandBufferID() const override; |
97 int32_t GetExtraCommandBufferData() const override; | 73 int32_t GetExtraCommandBufferData() const override; |
98 uint64_t GenerateFenceSyncRelease() override; | 74 uint64_t GenerateFenceSyncRelease() override; |
99 bool IsFenceSyncRelease(uint64_t release) override; | 75 bool IsFenceSyncRelease(uint64_t release) override; |
100 bool IsFenceSyncFlushed(uint64_t release) override; | 76 bool IsFenceSyncFlushed(uint64_t release) override; |
101 bool IsFenceSyncFlushReceived(uint64_t release) override; | 77 bool IsFenceSyncFlushReceived(uint64_t release) override; |
102 void SignalSyncToken(const gpu::SyncToken& sync_token, | 78 void SignalSyncToken(const gpu::SyncToken& sync_token, |
103 const base::Closure& callback) override; | 79 const base::Closure& callback) override; |
104 bool CanWaitUnverifiedSyncToken(const gpu::SyncToken* sync_token) override; | 80 bool CanWaitUnverifiedSyncToken(const gpu::SyncToken* sync_token) override; |
105 | 81 |
| 82 // Called by ThreadState to set the needed global variables when this context |
| 83 // is current. |
| 84 void ApplyCurrentContext(gfx::GLSurface* current_surface); |
| 85 static void ApplyContextReleased(); |
| 86 |
106 private: | 87 private: |
107 EGLNativeDisplayType display_id_; | 88 friend class base::RefCountedThreadSafe<Context>; |
| 89 ~Context() override; |
| 90 bool CreateService(gfx::GLSurface* gl_surface); |
| 91 void DestroyService(); |
| 92 // Returns true if the object has GL service, either a working one or one |
| 93 // that has lost its GL context. |
| 94 bool HasService() const; |
| 95 void MarkServiceContextLost(); |
| 96 bool WasServiceContextLost() const; |
| 97 bool IsCompatibleSurface(gfx::GLSurface* gl_surface); |
| 98 bool Flush(gfx::GLSurface* gl_surface); |
108 | 99 |
| 100 Display* display_; |
| 101 const Config* config_; |
| 102 bool is_current_in_some_thread_; |
| 103 bool is_destroyed_; |
109 gpu::GpuPreferences gpu_preferences_; | 104 gpu::GpuPreferences gpu_preferences_; |
110 bool is_initialized_; | |
111 | |
112 bool create_offscreen_; | |
113 int create_offscreen_width_; | |
114 int create_offscreen_height_; | |
115 uint64_t next_fence_sync_release_; | |
116 | |
117 scoped_refptr<gpu::TransferBufferManagerInterface> transfer_buffer_manager_; | |
118 scoped_ptr<gpu::CommandBufferService> command_buffer_; | 105 scoped_ptr<gpu::CommandBufferService> command_buffer_; |
119 scoped_ptr<gpu::CommandExecutor> executor_; | 106 scoped_ptr<gpu::gles2::GLES2CmdHelper> gles2_cmd_helper_; |
120 scoped_ptr<gpu::gles2::GLES2Decoder> decoder_; | 107 scoped_ptr<gpu::gles2::GLES2Decoder> decoder_; |
121 scoped_refptr<gfx::GLContext> gl_context_; | 108 scoped_ptr<gpu::CommandExecutor> command_executor_; |
122 scoped_refptr<gfx::GLSurface> gl_surface_; | |
123 scoped_ptr<gpu::gles2::GLES2CmdHelper> gles2_cmd_helper_; | |
124 scoped_ptr<gpu::TransferBuffer> transfer_buffer_; | 109 scoped_ptr<gpu::TransferBuffer> transfer_buffer_; |
125 | 110 |
126 // TODO(alokp): Support more than one config, surface, and context. | 111 scoped_refptr<gfx::GLContext> gl_context_; |
127 scoped_ptr<Config> config_; | |
128 scoped_ptr<Surface> surface_; | |
129 scoped_ptr<gpu::gles2::GLES2Implementation> context_; | |
130 | 112 |
131 DISALLOW_COPY_AND_ASSIGN(Display); | 113 scoped_ptr<gpu::gles2::GLES2Interface> client_gl_context_; |
| 114 DISALLOW_COPY_AND_ASSIGN(Context); |
132 }; | 115 }; |
133 | 116 |
134 } // namespace egl | 117 } // namespace egl |
135 | 118 |
136 #endif // GPU_GLES2_CONFORM_SUPPORT_EGL_DISPLAY_H_ | 119 #endif // GPU_GLES2_CONFORM_TEST_CONTEXT_H_ |
OLD | NEW |