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

Side by Side Diff: content/common/gpu/client/gl_helper.cc

Issue 11234008: Enable texture readback support for Android (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Forgot to remove local GLHelper from a method Created 8 years, 2 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
OLDNEW
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 <queue> 7 #include <queue>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 void InitBuffer(); 256 void InitBuffer();
257 void InitProgram(); 257 void InitProgram();
258 258
259 void CopyTextureTo(WebGLId src_texture, 259 void CopyTextureTo(WebGLId src_texture,
260 const gfx::Size& src_size, 260 const gfx::Size& src_size,
261 const gfx::Rect& src_subrect, 261 const gfx::Rect& src_subrect,
262 const gfx::Size& dst_size, 262 const gfx::Size& dst_size,
263 unsigned char* out, 263 unsigned char* out,
264 const base::Callback<void(bool)>& callback); 264 const base::Callback<void(bool)>& callback);
265 265
266 WebKit::WebGLId CopyTexture(WebGLId src_texture, const gfx::Size& size); 266 void SyncCopyRawTextureTo(WebGLId texture,
267 const gfx::Size& size,
268 unsigned char* out);
269
270 WebKit::WebGLId CopyTexture(WebGLId texture,
271 const gfx::Size& src_size,
272 const gfx::Size& dst_size);
267 273
268 private: 274 private:
269 // A single request to CopyTextureTo. 275 // A single request to CopyTextureTo.
270 // Thread-safety notes: the main thread creates instances of this class. The 276 // Thread-safety notes: the main thread creates instances of this class. The
271 // main thread can cancel the request, before it's handled by the helper 277 // main thread can cancel the request, before it's handled by the helper
272 // thread, by resetting the texture and pixels fields. Alternatively, the 278 // thread, by resetting the texture and pixels fields. Alternatively, the
273 // thread marks that it handles the request by resetting the pixels field 279 // thread marks that it handles the request by resetting the pixels field
274 // (meaning it guarantees that the callback with be called). 280 // (meaning it guarantees that the callback with be called).
275 // In either case, the callback must be called exactly once, and the texture 281 // In either case, the callback must be called exactly once, and the texture
276 // must be deleted by the main thread context. 282 // must be deleted by the main thread context.
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 new Request(this, texture, dst_size, out, callback); 516 new Request(this, texture, dst_size, out, callback);
511 request_queue_.push(request); 517 request_queue_.push(request);
512 518
513 g_gl_helper_thread.Pointer()->message_loop_proxy()->PostTask(FROM_HERE, 519 g_gl_helper_thread.Pointer()->message_loop_proxy()->PostTask(FROM_HERE,
514 base::Bind(&ReadBackFramebuffer, 520 base::Bind(&ReadBackFramebuffer,
515 request, 521 request,
516 context_for_thread_, 522 context_for_thread_,
517 base::MessageLoopProxy::current())); 523 base::MessageLoopProxy::current()));
518 } 524 }
519 525
526 void GLHelper::CopyTextureToImpl::SyncCopyRawTextureTo(WebGLId texture,
527 const gfx::Size& size,
528 unsigned char* out) {
529 ScopedFramebuffer dst_framebuffer(context_, context_->createFramebuffer());
530 ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder(
531 context_, dst_framebuffer);
532 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(context_, texture);
533 context_->framebufferTexture2D(GL_FRAMEBUFFER,
534 GL_COLOR_ATTACHMENT0,
535 GL_TEXTURE_2D,
536 texture,
537 0);
538 context_->readPixels(0,
539 0,
540 size.width(),
541 size.height(),
542 GL_RGBA,
543 GL_UNSIGNED_BYTE,
544 out);
545 }
546
520 WebKit::WebGLId GLHelper::CopyTextureToImpl::CopyTexture( 547 WebKit::WebGLId GLHelper::CopyTextureToImpl::CopyTexture(
521 WebGLId src_texture, 548 WebGLId src_texture,
522 const gfx::Size& size) { 549 const gfx::Size& src_size,
523 if (!context_for_thread_) 550 const gfx::Size& dst_size) {
524 return 0; 551 return ScaleTexture(src_texture, src_size, gfx::Rect(src_size), dst_size);
525 return ScaleTexture(src_texture, size, gfx::Rect(size), size);
526 } 552 }
527 553
528 void GLHelper::CopyTextureToImpl::ReadBackFramebuffer( 554 void GLHelper::CopyTextureToImpl::ReadBackFramebuffer(
529 scoped_refptr<Request> request, 555 scoped_refptr<Request> request,
530 WebGraphicsContext3D* context, 556 WebGraphicsContext3D* context,
531 scoped_refptr<base::TaskRunner> reply_loop) { 557 scoped_refptr<base::TaskRunner> reply_loop) {
532 DCHECK(context); 558 DCHECK(context);
533 if (!context->makeContextCurrent() || context->isContextLost()) { 559 if (!context->makeContextCurrent() || context->isContextLost()) {
534 base::AutoLock auto_lock(request->lock); 560 base::AutoLock auto_lock(request->lock);
535 if (request->pixels) { 561 if (request->pixels) {
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 const base::Callback<void(bool)>& callback) { 692 const base::Callback<void(bool)>& callback) {
667 InitCopyTextToImpl(); 693 InitCopyTextToImpl();
668 copy_texture_to_impl_->CopyTextureTo(src_texture, 694 copy_texture_to_impl_->CopyTextureTo(src_texture,
669 src_size, 695 src_size,
670 src_subrect, 696 src_subrect,
671 dst_size, 697 dst_size,
672 out, 698 out,
673 callback); 699 callback);
674 } 700 }
675 701
702 void GLHelper::SyncCopyRawTextureTo(WebKit::WebGLId texture,
703 const gfx::Size& size,
704 unsigned char* out) {
705 InitCopyTextToImpl();
706 copy_texture_to_impl_->SyncCopyRawTextureTo(texture,
707 size,
708 out);
709 }
710
676 WebKit::WebGLId GLHelper::CopyTexture(WebKit::WebGLId texture, 711 WebKit::WebGLId GLHelper::CopyTexture(WebKit::WebGLId texture,
677 const gfx::Size& size) { 712 const gfx::Size& size) {
713 return CopyTexture(texture,
714 size,
715 size);
716 }
717
718 WebKit::WebGLId GLHelper::CopyTexture(WebKit::WebGLId texture,
719 const gfx::Size& src_size,
720 const gfx::Size& dst_size) {
678 InitCopyTextToImpl(); 721 InitCopyTextToImpl();
679 return copy_texture_to_impl_->CopyTexture(texture, size); 722 return copy_texture_to_impl_->CopyTexture(texture, src_size, dst_size);
680 } 723 }
681 724
682 WebGLId GLHelper::CompileShaderFromSource( 725 WebGLId GLHelper::CompileShaderFromSource(
683 const WebKit::WGC3Dchar* source, 726 const WebKit::WGC3Dchar* source,
684 WebKit::WGC3Denum type) { 727 WebKit::WGC3Denum type) {
685 ScopedShader shader(context_, context_->createShader(type)); 728 ScopedShader shader(context_, context_->createShader(type));
686 context_->shaderSource(shader, source); 729 context_->shaderSource(shader, source);
687 context_->compileShader(shader); 730 context_->compileShader(shader);
688 WebKit::WGC3Dint compile_status = 0; 731 WebKit::WGC3Dint compile_status = 0;
689 context_->getShaderiv(shader, GL_COMPILE_STATUS, &compile_status); 732 context_->getShaderiv(shader, GL_COMPILE_STATUS, &compile_status);
690 if (!compile_status) { 733 if (!compile_status) {
691 LOG(ERROR) << std::string(context_->getShaderInfoLog(shader).utf8()); 734 LOG(ERROR) << std::string(context_->getShaderInfoLog(shader).utf8());
692 return 0; 735 return 0;
693 } 736 }
694 return shader.Detach(); 737 return shader.Detach();
695 } 738 }
696 739
697 void GLHelper::InitCopyTextToImpl() { 740 void GLHelper::InitCopyTextToImpl() {
698 // Lazily initialize |copy_texture_to_impl_| 741 // Lazily initialize |copy_texture_to_impl_|
699 if (!copy_texture_to_impl_.get()) 742 if (!copy_texture_to_impl_.get())
700 copy_texture_to_impl_.reset(new CopyTextureToImpl(context_, 743 copy_texture_to_impl_.reset(new CopyTextureToImpl(context_,
701 context_for_thread_, 744 context_for_thread_,
702 this)); 745 this));
703 746
704 } 747 }
705 748
706 } // namespace content 749 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698