| 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/common/gpu/client/gl_helper.h" | 5 #include "content/common/gpu/client/gl_helper.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 class ScopedTextureBinder : ScopedBinder<target> { | 184 class ScopedTextureBinder : ScopedBinder<target> { |
| 185 public: | 185 public: |
| 186 ScopedTextureBinder(WebKit::WebGraphicsContext3D* context, | 186 ScopedTextureBinder(WebKit::WebGraphicsContext3D* context, |
| 187 WebKit::WebGLId id) | 187 WebKit::WebGLId id) |
| 188 : ScopedBinder<target>( | 188 : ScopedBinder<target>( |
| 189 context, | 189 context, |
| 190 id, | 190 id, |
| 191 &WebKit::WebGraphicsContext3D::bindTexture) {} | 191 &WebKit::WebGraphicsContext3D::bindTexture) {} |
| 192 }; | 192 }; |
| 193 | 193 |
| 194 class ScopedFlush { |
| 195 public: |
| 196 ScopedFlush(WebKit::WebGraphicsContext3D* context) |
| 197 : context_(context) { |
| 198 } |
| 199 |
| 200 virtual ~ScopedFlush() { |
| 201 context_->flush(); |
| 202 } |
| 203 |
| 204 private: |
| 205 WebKit::WebGraphicsContext3D* context_; |
| 206 |
| 207 DISALLOW_COPY_AND_ASSIGN(ScopedFlush); |
| 208 }; |
| 209 |
| 194 void ReadBackFramebuffer( | 210 void ReadBackFramebuffer( |
| 195 WebKit::WebGraphicsContext3D* context, | 211 WebKit::WebGraphicsContext3D* context, |
| 196 unsigned char* pixels, | 212 unsigned char* pixels, |
| 197 gfx::Size size, | 213 gfx::Size size, |
| 198 WebKit::WebGLId dst_texture, | 214 WebKit::WebGLId dst_texture, |
| 199 bool* result) { | 215 bool* result) { |
| 200 *result = false; | 216 *result = false; |
| 201 if (!context->makeContextCurrent()) | 217 if (!context->makeContextCurrent()) |
| 202 return; | 218 return; |
| 203 if (context->isContextLost()) | 219 if (context->isContextLost()) |
| 204 return; | 220 return; |
| 221 ScopedFlush flush(context); |
| 205 ScopedFramebuffer dst_framebuffer(context, context->createFramebuffer()); | 222 ScopedFramebuffer dst_framebuffer(context, context->createFramebuffer()); |
| 206 { | 223 { |
| 207 ScopedFramebufferBinder<GL_DRAW_FRAMEBUFFER> framebuffer_binder( | 224 ScopedFramebufferBinder<GL_DRAW_FRAMEBUFFER> framebuffer_binder( |
| 208 context, dst_framebuffer); | 225 context, dst_framebuffer); |
| 209 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder( | 226 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder( |
| 210 context, dst_texture); | 227 context, dst_texture); |
| 211 context->framebufferTexture2D(GL_DRAW_FRAMEBUFFER, | 228 context->framebufferTexture2D(GL_DRAW_FRAMEBUFFER, |
| 212 GL_COLOR_ATTACHMENT0, | 229 GL_COLOR_ATTACHMENT0, |
| 213 GL_TEXTURE_2D, | 230 GL_TEXTURE_2D, |
| 214 dst_texture, | 231 dst_texture, |
| 215 0); | 232 0); |
| 216 } | 233 } |
| 217 *result = context->readBackFramebuffer( | 234 *result = context->readBackFramebuffer( |
| 218 pixels, | 235 pixels, |
| 219 4 * size.GetArea(), | 236 4 * size.GetArea(), |
| 220 static_cast<WebKit::WebGLId>(dst_framebuffer), | 237 static_cast<WebKit::WebGLId>(dst_framebuffer), |
| 221 size.width(), | 238 size.width(), |
| 222 size.height()); | 239 size.height()); |
| 223 context->flush(); | |
| 224 } | 240 } |
| 225 | 241 |
| 226 void ReadBackFramebufferComplete(WebKit::WebGraphicsContext3D* context, | 242 void ReadBackFramebufferComplete(WebKit::WebGraphicsContext3D* context, |
| 227 WebKit::WebGLId* dst_texture, | 243 WebKit::WebGLId* dst_texture, |
| 228 base::Callback<void(bool)> callback, | 244 base::Callback<void(bool)> callback, |
| 229 bool* result) { | 245 bool* result) { |
| 230 callback.Run(*result); | 246 callback.Run(*result); |
| 231 if (*dst_texture != 0) { | 247 if (*dst_texture != 0) { |
| 232 context->deleteTexture(*dst_texture); | 248 context->deleteTexture(*dst_texture); |
| 249 context->flush(); |
| 233 *dst_texture = 0; | 250 *dst_texture = 0; |
| 234 } | 251 } |
| 235 } | 252 } |
| 236 | 253 |
| 237 void DeleteContext(WebKit::WebGraphicsContext3D* context) { | 254 void DeleteContext(WebKit::WebGraphicsContext3D* context) { |
| 238 delete context; | 255 delete context; |
| 239 } | 256 } |
| 240 | 257 |
| 241 void SignalWaitableEvent(base::WaitableEvent* event) { | 258 void SignalWaitableEvent(base::WaitableEvent* event) { |
| 242 event->Signal(); | 259 event->Signal(); |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 base::Bind(&DeleteContext, | 464 base::Bind(&DeleteContext, |
| 448 context_for_thread_)); | 465 context_for_thread_)); |
| 449 context_for_thread_ = NULL; | 466 context_for_thread_ = NULL; |
| 450 } | 467 } |
| 451 | 468 |
| 452 bool GLHelper::CopyTextureToImpl::CopyTextureTo( | 469 bool GLHelper::CopyTextureToImpl::CopyTextureTo( |
| 453 WebKit::WebGLId src_texture, | 470 WebKit::WebGLId src_texture, |
| 454 const gfx::Size& src_size, | 471 const gfx::Size& src_size, |
| 455 const gfx::Size& dst_size, | 472 const gfx::Size& dst_size, |
| 456 unsigned char* out) { | 473 unsigned char* out) { |
| 474 ScopedFlush flush(context_); |
| 457 ScopedTexture dst_texture(context_, | 475 ScopedTexture dst_texture(context_, |
| 458 ScaleTexture(src_texture, src_size, dst_size)); | 476 ScaleTexture(src_texture, src_size, dst_size)); |
| 459 ScopedFramebuffer dst_framebuffer(context_, context_->createFramebuffer()); | 477 ScopedFramebuffer dst_framebuffer(context_, context_->createFramebuffer()); |
| 460 { | 478 { |
| 461 ScopedFramebufferBinder<GL_DRAW_FRAMEBUFFER> framebuffer_binder( | 479 ScopedFramebufferBinder<GL_DRAW_FRAMEBUFFER> framebuffer_binder( |
| 462 context_, dst_framebuffer); | 480 context_, dst_framebuffer); |
| 463 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder( | 481 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder( |
| 464 context_, dst_framebuffer); | 482 context_, dst_framebuffer); |
| 465 context_->framebufferTexture2D(GL_DRAW_FRAMEBUFFER, | 483 context_->framebufferTexture2D(GL_DRAW_FRAMEBUFFER, |
| 466 GL_COLOR_ATTACHMENT0, | 484 GL_COLOR_ATTACHMENT0, |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 WebKit::WGC3Dint compile_status = 0; | 604 WebKit::WGC3Dint compile_status = 0; |
| 587 context_->getShaderiv(shader, GL_COMPILE_STATUS, &compile_status); | 605 context_->getShaderiv(shader, GL_COMPILE_STATUS, &compile_status); |
| 588 if (!compile_status) { | 606 if (!compile_status) { |
| 589 LOG(ERROR) << std::string(context_->getShaderInfoLog(shader).utf8()); | 607 LOG(ERROR) << std::string(context_->getShaderInfoLog(shader).utf8()); |
| 590 return 0; | 608 return 0; |
| 591 } | 609 } |
| 592 return shader.Detach(); | 610 return shader.Detach(); |
| 593 } | 611 } |
| 594 | 612 |
| 595 } // namespace content | 613 } // namespace content |
| OLD | NEW |