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

Side by Side Diff: chrome/renderer/ggl/ggl.cc

Issue 2882004: Added support for allowing a parent GGL context to be destroyed before all of... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #include "base/ref_counted.h" 7 #include "base/ref_counted.h"
8 #include "base/singleton.h" 8 #include "base/singleton.h"
9 #include "base/thread_local.h" 9 #include "base/thread_local.h"
10 #include "base/weak_ptr.h"
10 #include "chrome/renderer/command_buffer_proxy.h" 11 #include "chrome/renderer/command_buffer_proxy.h"
11 #include "chrome/renderer/ggl/ggl.h" 12 #include "chrome/renderer/ggl/ggl.h"
12 #include "chrome/renderer/gpu_channel_host.h" 13 #include "chrome/renderer/gpu_channel_host.h"
13 #include "chrome/renderer/render_widget.h" 14 #include "chrome/renderer/render_widget.h"
14 #include "ipc/ipc_channel_handle.h" 15 #include "ipc/ipc_channel_handle.h"
15 16
16 #if defined(ENABLE_GPU) 17 #if defined(ENABLE_GPU)
17 #include "gpu/command_buffer/client/gles2_cmd_helper.h" 18 #include "gpu/command_buffer/client/gles2_cmd_helper.h"
18 #include "gpu/command_buffer/client/gles2_implementation.h" 19 #include "gpu/command_buffer/client/gles2_implementation.h"
19 #include "gpu/command_buffer/client/gles2_lib.h" 20 #include "gpu/command_buffer/client/gles2_lib.h"
(...skipping 24 matching lines...) Expand all
44 ~GLES2Initializer() { 45 ~GLES2Initializer() {
45 gles2::Terminate(); 46 gles2::Terminate();
46 } 47 }
47 48
48 private: 49 private:
49 DISALLOW_COPY_AND_ASSIGN(GLES2Initializer); 50 DISALLOW_COPY_AND_ASSIGN(GLES2Initializer);
50 }; 51 };
51 } // namespace anonymous 52 } // namespace anonymous
52 53
53 // Manages a GL context. 54 // Manages a GL context.
54 class Context { 55 class Context : public base::SupportsWeakPtr<Context> {
55 public: 56 public:
56 Context(GpuChannelHost* channel, Context* parent); 57 Context(GpuChannelHost* channel, Context* parent);
57 ~Context(); 58 ~Context();
58 59
59 // Initialize a GGL context that can be used in association with a a GPU 60 // Initialize a GGL context that can be used in association with a a GPU
60 // channel acquired from a RenderWidget or RenderView. 61 // channel acquired from a RenderWidget or RenderView.
61 bool Initialize(gfx::NativeViewId view, const gfx::Size& size); 62 bool Initialize(gfx::NativeViewId view, const gfx::Size& size);
62 63
63 // Asynchronously resizes an offscreen frame buffer. 64 // Asynchronously resizes an offscreen frame buffer.
64 void ResizeOffscreen(const gfx::Size& size); 65 void ResizeOffscreen(const gfx::Size& size);
(...skipping 16 matching lines...) Expand all
81 bool SwapBuffers(); 82 bool SwapBuffers();
82 83
83 // Get the current error code. 84 // Get the current error code.
84 Error GetError(); 85 Error GetError();
85 86
86 // TODO(gman): Remove this. 87 // TODO(gman): Remove this.
87 void DisableShaderTranslation(); 88 void DisableShaderTranslation();
88 89
89 private: 90 private:
90 scoped_refptr<GpuChannelHost> channel_; 91 scoped_refptr<GpuChannelHost> channel_;
91 Context* parent_; 92 base::WeakPtr<Context> parent_;
92 uint32 parent_texture_id_; 93 uint32 parent_texture_id_;
93 CommandBufferProxy* command_buffer_; 94 CommandBufferProxy* command_buffer_;
94 gpu::gles2::GLES2CmdHelper* gles2_helper_; 95 gpu::gles2::GLES2CmdHelper* gles2_helper_;
95 int32 transfer_buffer_id_; 96 int32 transfer_buffer_id_;
96 gpu::gles2::GLES2Implementation* gles2_implementation_; 97 gpu::gles2::GLES2Implementation* gles2_implementation_;
97 98
98 DISALLOW_COPY_AND_ASSIGN(Context); 99 DISALLOW_COPY_AND_ASSIGN(Context);
99 }; 100 };
100 101
101 Context::Context(GpuChannelHost* channel, Context* parent) 102 Context::Context(GpuChannelHost* channel, Context* parent)
102 : channel_(channel), 103 : channel_(channel),
103 parent_(parent), 104 parent_(parent ? parent->AsWeakPtr() : base::WeakPtr<Context>()),
104 parent_texture_id_(0), 105 parent_texture_id_(0),
105 command_buffer_(NULL), 106 command_buffer_(NULL),
106 gles2_helper_(NULL), 107 gles2_helper_(NULL),
107 transfer_buffer_id_(0), 108 transfer_buffer_id_(0),
108 gles2_implementation_(NULL) { 109 gles2_implementation_(NULL) {
109 DCHECK(channel); 110 DCHECK(channel);
110 } 111 }
111 112
112 Context::~Context() { 113 Context::~Context() {
113 Destroy(); 114 Destroy();
114 } 115 }
115 116
116 bool Context::Initialize(gfx::NativeViewId view, const gfx::Size& size) { 117 bool Context::Initialize(gfx::NativeViewId view, const gfx::Size& size) {
117 DCHECK(size.width() >= 0 && size.height() >= 0); 118 DCHECK(size.width() >= 0 && size.height() >= 0);
118 119
119 if (!channel_->ready()) 120 if (!channel_->ready())
120 return false; 121 return false;
121 122
122 // Ensure the gles2 library is initialized first in a thread safe way. 123 // Ensure the gles2 library is initialized first in a thread safe way.
123 Singleton<GLES2Initializer>::get(); 124 Singleton<GLES2Initializer>::get();
124 125
125 // Allocate a frame buffer ID with respect to the parent. 126 // Allocate a frame buffer ID with respect to the parent.
126 if (parent_) { 127 if (parent_.get()) {
127 // Flush any remaining commands in the parent context to make sure the 128 // Flush any remaining commands in the parent context to make sure the
128 // texture id accounting stays consistent. 129 // texture id accounting stays consistent.
129 int32 token = parent_->gles2_helper_->InsertToken(); 130 int32 token = parent_->gles2_helper_->InsertToken();
130 parent_->gles2_helper_->WaitForToken(token); 131 parent_->gles2_helper_->WaitForToken(token);
131 parent_texture_id_ = parent_->gles2_implementation_->MakeTextureId(); 132 parent_texture_id_ = parent_->gles2_implementation_->MakeTextureId();
132 } 133 }
133 134
134 // Create a proxy to a command buffer in the GPU process. 135 // Create a proxy to a command buffer in the GPU process.
135 if (view) { 136 if (view) {
136 command_buffer_ = channel_->CreateViewCommandBuffer(view); 137 command_buffer_ = channel_->CreateViewCommandBuffer(view);
137 } else { 138 } else {
138 CommandBufferProxy* parent_command_buffer = 139 CommandBufferProxy* parent_command_buffer =
139 parent_ ? parent_->command_buffer_ : NULL; 140 parent_.get() ? parent_->command_buffer_ : NULL;
140 command_buffer_ = channel_->CreateOffscreenCommandBuffer( 141 command_buffer_ = channel_->CreateOffscreenCommandBuffer(
141 parent_command_buffer, 142 parent_command_buffer,
142 size, 143 size,
143 parent_texture_id_); 144 parent_texture_id_);
144 } 145 }
145 if (!command_buffer_) { 146 if (!command_buffer_) {
146 Destroy(); 147 Destroy();
147 return false; 148 return false;
148 } 149 }
149 150
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 188
188 return true; 189 return true;
189 } 190 }
190 191
191 void Context::ResizeOffscreen(const gfx::Size& size) { 192 void Context::ResizeOffscreen(const gfx::Size& size) {
192 DCHECK(size.width() > 0 && size.height() > 0); 193 DCHECK(size.width() > 0 && size.height() > 0);
193 command_buffer_->ResizeOffscreenFrameBuffer(size); 194 command_buffer_->ResizeOffscreenFrameBuffer(size);
194 } 195 }
195 196
196 void Context::Destroy() { 197 void Context::Destroy() {
197 if (parent_ && parent_texture_id_ != 0) 198 if (parent_.get() && parent_texture_id_ != 0)
198 parent_->gles2_implementation_->FreeTextureId(parent_texture_id_); 199 parent_->gles2_implementation_->FreeTextureId(parent_texture_id_);
199 200
200 delete gles2_implementation_; 201 delete gles2_implementation_;
201 gles2_implementation_ = NULL; 202 gles2_implementation_ = NULL;
202 203
203 if (command_buffer_ && transfer_buffer_id_ != 0) { 204 if (command_buffer_ && transfer_buffer_id_ != 0) {
204 command_buffer_->DestroyTransferBuffer(transfer_buffer_id_); 205 command_buffer_->DestroyTransferBuffer(transfer_buffer_id_);
205 transfer_buffer_id_ = 0; 206 transfer_buffer_id_ = 0;
206 } 207 }
207 208
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 360
360 // TODO(gman): Remove This 361 // TODO(gman): Remove This
361 void DisableShaderTranslation(Context* context) { 362 void DisableShaderTranslation(Context* context) {
362 #if defined(ENABLE_GPU) 363 #if defined(ENABLE_GPU)
363 if (context) { 364 if (context) {
364 context->DisableShaderTranslation(); 365 context->DisableShaderTranslation();
365 } 366 }
366 #endif 367 #endif
367 } 368 }
368 } // namespace ggl 369 } // namespace ggl
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698