| 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 UI_GL_GL_CONTEXT_H_ | 5 #ifndef UI_GL_GL_CONTEXT_H_ |
| 6 #define UI_GL_GL_CONTEXT_H_ | 6 #define UI_GL_GL_CONTEXT_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 // Notify this context that |virtual_context|, that was using us, is | 120 // Notify this context that |virtual_context|, that was using us, is |
| 121 // being released or destroyed. | 121 // being released or destroyed. |
| 122 void OnReleaseVirtuallyCurrent(GLContext* virtual_context); | 122 void OnReleaseVirtuallyCurrent(GLContext* virtual_context); |
| 123 | 123 |
| 124 // Returns the GL version string. The context must be current. | 124 // Returns the GL version string. The context must be current. |
| 125 virtual std::string GetGLVersion(); | 125 virtual std::string GetGLVersion(); |
| 126 | 126 |
| 127 // Returns the GL renderer string. The context must be current. | 127 // Returns the GL renderer string. The context must be current. |
| 128 virtual std::string GetGLRenderer(); | 128 virtual std::string GetGLRenderer(); |
| 129 | 129 |
| 130 // Return a callback that, when called, indicates that the state the | |
| 131 // underlying context has been changed by code outside of the command buffer, | |
| 132 // and will need to be restored. | |
| 133 virtual base::Closure GetStateWasDirtiedExternallyCallback(); | |
| 134 | |
| 135 // Restore the context's state if it was dirtied by an external caller. | |
| 136 virtual void RestoreStateIfDirtiedExternally(); | |
| 137 | |
| 138 protected: | 130 protected: |
| 139 virtual ~GLContext(); | 131 virtual ~GLContext(); |
| 140 | 132 |
| 141 // Will release the current context when going out of scope, unless canceled. | 133 // Will release the current context when going out of scope, unless canceled. |
| 142 class ScopedReleaseCurrent { | 134 class ScopedReleaseCurrent { |
| 143 public: | 135 public: |
| 144 ScopedReleaseCurrent(); | 136 ScopedReleaseCurrent(); |
| 145 ~ScopedReleaseCurrent(); | 137 ~ScopedReleaseCurrent(); |
| 146 | 138 |
| 147 void Cancel(); | 139 void Cancel(); |
| 148 | 140 |
| 149 private: | 141 private: |
| 150 bool canceled_; | 142 bool canceled_; |
| 151 }; | 143 }; |
| 152 | 144 |
| 153 // Sets the GL api to the real hardware API (vs the VirtualAPI) | 145 // Sets the GL api to the real hardware API (vs the VirtualAPI) |
| 154 static void SetRealGLApi(); | 146 static void SetRealGLApi(); |
| 155 virtual void SetCurrent(GLSurface* surface); | 147 virtual void SetCurrent(GLSurface* surface); |
| 156 | 148 |
| 157 // Initialize function pointers to functions where the bound version depends | 149 // Initialize function pointers to functions where the bound version depends |
| 158 // on GL version or supported extensions. Should be called immediately after | 150 // on GL version or supported extensions. Should be called immediately after |
| 159 // this context is made current. | 151 // this context is made current. |
| 160 bool InitializeDynamicBindings(); | 152 bool InitializeDynamicBindings(); |
| 161 | 153 |
| 162 // Returns the last real (non-virtual) GLContext made current. | 154 // Returns the last real (non-virtual) GLContext made current. |
| 163 static GLContext* GetRealCurrent(); | 155 static GLContext* GetRealCurrent(); |
| 164 | 156 |
| 165 virtual void OnSetSwapInterval(int interval) = 0; | 157 virtual void OnSetSwapInterval(int interval) = 0; |
| 166 | 158 |
| 167 bool GetStateWasDirtiedExternally() const; | |
| 168 void SetStateWasDirtiedExternally(bool dirtied_externally); | |
| 169 | |
| 170 private: | 159 private: |
| 171 friend class base::RefCounted<GLContext>; | 160 friend class base::RefCounted<GLContext>; |
| 172 | 161 |
| 173 // For GetRealCurrent. | 162 // For GetRealCurrent. |
| 174 friend class VirtualGLApi; | 163 friend class VirtualGLApi; |
| 175 friend class gpu::GLContextVirtual; | 164 friend class gpu::GLContextVirtual; |
| 176 | 165 |
| 177 scoped_refptr<GLShareGroup> share_group_; | 166 scoped_refptr<GLShareGroup> share_group_; |
| 178 scoped_ptr<VirtualGLApi> virtual_gl_api_; | 167 scoped_ptr<VirtualGLApi> virtual_gl_api_; |
| 179 bool state_dirtied_externally_; | 168 bool state_dirtied_externally_; |
| 180 scoped_ptr<GLStateRestorer> state_restorer_; | 169 scoped_ptr<GLStateRestorer> state_restorer_; |
| 181 scoped_ptr<GLVersionInfo> version_info_; | 170 scoped_ptr<GLVersionInfo> version_info_; |
| 182 | 171 |
| 183 int swap_interval_; | 172 int swap_interval_; |
| 184 bool force_swap_interval_zero_; | 173 bool force_swap_interval_zero_; |
| 185 | 174 |
| 186 base::CancelableCallback<void()> state_dirtied_callback_; | |
| 187 | |
| 188 DISALLOW_COPY_AND_ASSIGN(GLContext); | 175 DISALLOW_COPY_AND_ASSIGN(GLContext); |
| 189 }; | 176 }; |
| 190 | 177 |
| 191 class GL_EXPORT GLContextReal : public GLContext { | 178 class GL_EXPORT GLContextReal : public GLContext { |
| 192 public: | 179 public: |
| 193 explicit GLContextReal(GLShareGroup* share_group); | 180 explicit GLContextReal(GLShareGroup* share_group); |
| 194 scoped_refptr<gfx::GPUTimingClient> CreateGPUTimingClient() override; | 181 scoped_refptr<gfx::GPUTimingClient> CreateGPUTimingClient() override; |
| 195 | 182 |
| 196 protected: | 183 protected: |
| 197 ~GLContextReal() override; | 184 ~GLContextReal() override; |
| 198 | 185 |
| 199 void SetCurrent(GLSurface* surface) override; | 186 void SetCurrent(GLSurface* surface) override; |
| 200 | 187 |
| 201 private: | 188 private: |
| 202 scoped_ptr<gfx::GPUTiming> gpu_timing_; | 189 scoped_ptr<gfx::GPUTiming> gpu_timing_; |
| 203 DISALLOW_COPY_AND_ASSIGN(GLContextReal); | 190 DISALLOW_COPY_AND_ASSIGN(GLContextReal); |
| 204 }; | 191 }; |
| 205 | 192 |
| 206 } // namespace gfx | 193 } // namespace gfx |
| 207 | 194 |
| 208 #endif // UI_GL_GL_CONTEXT_H_ | 195 #endif // UI_GL_GL_CONTEXT_H_ |
| OLD | NEW |