| 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/renderer_gl_context.h" | 5 #include "content/common/gpu/client/content_gl_context.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/shared_memory.h" | 14 #include "base/shared_memory.h" |
| 15 #include "content/common/view_messages.h" | 15 #include "content/common/gpu/client/command_buffer_proxy.h" |
| 16 #include "content/renderer/gpu/command_buffer_proxy.h" | 16 #include "content/common/gpu/client/gpu_channel_host.h" |
| 17 #include "content/renderer/gpu/gpu_channel_host.h" | |
| 18 #include "content/renderer/render_widget.h" | |
| 19 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
| 20 #include "ipc/ipc_channel_handle.h" | 18 #include "ipc/ipc_channel_handle.h" |
| 21 | 19 |
| 22 #if defined(ENABLE_GPU) | 20 #if defined(ENABLE_GPU) |
| 23 #include "gpu/command_buffer/client/gles2_cmd_helper.h" | 21 #include "gpu/command_buffer/client/gles2_cmd_helper.h" |
| 24 #include "gpu/command_buffer/client/gles2_implementation.h" | 22 #include "gpu/command_buffer/client/gles2_implementation.h" |
| 25 #include "gpu/command_buffer/client/gles2_lib.h" | 23 #include "gpu/command_buffer/client/gles2_lib.h" |
| 26 #include "gpu/command_buffer/client/transfer_buffer.h" | 24 #include "gpu/command_buffer/client/transfer_buffer.h" |
| 27 #include "gpu/command_buffer/common/constants.h" | 25 #include "gpu/command_buffer/common/constants.h" |
| 28 #endif // ENABLE_GPU | 26 #endif // ENABLE_GPU |
| (...skipping 23 matching lines...) Expand all Loading... |
| 52 }; | 50 }; |
| 53 | 51 |
| 54 //////////////////////////////////////////////////////////////////////////////// | 52 //////////////////////////////////////////////////////////////////////////////// |
| 55 | 53 |
| 56 base::LazyInstance<GLES2Initializer> g_gles2_initializer = | 54 base::LazyInstance<GLES2Initializer> g_gles2_initializer = |
| 57 LAZY_INSTANCE_INITIALIZER; | 55 LAZY_INSTANCE_INITIALIZER; |
| 58 | 56 |
| 59 //////////////////////////////////////////////////////////////////////////////// | 57 //////////////////////////////////////////////////////////////////////////////// |
| 60 | 58 |
| 61 #if defined(ENABLE_GPU) | 59 #if defined(ENABLE_GPU) |
| 62 RendererGLContext::ContextLostReason ConvertReason( | 60 ContentGLContext::ContextLostReason ConvertReason( |
| 63 gpu::error::ContextLostReason reason) { | 61 gpu::error::ContextLostReason reason) { |
| 64 switch (reason) { | 62 switch (reason) { |
| 65 case gpu::error::kGuilty: | 63 case gpu::error::kGuilty: |
| 66 return RendererGLContext::kGuilty; | 64 return ContentGLContext::kGuilty; |
| 67 case gpu::error::kInnocent: | 65 case gpu::error::kInnocent: |
| 68 return RendererGLContext::kInnocent; | 66 return ContentGLContext::kInnocent; |
| 69 case gpu::error::kUnknown: | 67 case gpu::error::kUnknown: |
| 70 return RendererGLContext::kUnknown; | 68 return ContentGLContext::kUnknown; |
| 71 } | 69 } |
| 72 NOTREACHED(); | 70 NOTREACHED(); |
| 73 return RendererGLContext::kUnknown; | 71 return ContentGLContext::kUnknown; |
| 74 } | 72 } |
| 75 #endif | 73 #endif |
| 76 | 74 |
| 77 } // namespace | 75 } // namespace |
| 78 | 76 |
| 79 RendererGLContext::~RendererGLContext() { | 77 ContentGLContext::~ContentGLContext() { |
| 80 Destroy(); | 78 Destroy(); |
| 81 } | 79 } |
| 82 | 80 |
| 83 RendererGLContext* RendererGLContext::CreateViewContext( | 81 ContentGLContext* ContentGLContext::CreateViewContext( |
| 84 GpuChannelHost* channel, | 82 GpuChannelHost* channel, |
| 85 int32 surface_id, | 83 int32 surface_id, |
| 86 RendererGLContext* share_group, | 84 ContentGLContext* share_group, |
| 87 const char* allowed_extensions, | 85 const char* allowed_extensions, |
| 88 const int32* attrib_list, | 86 const int32* attrib_list, |
| 89 const GURL& active_url, | 87 const GURL& active_url, |
| 90 gfx::GpuPreference gpu_preference) { | 88 gfx::GpuPreference gpu_preference) { |
| 91 #if defined(ENABLE_GPU) | 89 #if defined(ENABLE_GPU) |
| 92 scoped_ptr<RendererGLContext> context(new RendererGLContext(channel)); | 90 scoped_ptr<ContentGLContext> context(new ContentGLContext(channel)); |
| 93 if (!context->Initialize( | 91 if (!context->Initialize( |
| 94 true, | 92 true, |
| 95 surface_id, | 93 surface_id, |
| 96 gfx::Size(), | 94 gfx::Size(), |
| 97 share_group, | 95 share_group, |
| 98 allowed_extensions, | 96 allowed_extensions, |
| 99 attrib_list, | 97 attrib_list, |
| 100 active_url, | 98 active_url, |
| 101 gpu_preference)) | 99 gpu_preference)) |
| 102 return NULL; | 100 return NULL; |
| 103 | 101 |
| 104 return context.release(); | 102 return context.release(); |
| 105 #else | 103 #else |
| 106 return NULL; | 104 return NULL; |
| 107 #endif | 105 #endif |
| 108 } | 106 } |
| 109 | 107 |
| 110 RendererGLContext* RendererGLContext::CreateOffscreenContext( | 108 ContentGLContext* ContentGLContext::CreateOffscreenContext( |
| 111 GpuChannelHost* channel, | 109 GpuChannelHost* channel, |
| 112 const gfx::Size& size, | 110 const gfx::Size& size, |
| 113 RendererGLContext* share_group, | 111 ContentGLContext* share_group, |
| 114 const char* allowed_extensions, | 112 const char* allowed_extensions, |
| 115 const int32* attrib_list, | 113 const int32* attrib_list, |
| 116 const GURL& active_url, | 114 const GURL& active_url, |
| 117 gfx::GpuPreference gpu_preference) { | 115 gfx::GpuPreference gpu_preference) { |
| 118 #if defined(ENABLE_GPU) | 116 #if defined(ENABLE_GPU) |
| 119 scoped_ptr<RendererGLContext> context(new RendererGLContext(channel)); | 117 scoped_ptr<ContentGLContext> context(new ContentGLContext(channel)); |
| 120 if (!context->Initialize( | 118 if (!context->Initialize( |
| 121 false, | 119 false, |
| 122 0, | 120 0, |
| 123 size, | 121 size, |
| 124 share_group, | 122 share_group, |
| 125 allowed_extensions, | 123 allowed_extensions, |
| 126 attrib_list, | 124 attrib_list, |
| 127 active_url, | 125 active_url, |
| 128 gpu_preference)) | 126 gpu_preference)) |
| 129 return NULL; | 127 return NULL; |
| 130 | 128 |
| 131 return context.release(); | 129 return context.release(); |
| 132 #else | 130 #else |
| 133 return NULL; | 131 return NULL; |
| 134 #endif | 132 #endif |
| 135 } | 133 } |
| 136 | 134 |
| 137 bool RendererGLContext::SetParent(RendererGLContext* new_parent) { | 135 bool ContentGLContext::SetParent(ContentGLContext* new_parent) { |
| 138 if (parent_.get() == new_parent) | 136 if (parent_.get() == new_parent) |
| 139 return true; | 137 return true; |
| 140 | 138 |
| 141 // Allocate a texture ID with respect to the parent and change the parent. | 139 // Allocate a texture ID with respect to the parent and change the parent. |
| 142 uint32 new_parent_texture_id = 0; | 140 uint32 new_parent_texture_id = 0; |
| 143 if (command_buffer_) { | 141 if (command_buffer_) { |
| 144 if (new_parent) { | 142 if (new_parent) { |
| 145 TRACE_EVENT0("gpu", "RendererGLContext::SetParent::flushParent"); | 143 TRACE_EVENT0("gpu", "ContentGLContext::SetParent::flushParent"); |
| 146 // Flush any remaining commands in the parent context to make sure the | 144 // Flush any remaining commands in the parent context to make sure the |
| 147 // texture id accounting stays consistent. | 145 // texture id accounting stays consistent. |
| 148 int32 token = new_parent->gles2_helper_->InsertToken(); | 146 int32 token = new_parent->gles2_helper_->InsertToken(); |
| 149 new_parent->gles2_helper_->WaitForToken(token); | 147 new_parent->gles2_helper_->WaitForToken(token); |
| 150 new_parent_texture_id = | 148 new_parent_texture_id = |
| 151 new_parent->gles2_implementation_->MakeTextureId(); | 149 new_parent->gles2_implementation_->MakeTextureId(); |
| 152 | 150 |
| 153 if (!command_buffer_->SetParent(new_parent->command_buffer_, | 151 if (!command_buffer_->SetParent(new_parent->command_buffer_, |
| 154 new_parent_texture_id)) { | 152 new_parent_texture_id)) { |
| 155 new_parent->gles2_implementation_->FreeTextureId(parent_texture_id_); | 153 new_parent->gles2_implementation_->FreeTextureId(parent_texture_id_); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 175 parent_ = new_parent->AsWeakPtr(); | 173 parent_ = new_parent->AsWeakPtr(); |
| 176 parent_texture_id_ = new_parent_texture_id; | 174 parent_texture_id_ = new_parent_texture_id; |
| 177 } else { | 175 } else { |
| 178 parent_.reset(); | 176 parent_.reset(); |
| 179 parent_texture_id_ = 0; | 177 parent_texture_id_ = 0; |
| 180 } | 178 } |
| 181 | 179 |
| 182 return true; | 180 return true; |
| 183 } | 181 } |
| 184 | 182 |
| 185 uint32 RendererGLContext::GetParentTextureId() { | 183 uint32 ContentGLContext::GetParentTextureId() { |
| 186 return parent_texture_id_; | 184 return parent_texture_id_; |
| 187 } | 185 } |
| 188 | 186 |
| 189 uint32 RendererGLContext::CreateParentTexture(const gfx::Size& size) { | 187 uint32 ContentGLContext::CreateParentTexture(const gfx::Size& size) { |
| 190 uint32 texture_id = 0; | 188 uint32 texture_id = 0; |
| 191 gles2_implementation_->GenTextures(1, &texture_id); | 189 gles2_implementation_->GenTextures(1, &texture_id); |
| 192 gles2_implementation_->Flush(); | 190 gles2_implementation_->Flush(); |
| 193 return texture_id; | 191 return texture_id; |
| 194 } | 192 } |
| 195 | 193 |
| 196 void RendererGLContext::DeleteParentTexture(uint32 texture) { | 194 void ContentGLContext::DeleteParentTexture(uint32 texture) { |
| 197 gles2_implementation_->DeleteTextures(1, &texture); | 195 gles2_implementation_->DeleteTextures(1, &texture); |
| 198 } | 196 } |
| 199 | 197 |
| 200 void RendererGLContext::SetContextLostCallback( | 198 void ContentGLContext::SetContextLostCallback( |
| 201 const base::Callback<void (ContextLostReason)>& callback) { | 199 const base::Callback<void (ContextLostReason)>& callback) { |
| 202 context_lost_callback_ = callback; | 200 context_lost_callback_ = callback; |
| 203 } | 201 } |
| 204 | 202 |
| 205 bool RendererGLContext::MakeCurrent(RendererGLContext* context) { | 203 bool ContentGLContext::MakeCurrent(ContentGLContext* context) { |
| 206 if (context) { | 204 if (context) { |
| 207 DCHECK(context->CalledOnValidThread()); | 205 DCHECK(context->CalledOnValidThread()); |
| 208 gles2::SetGLContext(context->gles2_implementation_); | 206 gles2::SetGLContext(context->gles2_implementation_); |
| 209 | 207 |
| 210 // Don't request latest error status from service. Just use the locally | 208 // Don't request latest error status from service. Just use the locally |
| 211 // cached information from the last flush. | 209 // cached information from the last flush. |
| 212 // TODO(apatrick): I'm not sure if this should actually change the | 210 // TODO(apatrick): I'm not sure if this should actually change the |
| 213 // current context if it fails. For now it gets changed even if it fails | 211 // current context if it fails. For now it gets changed even if it fails |
| 214 // because making GL calls with a NULL context crashes. | 212 // because making GL calls with a NULL context crashes. |
| 215 if (context->command_buffer_->GetLastState().error != gpu::error::kNoError) | 213 if (context->command_buffer_->GetLastState().error != gpu::error::kNoError) |
| 216 return false; | 214 return false; |
| 217 } else { | 215 } else { |
| 218 gles2::SetGLContext(NULL); | 216 gles2::SetGLContext(NULL); |
| 219 } | 217 } |
| 220 | 218 |
| 221 return true; | 219 return true; |
| 222 } | 220 } |
| 223 | 221 |
| 224 bool RendererGLContext::SwapBuffers() { | 222 bool ContentGLContext::SwapBuffers() { |
| 225 TRACE_EVENT1("gpu", "RendererGLContext::SwapBuffers", "frame", frame_number_); | 223 TRACE_EVENT1("gpu", "ContentGLContext::SwapBuffers", "frame", frame_number_); |
| 226 frame_number_++; | 224 frame_number_++; |
| 227 | 225 |
| 228 // Don't request latest error status from service. Just use the locally cached | 226 // Don't request latest error status from service. Just use the locally cached |
| 229 // information from the last flush. | 227 // information from the last flush. |
| 230 if (command_buffer_->GetLastState().error != gpu::error::kNoError) | 228 if (command_buffer_->GetLastState().error != gpu::error::kNoError) |
| 231 return false; | 229 return false; |
| 232 | 230 |
| 233 gles2_implementation_->SwapBuffers(); | 231 gles2_implementation_->SwapBuffers(); |
| 234 | 232 |
| 235 return true; | 233 return true; |
| 236 } | 234 } |
| 237 | 235 |
| 238 bool RendererGLContext::Echo(const base::Closure& task) { | 236 bool ContentGLContext::Echo(const base::Closure& task) { |
| 239 return command_buffer_->Echo(task); | 237 return command_buffer_->Echo(task); |
| 240 } | 238 } |
| 241 | 239 |
| 242 RendererGLContext::Error RendererGLContext::GetError() { | 240 ContentGLContext::Error ContentGLContext::GetError() { |
| 243 gpu::CommandBuffer::State state = command_buffer_->GetState(); | 241 gpu::CommandBuffer::State state = command_buffer_->GetState(); |
| 244 if (state.error == gpu::error::kNoError) { | 242 if (state.error == gpu::error::kNoError) { |
| 245 Error old_error = last_error_; | 243 Error old_error = last_error_; |
| 246 last_error_ = SUCCESS; | 244 last_error_ = SUCCESS; |
| 247 return old_error; | 245 return old_error; |
| 248 } else { | 246 } else { |
| 249 // All command buffer errors are unrecoverable. The error is treated as a | 247 // All command buffer errors are unrecoverable. The error is treated as a |
| 250 // lost context: destroy the context and create another one. | 248 // lost context: destroy the context and create another one. |
| 251 return CONTEXT_LOST; | 249 return CONTEXT_LOST; |
| 252 } | 250 } |
| 253 } | 251 } |
| 254 | 252 |
| 255 bool RendererGLContext::IsCommandBufferContextLost() { | 253 bool ContentGLContext::IsCommandBufferContextLost() { |
| 256 // If the channel shut down unexpectedly, let that supersede the | 254 // If the channel shut down unexpectedly, let that supersede the |
| 257 // command buffer's state. | 255 // command buffer's state. |
| 258 if (channel_->state() == GpuChannelHost::kLost) | 256 if (channel_->state() == GpuChannelHost::kLost) |
| 259 return true; | 257 return true; |
| 260 gpu::CommandBuffer::State state = command_buffer_->GetLastState(); | 258 gpu::CommandBuffer::State state = command_buffer_->GetLastState(); |
| 261 return state.error == gpu::error::kLostContext; | 259 return state.error == gpu::error::kLostContext; |
| 262 } | 260 } |
| 263 | 261 |
| 264 CommandBufferProxy* RendererGLContext::GetCommandBufferProxy() { | 262 CommandBufferProxy* ContentGLContext::GetCommandBufferProxy() { |
| 265 return command_buffer_; | 263 return command_buffer_; |
| 266 } | 264 } |
| 267 | 265 |
| 268 bool RendererGLContext::SetSurfaceVisible(bool visible) { | 266 bool ContentGLContext::SetSurfaceVisible(bool visible) { |
| 269 return GetCommandBufferProxy()->SetSurfaceVisible(visible); | 267 return GetCommandBufferProxy()->SetSurfaceVisible(visible); |
| 270 } | 268 } |
| 271 | 269 |
| 272 // TODO(gman): Remove This | 270 // TODO(gman): Remove This |
| 273 void RendererGLContext::DisableShaderTranslation() { | 271 void ContentGLContext::DisableShaderTranslation() { |
| 274 NOTREACHED(); | 272 NOTREACHED(); |
| 275 } | 273 } |
| 276 | 274 |
| 277 gpu::gles2::GLES2Implementation* RendererGLContext::GetImplementation() { | 275 gpu::gles2::GLES2Implementation* ContentGLContext::GetImplementation() { |
| 278 return gles2_implementation_; | 276 return gles2_implementation_; |
| 279 } | 277 } |
| 280 | 278 |
| 281 RendererGLContext::RendererGLContext(GpuChannelHost* channel) | 279 ContentGLContext::ContentGLContext(GpuChannelHost* channel) |
| 282 : channel_(channel), | 280 : channel_(channel), |
| 283 parent_(base::WeakPtr<RendererGLContext>()), | 281 parent_(base::WeakPtr<ContentGLContext>()), |
| 284 parent_texture_id_(0), | 282 parent_texture_id_(0), |
| 285 command_buffer_(NULL), | 283 command_buffer_(NULL), |
| 286 gles2_helper_(NULL), | 284 gles2_helper_(NULL), |
| 287 transfer_buffer_(NULL), | 285 transfer_buffer_(NULL), |
| 288 gles2_implementation_(NULL), | 286 gles2_implementation_(NULL), |
| 289 last_error_(SUCCESS), | 287 last_error_(SUCCESS), |
| 290 frame_number_(0) { | 288 frame_number_(0) { |
| 291 DCHECK(channel); | 289 DCHECK(channel); |
| 292 } | 290 } |
| 293 | 291 |
| 294 bool RendererGLContext::Initialize(bool onscreen, | 292 bool ContentGLContext::Initialize(bool onscreen, |
| 295 int32 surface_id, | 293 int32 surface_id, |
| 296 const gfx::Size& size, | 294 const gfx::Size& size, |
| 297 RendererGLContext* share_group, | 295 ContentGLContext* share_group, |
| 298 const char* allowed_extensions, | 296 const char* allowed_extensions, |
| 299 const int32* attrib_list, | 297 const int32* attrib_list, |
| 300 const GURL& active_url, | 298 const GURL& active_url, |
| 301 gfx::GpuPreference gpu_preference) { | 299 gfx::GpuPreference gpu_preference) { |
| 302 DCHECK(CalledOnValidThread()); | 300 DCHECK(CalledOnValidThread()); |
| 303 DCHECK(size.width() >= 0 && size.height() >= 0); | 301 DCHECK(size.width() >= 0 && size.height() >= 0); |
| 304 TRACE_EVENT2("gpu", "RendererGLContext::Initialize", | 302 TRACE_EVENT2("gpu", "ContentGLContext::Initialize", |
| 305 "on_screen", onscreen, "num_pixels", size.GetArea()); | 303 "on_screen", onscreen, "num_pixels", size.GetArea()); |
| 306 | 304 |
| 307 if (channel_->state() != GpuChannelHost::kConnected) | 305 if (channel_->state() != GpuChannelHost::kConnected) |
| 308 return false; | 306 return false; |
| 309 | 307 |
| 310 // Ensure the gles2 library is initialized first in a thread safe way. | 308 // Ensure the gles2 library is initialized first in a thread safe way. |
| 311 g_gles2_initializer.Get(); | 309 g_gles2_initializer.Get(); |
| 312 | 310 |
| 313 bool share_resources = true; | 311 bool share_resources = true; |
| 314 bool bind_generates_resources = true; | 312 bool bind_generates_resources = true; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 342 last_error_ = BAD_ATTRIBUTE; | 340 last_error_ = BAD_ATTRIBUTE; |
| 343 attribs.push_back(NONE); | 341 attribs.push_back(NONE); |
| 344 attrib_list = NULL; | 342 attrib_list = NULL; |
| 345 break; | 343 break; |
| 346 } | 344 } |
| 347 } | 345 } |
| 348 | 346 |
| 349 // Create a proxy to a command buffer in the GPU process. | 347 // Create a proxy to a command buffer in the GPU process. |
| 350 if (onscreen) { | 348 if (onscreen) { |
| 351 TRACE_EVENT0("gpu", | 349 TRACE_EVENT0("gpu", |
| 352 "RendererGLContext::Initialize::CreateViewCommandBuffer"); | 350 "ContentGLContext::Initialize::CreateViewCommandBuffer"); |
| 353 command_buffer_ = channel_->CreateViewCommandBuffer( | 351 command_buffer_ = channel_->CreateViewCommandBuffer( |
| 354 surface_id, | 352 surface_id, |
| 355 share_group ? share_group->command_buffer_ : NULL, | 353 share_group ? share_group->command_buffer_ : NULL, |
| 356 allowed_extensions, | 354 allowed_extensions, |
| 357 attribs, | 355 attribs, |
| 358 active_url, | 356 active_url, |
| 359 gpu_preference); | 357 gpu_preference); |
| 360 } else { | 358 } else { |
| 361 command_buffer_ = channel_->CreateOffscreenCommandBuffer( | 359 command_buffer_ = channel_->CreateOffscreenCommandBuffer( |
| 362 size, | 360 size, |
| 363 share_group ? share_group->command_buffer_ : NULL, | 361 share_group ? share_group->command_buffer_ : NULL, |
| 364 allowed_extensions, | 362 allowed_extensions, |
| 365 attribs, | 363 attribs, |
| 366 active_url, | 364 active_url, |
| 367 gpu_preference); | 365 gpu_preference); |
| 368 } | 366 } |
| 369 if (!command_buffer_) { | 367 if (!command_buffer_) { |
| 370 Destroy(); | 368 Destroy(); |
| 371 return false; | 369 return false; |
| 372 } | 370 } |
| 373 | 371 |
| 374 { | 372 { |
| 375 TRACE_EVENT0("gpu", | 373 TRACE_EVENT0("gpu", |
| 376 "RendererGLContext::Initialize::InitializeCommandBuffer"); | 374 "ContentGLContext::Initialize::InitializeCommandBuffer"); |
| 377 // Initiaize the command buffer. | 375 // Initiaize the command buffer. |
| 378 if (!command_buffer_->Initialize()) { | 376 if (!command_buffer_->Initialize()) { |
| 379 Destroy(); | 377 Destroy(); |
| 380 return false; | 378 return false; |
| 381 } | 379 } |
| 382 } | 380 } |
| 383 | 381 |
| 384 command_buffer_->SetChannelErrorCallback( | 382 command_buffer_->SetChannelErrorCallback( |
| 385 base::Bind(&RendererGLContext::OnContextLost, base::Unretained(this))); | 383 base::Bind(&ContentGLContext::OnContextLost, base::Unretained(this))); |
| 386 | 384 |
| 387 // Create the GLES2 helper, which writes the command buffer protocol. | 385 // Create the GLES2 helper, which writes the command buffer protocol. |
| 388 gles2_helper_ = new gpu::gles2::GLES2CmdHelper(command_buffer_); | 386 gles2_helper_ = new gpu::gles2::GLES2CmdHelper(command_buffer_); |
| 389 if (!gles2_helper_->Initialize(kCommandBufferSize)) { | 387 if (!gles2_helper_->Initialize(kCommandBufferSize)) { |
| 390 Destroy(); | 388 Destroy(); |
| 391 return false; | 389 return false; |
| 392 } | 390 } |
| 393 | 391 |
| 394 { | 392 { |
| 395 TRACE_EVENT0("gpu", "RendererGLContext::Initialize::CreateTransferBuffer"); | 393 TRACE_EVENT0("gpu", "ContentGLContext::Initialize::CreateTransferBuffer"); |
| 396 // Create a transfer buffer used to copy resources between the renderer | 394 // Create a transfer buffer used to copy resources between the renderer |
| 397 // process and the GPU process. | 395 // process and the GPU process. |
| 398 transfer_buffer_ = new gpu::TransferBuffer(gles2_helper_); | 396 transfer_buffer_ = new gpu::TransferBuffer(gles2_helper_); |
| 399 } | 397 } |
| 400 | 398 |
| 401 // Create the object exposing the OpenGL API. | 399 // Create the object exposing the OpenGL API. |
| 402 gles2_implementation_ = new gpu::gles2::GLES2Implementation( | 400 gles2_implementation_ = new gpu::gles2::GLES2Implementation( |
| 403 gles2_helper_, | 401 gles2_helper_, |
| 404 transfer_buffer_, | 402 transfer_buffer_, |
| 405 share_resources, | 403 share_resources, |
| 406 bind_generates_resources); | 404 bind_generates_resources); |
| 407 | 405 |
| 408 if (!gles2_implementation_->Initialize( | 406 if (!gles2_implementation_->Initialize( |
| 409 kStartTransferBufferSize, | 407 kStartTransferBufferSize, |
| 410 kMinTransferBufferSize, | 408 kMinTransferBufferSize, |
| 411 kMaxTransferBufferSize)) { | 409 kMaxTransferBufferSize)) { |
| 412 Destroy(); | 410 Destroy(); |
| 413 return false; | 411 return false; |
| 414 } | 412 } |
| 415 | 413 |
| 416 return true; | 414 return true; |
| 417 } | 415 } |
| 418 | 416 |
| 419 void RendererGLContext::Destroy() { | 417 void ContentGLContext::Destroy() { |
| 420 TRACE_EVENT0("gpu", "RendererGLContext::Destroy"); | 418 TRACE_EVENT0("gpu", "ContentGLContext::Destroy"); |
| 421 DCHECK(CalledOnValidThread()); | 419 DCHECK(CalledOnValidThread()); |
| 422 SetParent(NULL); | 420 SetParent(NULL); |
| 423 | 421 |
| 424 if (gles2_implementation_) { | 422 if (gles2_implementation_) { |
| 425 // First flush the context to ensure that any pending frees of resources | 423 // First flush the context to ensure that any pending frees of resources |
| 426 // are completed. Otherwise, if this context is part of a share group, | 424 // are completed. Otherwise, if this context is part of a share group, |
| 427 // those resources might leak. Also, any remaining side effects of commands | 425 // those resources might leak. Also, any remaining side effects of commands |
| 428 // issued on this context might not be visible to other contexts in the | 426 // issued on this context might not be visible to other contexts in the |
| 429 // share group. | 427 // share group. |
| 430 gles2_implementation_->Flush(); | 428 gles2_implementation_->Flush(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 442 gles2_helper_ = NULL; | 440 gles2_helper_ = NULL; |
| 443 | 441 |
| 444 if (channel_ && command_buffer_) { | 442 if (channel_ && command_buffer_) { |
| 445 channel_->DestroyCommandBuffer(command_buffer_); | 443 channel_->DestroyCommandBuffer(command_buffer_); |
| 446 command_buffer_ = NULL; | 444 command_buffer_ = NULL; |
| 447 } | 445 } |
| 448 | 446 |
| 449 channel_ = NULL; | 447 channel_ = NULL; |
| 450 } | 448 } |
| 451 | 449 |
| 452 void RendererGLContext::OnContextLost() { | 450 void ContentGLContext::OnContextLost() { |
| 453 if (!context_lost_callback_.is_null()) { | 451 if (!context_lost_callback_.is_null()) { |
| 454 RendererGLContext::ContextLostReason reason = kUnknown; | 452 ContentGLContext::ContextLostReason reason = kUnknown; |
| 455 if (command_buffer_) { | 453 if (command_buffer_) { |
| 456 reason = ConvertReason( | 454 reason = ConvertReason( |
| 457 command_buffer_->GetLastState().context_lost_reason); | 455 command_buffer_->GetLastState().context_lost_reason); |
| 458 } | 456 } |
| 459 context_lost_callback_.Run(reason); | 457 context_lost_callback_.Run(reason); |
| 460 } | 458 } |
| 461 } | 459 } |
| OLD | NEW |