| 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 #include "content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.h" | 5 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
| 6 | 6 |
| 7 #include "third_party/khronos/GLES2/gl2.h" | 7 #include "third_party/khronos/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 "third_party/khronos/GLES2/gl2ext.h" | 11 #include "third_party/khronos/GLES2/gl2ext.h" |
| 12 | 12 |
| 13 #include <algorithm> | 13 #include <algorithm> |
| 14 #include <set> | 14 #include <set> |
| 15 | 15 |
| 16 #include "base/bind.h" | 16 #include "base/bind.h" |
| 17 #include "base/lazy_instance.h" | 17 #include "base/lazy_instance.h" |
| 18 #include "base/string_tokenizer.h" | 18 #include "base/string_tokenizer.h" |
| 19 #include "base/command_line.h" | 19 #include "base/command_line.h" |
| 20 #include "base/debug/trace_event.h" | 20 #include "base/debug/trace_event.h" |
| 21 #include "base/logging.h" | 21 #include "base/logging.h" |
| 22 #include "base/message_loop.h" | 22 #include "base/message_loop.h" |
| 23 #include "base/metrics/histogram.h" | 23 #include "base/metrics/histogram.h" |
| 24 #include "base/synchronization/lock.h" | 24 #include "base/synchronization/lock.h" |
| 25 #include "content/common/gpu/client/command_buffer_proxy.h" |
| 26 #include "content/common/gpu/client/gpu_channel_host.h" |
| 25 #include "content/public/common/content_switches.h" | 27 #include "content/public/common/content_switches.h" |
| 26 #include "content/renderer/gpu/command_buffer_proxy.h" | |
| 27 #include "content/renderer/gpu/gpu_channel_host.h" | |
| 28 #include "content/renderer/render_view_impl.h" | |
| 29 #include "gpu/command_buffer/client/gles2_implementation.h" | 28 #include "gpu/command_buffer/client/gles2_implementation.h" |
| 30 #include "gpu/command_buffer/common/constants.h" | 29 #include "gpu/command_buffer/common/constants.h" |
| 31 #include "webkit/glue/gl_bindings_skia_cmd_buffer.h" | 30 #include "webkit/glue/gl_bindings_skia_cmd_buffer.h" |
| 32 | 31 |
| 33 static base::LazyInstance<base::Lock>::Leaky | 32 static base::LazyInstance<base::Lock>::Leaky |
| 34 g_all_shared_contexts_lock = LAZY_INSTANCE_INITIALIZER; | 33 g_all_shared_contexts_lock = LAZY_INSTANCE_INITIALIZER; |
| 35 static base::LazyInstance<std::set<WebGraphicsContext3DCommandBufferImpl*> > | 34 static base::LazyInstance<std::set<WebGraphicsContext3DCommandBufferImpl*> > |
| 36 g_all_shared_contexts = LAZY_INSTANCE_INITIALIZER; | 35 g_all_shared_contexts = LAZY_INSTANCE_INITIALIZER; |
| 37 | 36 |
| 38 namespace { | 37 namespace { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 do { | 101 do { |
| 103 host_ = factory->EstablishGpuChannelSync( | 102 host_ = factory->EstablishGpuChannelSync( |
| 104 content:: | 103 content:: |
| 105 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE); | 104 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE); |
| 106 if (!host_) | 105 if (!host_) |
| 107 return false; | 106 return false; |
| 108 DCHECK(host_->state() == GpuChannelHost::kConnected); | 107 DCHECK(host_->state() == GpuChannelHost::kConnected); |
| 109 | 108 |
| 110 if (!retry) { | 109 if (!retry) { |
| 111 // If the creation of this context requires all contexts for this | 110 // If the creation of this context requires all contexts for this |
| 112 // renderer to be destroyed on the GPU process side, then drop the | 111 // client to be destroyed on the GPU process side, then drop the |
| 113 // channel and recreate it. | 112 // channel and recreate it. |
| 114 if (host_->WillGpuSwitchOccur(true, gpu_preference_)) { | 113 if (host_->WillGpuSwitchOccur(true, gpu_preference_)) { |
| 115 host_->ForciblyCloseChannel(); | 114 host_->ForciblyCloseChannel(); |
| 116 ClearSharedContexts(); | 115 ClearSharedContexts(); |
| 117 retry = true; | 116 retry = true; |
| 118 } | 117 } |
| 119 } else { | 118 } else { |
| 120 retry = false; | 119 retry = false; |
| 121 } | 120 } |
| 122 } while (retry); | 121 } while (retry); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 143 | 142 |
| 144 TRACE_EVENT0("gpu", "WebGfxCtx3DCmdBfrImpl::MaybeInitializeGL"); | 143 TRACE_EVENT0("gpu", "WebGfxCtx3DCmdBfrImpl::MaybeInitializeGL"); |
| 145 | 144 |
| 146 // If the context is being initialized on something other than the main | 145 // If the context is being initialized on something other than the main |
| 147 // thread, then make sure the swap_client_ pointer is NULL so we don't | 146 // thread, then make sure the swap_client_ pointer is NULL so we don't |
| 148 // accidentally dereference it. | 147 // accidentally dereference it. |
| 149 GpuChannelHostFactory* factory = GpuChannelHostFactory::instance(); | 148 GpuChannelHostFactory* factory = GpuChannelHostFactory::instance(); |
| 150 if (!factory || !factory->IsMainThread()) | 149 if (!factory || !factory->IsMainThread()) |
| 151 DCHECK(!swap_client_.get()); | 150 DCHECK(!swap_client_.get()); |
| 152 | 151 |
| 153 // Convert WebGL context creation attributes into RendererGLContext / EGL size | 152 // Convert WebGL context creation attributes into ContentGLContext / EGL size |
| 154 // requests. | 153 // requests. |
| 155 const int alpha_size = attributes_.alpha ? 8 : 0; | 154 const int alpha_size = attributes_.alpha ? 8 : 0; |
| 156 const int depth_size = attributes_.depth ? 24 : 0; | 155 const int depth_size = attributes_.depth ? 24 : 0; |
| 157 const int stencil_size = attributes_.stencil ? 8 : 0; | 156 const int stencil_size = attributes_.stencil ? 8 : 0; |
| 158 const int samples = attributes_.antialias ? 4 : 0; | 157 const int samples = attributes_.antialias ? 4 : 0; |
| 159 const int sample_buffers = attributes_.antialias ? 1 : 0; | 158 const int sample_buffers = attributes_.antialias ? 1 : 0; |
| 160 const int32 attribs[] = { | 159 const int32 attribs[] = { |
| 161 RendererGLContext::ALPHA_SIZE, alpha_size, | 160 ContentGLContext::ALPHA_SIZE, alpha_size, |
| 162 RendererGLContext::DEPTH_SIZE, depth_size, | 161 ContentGLContext::DEPTH_SIZE, depth_size, |
| 163 RendererGLContext::STENCIL_SIZE, stencil_size, | 162 ContentGLContext::STENCIL_SIZE, stencil_size, |
| 164 RendererGLContext::SAMPLES, samples, | 163 ContentGLContext::SAMPLES, samples, |
| 165 RendererGLContext::SAMPLE_BUFFERS, sample_buffers, | 164 ContentGLContext::SAMPLE_BUFFERS, sample_buffers, |
| 166 RendererGLContext::SHARE_RESOURCES, attributes_.shareResources ? 1 : 0, | 165 ContentGLContext::SHARE_RESOURCES, attributes_.shareResources ? 1 : 0, |
| 167 RendererGLContext::BIND_GENERATES_RESOURCES, 0, | 166 ContentGLContext::BIND_GENERATES_RESOURCES, 0, |
| 168 RendererGLContext::NONE, | 167 ContentGLContext::NONE, |
| 169 }; | 168 }; |
| 170 | 169 |
| 171 const char* preferred_extensions = "*"; | 170 const char* preferred_extensions = "*"; |
| 172 | 171 |
| 173 // We need to lock g_all_shared_contexts until after RendererGLContext::Create | 172 // We need to lock g_all_shared_contexts until after ContentGLContext::Create |
| 174 // to ensure that the context we picked for our share group isn't deleted. | 173 // to ensure that the context we picked for our share group isn't deleted. |
| 175 // (There's also a lock in our destructor.) | 174 // (There's also a lock in our destructor.) |
| 176 { | 175 { |
| 177 base::AutoLock lock(g_all_shared_contexts_lock.Get()); | 176 base::AutoLock lock(g_all_shared_contexts_lock.Get()); |
| 178 RendererGLContext* share_group = NULL; | 177 ContentGLContext* share_group = NULL; |
| 179 if (attributes_.shareResources) { | 178 if (attributes_.shareResources) { |
| 180 share_group = g_all_shared_contexts.Pointer()->empty() ? | 179 share_group = g_all_shared_contexts.Pointer()->empty() ? |
| 181 NULL : (*g_all_shared_contexts.Pointer()->begin())->context_; | 180 NULL : (*g_all_shared_contexts.Pointer()->begin())->context_; |
| 182 } | 181 } |
| 183 | 182 |
| 184 if (surface_id_) { | 183 if (surface_id_) { |
| 185 context_ = RendererGLContext::CreateViewContext( | 184 context_ = ContentGLContext::CreateViewContext( |
| 186 host_, | 185 host_, |
| 187 surface_id_, | 186 surface_id_, |
| 188 share_group, | 187 share_group, |
| 189 preferred_extensions, | 188 preferred_extensions, |
| 190 attribs, | 189 attribs, |
| 191 active_url_, | 190 active_url_, |
| 192 gpu_preference_); | 191 gpu_preference_); |
| 193 } else { | 192 } else { |
| 194 context_ = RendererGLContext::CreateOffscreenContext( | 193 context_ = ContentGLContext::CreateOffscreenContext( |
| 195 host_, | 194 host_, |
| 196 gfx::Size(1, 1), | 195 gfx::Size(1, 1), |
| 197 share_group, | 196 share_group, |
| 198 preferred_extensions, | 197 preferred_extensions, |
| 199 attribs, | 198 attribs, |
| 200 active_url_, | 199 active_url_, |
| 201 gpu_preference_); | 200 gpu_preference_); |
| 202 } | 201 } |
| 203 } | 202 } |
| 204 | 203 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 base::AutoLock lock(g_all_shared_contexts_lock.Get()); | 241 base::AutoLock lock(g_all_shared_contexts_lock.Get()); |
| 243 g_all_shared_contexts.Pointer()->insert(this); | 242 g_all_shared_contexts.Pointer()->insert(this); |
| 244 } | 243 } |
| 245 | 244 |
| 246 return true; | 245 return true; |
| 247 } | 246 } |
| 248 | 247 |
| 249 bool WebGraphicsContext3DCommandBufferImpl::makeContextCurrent() { | 248 bool WebGraphicsContext3DCommandBufferImpl::makeContextCurrent() { |
| 250 if (!MaybeInitializeGL()) | 249 if (!MaybeInitializeGL()) |
| 251 return false; | 250 return false; |
| 252 return RendererGLContext::MakeCurrent(context_); | 251 return ContentGLContext::MakeCurrent(context_); |
| 253 } | 252 } |
| 254 | 253 |
| 255 int WebGraphicsContext3DCommandBufferImpl::width() { | 254 int WebGraphicsContext3DCommandBufferImpl::width() { |
| 256 return cached_width_; | 255 return cached_width_; |
| 257 } | 256 } |
| 258 | 257 |
| 259 int WebGraphicsContext3DCommandBufferImpl::height() { | 258 int WebGraphicsContext3DCommandBufferImpl::height() { |
| 260 return cached_height_; | 259 return cached_height_; |
| 261 } | 260 } |
| 262 | 261 |
| (...skipping 884 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1147 WGC3Denum, WGC3Dint, WGC3Duint, WGC3Dint, WGC3Dint) | 1146 WGC3Denum, WGC3Dint, WGC3Duint, WGC3Dint, WGC3Dint) |
| 1148 | 1147 |
| 1149 #if WEBKIT_USING_SKIA | 1148 #if WEBKIT_USING_SKIA |
| 1150 GrGLInterface* WebGraphicsContext3DCommandBufferImpl::onCreateGrGLInterface() { | 1149 GrGLInterface* WebGraphicsContext3DCommandBufferImpl::onCreateGrGLInterface() { |
| 1151 return webkit_glue::CreateCommandBufferSkiaGLBinding(); | 1150 return webkit_glue::CreateCommandBufferSkiaGLBinding(); |
| 1152 } | 1151 } |
| 1153 #endif | 1152 #endif |
| 1154 | 1153 |
| 1155 namespace { | 1154 namespace { |
| 1156 | 1155 |
| 1157 WGC3Denum convertReason(RendererGLContext::ContextLostReason reason) { | 1156 WGC3Denum convertReason(ContentGLContext::ContextLostReason reason) { |
| 1158 switch (reason) { | 1157 switch (reason) { |
| 1159 case RendererGLContext::kGuilty: | 1158 case ContentGLContext::kGuilty: |
| 1160 return GL_GUILTY_CONTEXT_RESET_ARB; | 1159 return GL_GUILTY_CONTEXT_RESET_ARB; |
| 1161 case RendererGLContext::kInnocent: | 1160 case ContentGLContext::kInnocent: |
| 1162 return GL_INNOCENT_CONTEXT_RESET_ARB; | 1161 return GL_INNOCENT_CONTEXT_RESET_ARB; |
| 1163 case RendererGLContext::kUnknown: | 1162 case ContentGLContext::kUnknown: |
| 1164 return GL_UNKNOWN_CONTEXT_RESET_ARB; | 1163 return GL_UNKNOWN_CONTEXT_RESET_ARB; |
| 1165 } | 1164 } |
| 1166 | 1165 |
| 1167 NOTREACHED(); | 1166 NOTREACHED(); |
| 1168 return GL_UNKNOWN_CONTEXT_RESET_ARB; | 1167 return GL_UNKNOWN_CONTEXT_RESET_ARB; |
| 1169 } | 1168 } |
| 1170 | 1169 |
| 1171 } // anonymous namespace | 1170 } // anonymous namespace |
| 1172 | 1171 |
| 1173 void WebGraphicsContext3DCommandBufferImpl::OnContextLost( | 1172 void WebGraphicsContext3DCommandBufferImpl::OnContextLost( |
| 1174 RendererGLContext::ContextLostReason reason) { | 1173 ContentGLContext::ContextLostReason reason) { |
| 1175 context_lost_reason_ = convertReason(reason); | 1174 context_lost_reason_ = convertReason(reason); |
| 1176 if (context_lost_callback_) { | 1175 if (context_lost_callback_) { |
| 1177 context_lost_callback_->onContextLost(); | 1176 context_lost_callback_->onContextLost(); |
| 1178 } | 1177 } |
| 1179 if (attributes_.shareResources) | 1178 if (attributes_.shareResources) |
| 1180 ClearSharedContexts(); | 1179 ClearSharedContexts(); |
| 1181 if (swap_client_.get()) | 1180 if (swap_client_.get()) |
| 1182 swap_client_->OnViewContextSwapBuffersAborted(); | 1181 swap_client_->OnViewContextSwapBuffersAborted(); |
| 1183 } | 1182 } |
| OLD | NEW |