Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc

Issue 470973002: gpu: Remove WebGraphicsContext3D::makeContextCurrent() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: build fix in unittests Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl. h" 5 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl. h"
6 6
7 #include <GLES2/gl2.h> 7 #include <GLES2/gl2.h>
8 #ifndef GL_GLEXT_PROTOTYPES 8 #ifndef GL_GLEXT_PROTOTYPES
9 #define GL_GLEXT_PROTOTYPES 1 9 #define GL_GLEXT_PROTOTYPES 1
10 #endif 10 #endif
11 #include <GLES2/gl2ext.h> 11 #include <GLES2/gl2ext.h>
12 #include <GLES2/gl2extchromium.h> 12 #include <GLES2/gl2extchromium.h>
13 13
14 #include <string> 14 #include <string>
15 15
16 #include "base/atomicops.h" 16 #include "base/atomicops.h"
17 #include "base/bind.h" 17 #include "base/bind.h"
18 #include "base/bind_helpers.h" 18 #include "base/bind_helpers.h"
19 #include "base/callback.h" 19 #include "base/callback.h"
20 #include "base/lazy_instance.h"
21 #include "base/logging.h" 20 #include "base/logging.h"
22 #include "gpu/command_buffer/client/gles2_implementation.h" 21 #include "gpu/command_buffer/client/gles2_implementation.h"
23 #include "gpu/command_buffer/client/gles2_lib.h"
24 #include "gpu/command_buffer/common/gles2_cmd_utils.h" 22 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
25 #include "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h" 23 #include "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h"
26 #include "ui/gfx/size.h" 24 #include "ui/gfx/size.h"
27 #include "ui/gl/gl_implementation.h" 25 #include "ui/gl/gl_implementation.h"
28 26
29 using gpu::gles2::GLES2Implementation; 27 using gpu::gles2::GLES2Implementation;
30 using gpu::GLInProcessContext; 28 using gpu::GLInProcessContext;
31 29
32 namespace webkit { 30 namespace webkit {
33 namespace gpu { 31 namespace gpu {
34 32
35 namespace {
36
37 // Singleton used to initialize and terminate the gles2 library.
38 class GLES2Initializer {
39 public:
40 GLES2Initializer() {
41 ::gles2::Initialize();
42 }
43
44 ~GLES2Initializer() {
45 ::gles2::Terminate();
46 }
47
48 private:
49 DISALLOW_COPY_AND_ASSIGN(GLES2Initializer);
50 };
51
52 static base::LazyInstance<GLES2Initializer> g_gles2_initializer =
53 LAZY_INSTANCE_INITIALIZER;
54
55 } // namespace anonymous
56
57 // static 33 // static
58 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> 34 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>
59 WebGraphicsContext3DInProcessCommandBufferImpl::CreateViewContext( 35 WebGraphicsContext3DInProcessCommandBufferImpl::CreateViewContext(
60 const blink::WebGraphicsContext3D::Attributes& attributes, 36 const blink::WebGraphicsContext3D::Attributes& attributes,
61 bool lose_context_when_out_of_memory, 37 bool lose_context_when_out_of_memory,
62 gfx::AcceleratedWidget window) { 38 gfx::AcceleratedWidget window) {
63 DCHECK_NE(gfx::GetGLImplementation(), gfx::kGLImplementationNone); 39 DCHECK_NE(gfx::GetGLImplementation(), gfx::kGLImplementationNone);
64 bool is_offscreen = false; 40 bool is_offscreen = false;
65 return make_scoped_ptr(new WebGraphicsContext3DInProcessCommandBufferImpl( 41 return make_scoped_ptr(new WebGraphicsContext3DInProcessCommandBufferImpl(
66 scoped_ptr< ::gpu::GLInProcessContext>(), 42 scoped_ptr< ::gpu::GLInProcessContext>(),
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 return context_->GetMappedMemoryLimit(); 98 return context_->GetMappedMemoryLimit();
123 } 99 }
124 100
125 bool WebGraphicsContext3DInProcessCommandBufferImpl::MaybeInitializeGL() { 101 bool WebGraphicsContext3DInProcessCommandBufferImpl::MaybeInitializeGL() {
126 if (initialized_) 102 if (initialized_)
127 return true; 103 return true;
128 104
129 if (initialize_failed_) 105 if (initialize_failed_)
130 return false; 106 return false;
131 107
132 // Ensure the gles2 library is initialized first in a thread safe way.
133 g_gles2_initializer.Get();
134
135 if (!context_) { 108 if (!context_) {
136 // TODO(kbr): More work will be needed in this implementation to 109 // TODO(kbr): More work will be needed in this implementation to
137 // properly support GPU switching. Like in the out-of-process 110 // properly support GPU switching. Like in the out-of-process
138 // command buffer implementation, all previously created contexts 111 // command buffer implementation, all previously created contexts
139 // will need to be lost either when the first context requesting the 112 // will need to be lost either when the first context requesting the
140 // discrete GPU is created, or the last one is destroyed. 113 // discrete GPU is created, or the last one is destroyed.
141 gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; 114 gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu;
142 context_.reset(GLInProcessContext::Create( 115 context_.reset(GLInProcessContext::Create(
143 NULL, /* service */ 116 NULL, /* service */
144 NULL, /* surface */ 117 NULL, /* surface */
(...skipping 20 matching lines...) Expand all
165 real_gl_ = context_->GetImplementation(); 138 real_gl_ = context_->GetImplementation();
166 setGLInterface(real_gl_); 139 setGLInterface(real_gl_);
167 140
168 if (real_gl_ && webgl_context_) 141 if (real_gl_ && webgl_context_)
169 real_gl_->EnableFeatureCHROMIUM("webgl_enable_glsl_webgl_validation"); 142 real_gl_->EnableFeatureCHROMIUM("webgl_enable_glsl_webgl_validation");
170 143
171 initialized_ = true; 144 initialized_ = true;
172 return true; 145 return true;
173 } 146 }
174 147
175 bool WebGraphicsContext3DInProcessCommandBufferImpl::makeContextCurrent() { 148 bool
149 WebGraphicsContext3DInProcessCommandBufferImpl::InitializeOnCurrentThread() {
176 if (!MaybeInitializeGL()) 150 if (!MaybeInitializeGL())
177 return false; 151 return false;
178 ::gles2::SetGLContext(GetGLInterface());
179 return context_ && !isContextLost(); 152 return context_ && !isContextLost();
180 } 153 }
181 154
182 bool WebGraphicsContext3DInProcessCommandBufferImpl::isContextLost() { 155 bool WebGraphicsContext3DInProcessCommandBufferImpl::isContextLost() {
183 return context_lost_reason_ != GL_NO_ERROR; 156 return context_lost_reason_ != GL_NO_ERROR;
184 } 157 }
185 158
186 WGC3Denum WebGraphicsContext3DInProcessCommandBufferImpl:: 159 WGC3Denum WebGraphicsContext3DInProcessCommandBufferImpl::
187 getGraphicsResetStatusARB() { 160 getGraphicsResetStatusARB() {
188 return context_lost_reason_; 161 return context_lost_reason_;
189 } 162 }
190 163
191 ::gpu::ContextSupport* 164 ::gpu::ContextSupport*
192 WebGraphicsContext3DInProcessCommandBufferImpl::GetContextSupport() { 165 WebGraphicsContext3DInProcessCommandBufferImpl::GetContextSupport() {
193 return real_gl_; 166 return real_gl_;
194 } 167 }
195 168
196 void WebGraphicsContext3DInProcessCommandBufferImpl::OnContextLost() { 169 void WebGraphicsContext3DInProcessCommandBufferImpl::OnContextLost() {
197 // TODO(kbr): improve the precision here. 170 // TODO(kbr): improve the precision here.
198 context_lost_reason_ = GL_UNKNOWN_CONTEXT_RESET_ARB; 171 context_lost_reason_ = GL_UNKNOWN_CONTEXT_RESET_ARB;
199 if (context_lost_callback_) { 172 if (context_lost_callback_) {
200 context_lost_callback_->onContextLost(); 173 context_lost_callback_->onContextLost();
201 } 174 }
202 } 175 }
203 176
204 } // namespace gpu 177 } // namespace gpu
205 } // namespace webkit 178 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698