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> | 12 #include "base/macros.h" |
| 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "gpu/command_buffer/client/gles2_cmd_helper.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" |
13 | 22 |
14 #include "base/macros.h" | 23 namespace gpu { |
15 #include "base/memory/ref_counted.h" | 24 class CommandBufferService; |
16 #include "base/memory/scoped_ptr.h" | 25 class GpuControl; |
17 #include "base/synchronization/lock.h" | 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 |
18 | 35 |
19 namespace egl { | 36 namespace egl { |
20 | 37 |
21 class Config; | 38 class Config; |
22 class Context; | |
23 class Surface; | 39 class Surface; |
24 class ThreadState; | |
25 | 40 |
26 class Display { | 41 class Display : private gpu::GpuControl { |
27 public: | 42 public: |
28 explicit Display(); | 43 explicit Display(EGLNativeDisplayType display_id); |
29 ~Display(); | 44 ~Display() override; |
| 45 |
| 46 void SetCreateOffscreen(int width, int height) { |
| 47 create_offscreen_ = true; |
| 48 create_offscreen_width_ = width; |
| 49 create_offscreen_height_ = height; |
| 50 } |
30 | 51 |
31 bool is_initialized() const { return is_initialized_; } | 52 bool is_initialized() const { return is_initialized_; } |
32 | 53 bool Initialize(); |
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); | |
38 | 54 |
39 // Config routines. | 55 // Config routines. |
40 EGLBoolean GetConfigAttrib(ThreadState* ts, | 56 bool IsValidConfig(EGLConfig config); |
41 EGLConfig cfg, | 57 bool ChooseConfigs( |
42 EGLint attribute, | 58 EGLConfig* configs, EGLint config_size, EGLint* num_config); |
43 EGLint* value); | 59 bool GetConfigs(EGLConfig* configs, EGLint config_size, EGLint* num_config); |
44 EGLBoolean ChooseConfig(ThreadState* ts, | 60 bool GetConfigAttrib(EGLConfig config, EGLint attribute, EGLint* value); |
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); | |
53 | 61 |
54 // Surface routines. | 62 // Surface routines. |
55 static bool IsValidNativeWindow(EGLNativeWindowType); | 63 bool IsValidNativeWindow(EGLNativeWindowType win); |
56 EGLSurface CreatePbufferSurface(ThreadState*, | 64 bool IsValidSurface(EGLSurface surface); |
57 EGLConfig, | 65 EGLSurface CreateWindowSurface(EGLConfig config, |
58 const EGLint* attrib_list); | |
59 EGLSurface CreateWindowSurface(ThreadState*, | |
60 EGLConfig, | |
61 EGLNativeWindowType win, | 66 EGLNativeWindowType win, |
62 const EGLint* attrib_list); | 67 const EGLint* attrib_list); |
63 EGLBoolean DestroySurface(ThreadState*, EGLSurface); | 68 void DestroySurface(EGLSurface surface); |
64 EGLBoolean SwapBuffers(ThreadState*, EGLSurface); | 69 void SwapBuffers(EGLSurface surface); |
65 | 70 |
66 // Context routines. | 71 // Context routines. |
67 EGLContext CreateContext(ThreadState*, | 72 bool IsValidContext(EGLContext ctx); |
68 EGLConfig, | 73 EGLContext CreateContext(EGLConfig config, |
69 EGLSurface share_ctx, | 74 EGLContext share_ctx, |
70 const EGLint* attrib_list); | 75 const EGLint* attrib_list); |
71 EGLBoolean DestroyContext(ThreadState*, EGLContext); | 76 void DestroyContext(EGLContext ctx); |
| 77 bool MakeCurrent(EGLSurface draw, EGLSurface read, EGLContext ctx); |
72 | 78 |
73 EGLBoolean ReleaseCurrent(ThreadState*); | 79 // GpuControl implementation. |
74 EGLBoolean MakeCurrent(ThreadState*, EGLSurface, EGLSurface, EGLContext); | 80 gpu::Capabilities GetCapabilities() override; |
75 | 81 int32_t CreateImage(ClientBuffer buffer, |
76 uint64_t GenerateFenceSyncRelease(); | 82 size_t width, |
77 bool IsFenceSyncRelease(uint64_t release); | 83 size_t height, |
78 bool IsFenceSyncFlushed(uint64_t release); | 84 unsigned internalformat) override; |
79 bool IsFenceSyncFlushReceived(uint64_t release); | 85 void DestroyImage(int32_t id) override; |
| 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; |
80 | 104 |
81 private: | 105 private: |
82 void InitializeConfigsIfNeeded(); | 106 EGLNativeDisplayType display_id_; |
83 const Config* GetConfig(EGLConfig); | |
84 Surface* GetSurface(EGLSurface); | |
85 Context* GetContext(EGLContext); | |
86 | 107 |
87 base::Lock lock_; | |
88 bool is_initialized_; | 108 bool is_initialized_; |
| 109 |
| 110 bool create_offscreen_; |
| 111 int create_offscreen_width_; |
| 112 int create_offscreen_height_; |
89 uint64_t next_fence_sync_release_; | 113 uint64_t next_fence_sync_release_; |
90 std::vector<scoped_refptr<Surface>> surfaces_; | 114 |
91 std::vector<scoped_refptr<Context>> contexts_; | 115 scoped_refptr<gpu::TransferBufferManagerInterface> transfer_buffer_manager_; |
92 scoped_ptr<Config> configs_[2]; | 116 scoped_ptr<gpu::CommandBufferService> command_buffer_; |
| 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_; |
93 | 128 |
94 DISALLOW_COPY_AND_ASSIGN(Display); | 129 DISALLOW_COPY_AND_ASSIGN(Display); |
95 }; | 130 }; |
96 | 131 |
97 } // namespace egl | 132 } // namespace egl |
98 | 133 |
99 #endif // GPU_GLES2_CONFORM_SUPPORT_EGL_DISPLAY_H_ | 134 #endif // GPU_GLES2_CONFORM_SUPPORT_EGL_DISPLAY_H_ |
OLD | NEW |