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