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

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

Issue 1136006: Calling OpenGL from the renderer process. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 9 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 | « chrome/renderer/ggl/ggl.h ('k') | chrome/renderer/gpu_channel_host.h » ('j') | 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 "chrome/renderer/command_buffer_proxy.h" 10 #include "chrome/renderer/command_buffer_proxy.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 } 43 }
44 44
45 private: 45 private:
46 DISALLOW_COPY_AND_ASSIGN(GLES2Initializer); 46 DISALLOW_COPY_AND_ASSIGN(GLES2Initializer);
47 }; 47 };
48 } // namespace anonymous 48 } // namespace anonymous
49 49
50 // Manages a GL context. 50 // Manages a GL context.
51 class Context { 51 class Context {
52 public: 52 public:
53 Context(); 53 Context(GpuChannelHost* channel, Context* parent);
54 ~Context(); 54 ~Context();
55 55
56 // Initialize a GGL context that can be used in association with a a GPU 56 // Initialize a GGL context that can be used in association with a a GPU
57 // channel acquired from a RenderWidget or RenderView. 57 // channel acquired from a RenderWidget or RenderView.
58 bool Initialize(GpuChannelHost* channel); 58 bool Initialize(gfx::NativeViewId view, const gfx::Size& size);
59
60 // Asynchronously resizes an offscreen frame buffer.
61 void ResizeOffscreen(const gfx::Size& size);
62
63 // For an offscreen frame buffer context, return the frame buffer ID with
64 // respect to the parent.
65 uint32 parent_texture_id() const {
66 return parent_texture_id_;
67 }
59 68
60 // Destroy all resources associated with the GGL context. 69 // Destroy all resources associated with the GGL context.
61 void Destroy(); 70 void Destroy();
62 71
63 // Make a GGL context current for the calling thread. 72 // Make a GGL context current for the calling thread.
64 static bool MakeCurrent(Context* context); 73 static bool MakeCurrent(Context* context);
65 74
66 // Display all content rendered since last call to SwapBuffers. 75 // Display all content rendered since last call to SwapBuffers.
67 // TODO(apatrick): support rendering to browser window. This function is 76 // TODO(apatrick): support rendering to browser window. This function is
68 // not useful at this point. 77 // not useful at this point.
69 bool SwapBuffers(); 78 bool SwapBuffers();
70 79
71 // Get the current error code. 80 // Get the current error code.
72 Error GetError(); 81 Error GetError();
73 82
74 private: 83 private:
75 scoped_refptr<GpuChannelHost> channel_; 84 scoped_refptr<GpuChannelHost> channel_;
85 Context* parent_;
86 uint32 parent_texture_id_;
76 CommandBufferProxy* command_buffer_; 87 CommandBufferProxy* command_buffer_;
77 gpu::gles2::GLES2CmdHelper* gles2_helper_; 88 gpu::gles2::GLES2CmdHelper* gles2_helper_;
78 int32 transfer_buffer_id_; 89 int32 transfer_buffer_id_;
79 gpu::gles2::GLES2Implementation* gles2_implementation_; 90 gpu::gles2::GLES2Implementation* gles2_implementation_;
80 91
81 DISALLOW_COPY_AND_ASSIGN(Context); 92 DISALLOW_COPY_AND_ASSIGN(Context);
82 }; 93 };
83 94
84 Context::Context() 95 Context::Context(GpuChannelHost* channel, Context* parent)
85 : channel_(NULL), 96 : channel_(channel),
97 parent_(parent),
98 parent_texture_id_(0),
86 command_buffer_(NULL), 99 command_buffer_(NULL),
87 gles2_helper_(NULL), 100 gles2_helper_(NULL),
88 transfer_buffer_id_(0), 101 transfer_buffer_id_(0),
89 gles2_implementation_(NULL) { 102 gles2_implementation_(NULL) {
103 DCHECK(channel);
90 } 104 }
91 105
92 Context::~Context() { 106 Context::~Context() {
93 Destroy(); 107 Destroy();
94 } 108 }
95 109
96 bool Context::Initialize(GpuChannelHost* channel) { 110 bool Context::Initialize(gfx::NativeViewId view, const gfx::Size& size) {
97 DCHECK(channel); 111 DCHECK(size.width() >= 0 && size.height() >= 0);
98 112
99 if (!channel->ready()) 113 if (!channel_->ready())
100 return false; 114 return false;
101 115
102 channel_ = channel;
103
104 // Ensure the gles2 library is initialized first in a thread safe way. 116 // Ensure the gles2 library is initialized first in a thread safe way.
105 Singleton<GLES2Initializer>::get(); 117 Singleton<GLES2Initializer>::get();
106 118
119 // Allocate a frame buffer ID with respect to the parent.
120 if (parent_) {
121 parent_->gles2_implementation_->MakeIds(1, &parent_texture_id_);
122 }
123
107 // Create a proxy to a command buffer in the GPU process. 124 // Create a proxy to a command buffer in the GPU process.
108 command_buffer_ = channel_->CreateCommandBuffer(); 125 if (view) {
126 command_buffer_ = channel_->CreateViewCommandBuffer(view);
127 } else {
128 CommandBufferProxy* parent_command_buffer =
129 parent_ ? parent_->command_buffer_ : NULL;
130 command_buffer_ = channel_->CreateOffscreenCommandBuffer(
131 parent_command_buffer,
132 size,
133 parent_texture_id_);
134 }
109 if (!command_buffer_) { 135 if (!command_buffer_) {
110 Destroy(); 136 Destroy();
111 return false; 137 return false;
112 } 138 }
113 139
114 // Initiaize the command buffer. 140 // Initiaize the command buffer.
115 if (!command_buffer_->Initialize(kCommandBufferSize)) { 141 if (!command_buffer_->Initialize(kCommandBufferSize)) {
116 Destroy(); 142 Destroy();
117 return false; 143 return false;
118 } 144 }
(...skipping 25 matching lines...) Expand all
144 // Create the object exposing the OpenGL API. 170 // Create the object exposing the OpenGL API.
145 gles2_implementation_ = new gpu::gles2::GLES2Implementation( 171 gles2_implementation_ = new gpu::gles2::GLES2Implementation(
146 gles2_helper_, 172 gles2_helper_,
147 transfer_buffer.size, 173 transfer_buffer.size,
148 transfer_buffer.ptr, 174 transfer_buffer.ptr,
149 transfer_buffer_id_); 175 transfer_buffer_id_);
150 176
151 return true; 177 return true;
152 } 178 }
153 179
180 void Context::ResizeOffscreen(const gfx::Size& size) {
181 DCHECK(size.width() > 0 && size.height() > 0);
182 command_buffer_->ResizeOffscreenFrameBuffer(size);
183 }
184
154 void Context::Destroy() { 185 void Context::Destroy() {
186 if (parent_ && parent_texture_id_ != 0)
187 parent_->gles2_implementation_->FreeIds(1, &parent_texture_id_);
188
155 delete gles2_implementation_; 189 delete gles2_implementation_;
156 gles2_implementation_ = NULL; 190 gles2_implementation_ = NULL;
157 191
158 if (command_buffer_ && transfer_buffer_id_ != 0) { 192 if (command_buffer_ && transfer_buffer_id_ != 0) {
159 command_buffer_->DestroyTransferBuffer(transfer_buffer_id_); 193 command_buffer_->DestroyTransferBuffer(transfer_buffer_id_);
160 transfer_buffer_id_ = 0; 194 transfer_buffer_id_ = 0;
161 } 195 }
162 196
163 delete gles2_helper_; 197 delete gles2_helper_;
164 gles2_helper_ = NULL; 198 gles2_helper_ = NULL;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 return SUCCESS; 240 return SUCCESS;
207 } else { 241 } else {
208 // All command buffer errors are unrecoverable. The error is treated as a 242 // All command buffer errors are unrecoverable. The error is treated as a
209 // lost context: destroy the context and create another one. 243 // lost context: destroy the context and create another one.
210 return CONTEXT_LOST; 244 return CONTEXT_LOST;
211 } 245 }
212 } 246 }
213 247
214 #endif // ENABLE_GPU 248 #endif // ENABLE_GPU
215 249
216 Context* CreateContext(GpuChannelHost* channel) { 250 Context* CreateViewContext(GpuChannelHost* channel, gfx::NativeViewId view) {
217 #if defined(ENABLE_GPU) 251 #if defined(ENABLE_GPU)
218 scoped_ptr<Context> context(new Context); 252 scoped_ptr<Context> context(new Context(channel, NULL));
219 if (!context->Initialize(channel)) 253 if (!context->Initialize(view, gfx::Size()))
220 return NULL; 254 return NULL;
221 255
222 return context.release(); 256 return context.release();
223 #else 257 #else
224 return NULL; 258 return NULL;
225 #endif 259 #endif
226 } 260 }
227 261
262 Context* CreateOffscreenContext(GpuChannelHost* channel,
263 Context* parent,
264 const gfx::Size& size) {
265 #if defined(ENABLE_GPU)
266 scoped_ptr<Context> context(new Context(channel, parent));
267 if (!context->Initialize(NULL, size))
268 return NULL;
269
270 return context.release();
271 #else
272 return NULL;
273 #endif
274 }
275
276 void ResizeOffscreenContext(Context* context, const gfx::Size& size) {
277 #if defined(ENABLE_GPU)
278 context->ResizeOffscreen(size);
279 #endif
280 }
281
282 uint32 GetParentTextureId(Context* context) {
283 #if defined(ENABLE_GPU)
284 return context->parent_texture_id();
285 #else
286 return 0;
287 #endif
288 }
289
228 bool MakeCurrent(Context* context) { 290 bool MakeCurrent(Context* context) {
229 #if defined(ENABLE_GPU) 291 #if defined(ENABLE_GPU)
230 return Context::MakeCurrent(context); 292 return Context::MakeCurrent(context);
231 #else 293 #else
232 return false; 294 return false;
233 #endif 295 #endif
234 } 296 }
235 297
236 Context* GetCurrentContext() { 298 Context* GetCurrentContext() {
237 #if defined(ENABLE_GPU) 299 #if defined(ENABLE_GPU)
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 if (!context) 336 if (!context)
275 return BAD_CONTEXT; 337 return BAD_CONTEXT;
276 338
277 return context->GetError(); 339 return context->GetError();
278 #else 340 #else
279 return NOT_INITIALIZED; 341 return NOT_INITIALIZED;
280 #endif 342 #endif
281 } 343 }
282 344
283 } // namespace ggl 345 } // namespace ggl
OLDNEW
« no previous file with comments | « chrome/renderer/ggl/ggl.h ('k') | chrome/renderer/gpu_channel_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698