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