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

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

Issue 10910242: Makes copying layers clone external textures. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Tweaks Created 8 years, 3 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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 252
253 void InitBuffer(); 253 void InitBuffer();
254 void InitProgram(); 254 void InitProgram();
255 255
256 void CopyTextureTo(WebGLId src_texture, 256 void CopyTextureTo(WebGLId src_texture,
257 const gfx::Size& src_size, 257 const gfx::Size& src_size,
258 const gfx::Rect& src_subrect, 258 const gfx::Rect& src_subrect,
259 const gfx::Size& dst_size, 259 const gfx::Size& dst_size,
260 unsigned char* out, 260 unsigned char* out,
261 const base::Callback<void(bool)>& callback); 261 const base::Callback<void(bool)>& callback);
262
263 WebKit::WebGLId CopyTexture(WebGLId src_texture, const gfx::Size& size);
264
262 private: 265 private:
263 // A single request to CopyTextureTo. 266 // A single request to CopyTextureTo.
264 // Thread-safety notes: the main thread creates instances of this class. The 267 // Thread-safety notes: the main thread creates instances of this class. The
265 // main thread can cancel the request, before it's handled by the helper 268 // main thread can cancel the request, before it's handled by the helper
266 // thread, by resetting the texture and pixels fields. Alternatively, the 269 // thread, by resetting the texture and pixels fields. Alternatively, the
267 // thread marks that it handles the request by resetting the pixels field 270 // thread marks that it handles the request by resetting the pixels field
268 // (meaning it guarantees that the callback with be called). 271 // (meaning it guarantees that the callback with be called).
269 // In either case, the callback must be called exactly once, and the texture 272 // In either case, the callback must be called exactly once, and the texture
270 // must be deleted by the main thread context. 273 // must be deleted by the main thread context.
271 struct Request : public base::RefCountedThreadSafe<Request> { 274 struct Request : public base::RefCountedThreadSafe<Request> {
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 new Request(this, texture, dst_size, out, callback); 507 new Request(this, texture, dst_size, out, callback);
505 request_queue_.push(request); 508 request_queue_.push(request);
506 509
507 g_gl_helper_thread.Pointer()->message_loop_proxy()->PostTask(FROM_HERE, 510 g_gl_helper_thread.Pointer()->message_loop_proxy()->PostTask(FROM_HERE,
508 base::Bind(&ReadBackFramebuffer, 511 base::Bind(&ReadBackFramebuffer,
509 request, 512 request,
510 context_for_thread_, 513 context_for_thread_,
511 base::MessageLoopProxy::current())); 514 base::MessageLoopProxy::current()));
512 } 515 }
513 516
517 WebKit::WebGLId GLHelper::CopyTextureToImpl::CopyTexture(
518 WebGLId src_texture,
519 const gfx::Size& size) {
520 if (!context_for_thread_)
521 return 0;
522 return ScaleTexture(src_texture, size, gfx::Rect(size), size);
523 }
524
514 void GLHelper::CopyTextureToImpl::ReadBackFramebuffer( 525 void GLHelper::CopyTextureToImpl::ReadBackFramebuffer(
515 scoped_refptr<Request> request, 526 scoped_refptr<Request> request,
516 WebGraphicsContext3D* context, 527 WebGraphicsContext3D* context,
517 scoped_refptr<base::TaskRunner> reply_loop) { 528 scoped_refptr<base::TaskRunner> reply_loop) {
518 DCHECK(context); 529 DCHECK(context);
519 if (!context->makeContextCurrent() || context->isContextLost()) { 530 if (!context->makeContextCurrent() || context->isContextLost()) {
520 base::AutoLock auto_lock(request->lock); 531 base::AutoLock auto_lock(request->lock);
521 if (request->pixels) { 532 if (request->pixels) {
522 // Only report failure if the request wasn't canceled (otherwise the 533 // Only report failure if the request wasn't canceled (otherwise the
523 // failure has already been reported). 534 // failure has already been reported).
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 WebGraphicsContext3D* GLHelper::context() const { 654 WebGraphicsContext3D* GLHelper::context() const {
644 return context_; 655 return context_;
645 } 656 }
646 657
647 void GLHelper::CopyTextureTo(WebGLId src_texture, 658 void GLHelper::CopyTextureTo(WebGLId src_texture,
648 const gfx::Size& src_size, 659 const gfx::Size& src_size,
649 const gfx::Rect& src_subrect, 660 const gfx::Rect& src_subrect,
650 const gfx::Size& dst_size, 661 const gfx::Size& dst_size,
651 unsigned char* out, 662 unsigned char* out,
652 const base::Callback<void(bool)>& callback) { 663 const base::Callback<void(bool)>& callback) {
653 // Lazily initialize |copy_texture_to_impl_| 664 InitCopyTextToImpl();
654 if (!copy_texture_to_impl_.get())
655 copy_texture_to_impl_.reset(new CopyTextureToImpl(context_,
656 context_for_thread_,
657 this));
658
659 copy_texture_to_impl_->CopyTextureTo(src_texture, 665 copy_texture_to_impl_->CopyTextureTo(src_texture,
660 src_size, 666 src_size,
661 src_subrect, 667 src_subrect,
662 dst_size, 668 dst_size,
663 out, 669 out,
664 callback); 670 callback);
665 } 671 }
666 672
673 WebKit::WebGLId GLHelper::CopyTexture(WebKit::WebGLId texture,
674 const gfx::Size& size) {
675 InitCopyTextToImpl();
676 return copy_texture_to_impl_->CopyTexture(texture, size);
677 }
678
667 WebGLId GLHelper::CompileShaderFromSource( 679 WebGLId GLHelper::CompileShaderFromSource(
668 const WebKit::WGC3Dchar* source, 680 const WebKit::WGC3Dchar* source,
669 WebKit::WGC3Denum type) { 681 WebKit::WGC3Denum type) {
670 ScopedShader shader(context_, context_->createShader(type)); 682 ScopedShader shader(context_, context_->createShader(type));
671 context_->shaderSource(shader, source); 683 context_->shaderSource(shader, source);
672 context_->compileShader(shader); 684 context_->compileShader(shader);
673 WebKit::WGC3Dint compile_status = 0; 685 WebKit::WGC3Dint compile_status = 0;
674 context_->getShaderiv(shader, GL_COMPILE_STATUS, &compile_status); 686 context_->getShaderiv(shader, GL_COMPILE_STATUS, &compile_status);
675 if (!compile_status) { 687 if (!compile_status) {
676 LOG(ERROR) << std::string(context_->getShaderInfoLog(shader).utf8()); 688 LOG(ERROR) << std::string(context_->getShaderInfoLog(shader).utf8());
677 return 0; 689 return 0;
678 } 690 }
679 return shader.Detach(); 691 return shader.Detach();
680 } 692 }
681 693
694 void GLHelper::InitCopyTextToImpl() {
695 // Lazily initialize |copy_texture_to_impl_|
696 if (!copy_texture_to_impl_.get())
697 copy_texture_to_impl_.reset(new CopyTextureToImpl(context_,
698 context_for_thread_,
699 this));
700
701 }
702
682 } // namespace content 703 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698