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 <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 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 const gfx::Size& dst_size, | 266 const gfx::Size& dst_size, |
267 unsigned char* out, | 267 unsigned char* out, |
268 const base::Callback<void(bool)>& callback); | 268 const base::Callback<void(bool)>& callback); |
269 | 269 |
270 void ReadbackTextureSync(WebGLId texture, | 270 void ReadbackTextureSync(WebGLId texture, |
271 const gfx::Size& size, | 271 const gfx::Size& size, |
272 unsigned char* out); | 272 unsigned char* out); |
273 | 273 |
274 WebKit::WebGLId CopyAndScaleTexture(WebGLId texture, | 274 WebKit::WebGLId CopyAndScaleTexture(WebGLId texture, |
275 const gfx::Size& src_size, | 275 const gfx::Size& src_size, |
| 276 const gfx::Rect& src_rect, |
276 const gfx::Size& dst_size, | 277 const gfx::Size& dst_size, |
277 bool vertically_flip_texture); | 278 bool vertically_flip_texture); |
278 | 279 |
279 private: | 280 private: |
280 // A single request to CropScaleReadbackAndCleanTexture. | 281 // A single request to CropScaleReadbackAndCleanTexture. |
281 // Thread-safety notes: the main thread creates instances of this class. The | 282 // Thread-safety notes: the main thread creates instances of this class. The |
282 // main thread can cancel the request, before it's handled by the helper | 283 // main thread can cancel the request, before it's handled by the helper |
283 // thread, by resetting the texture and pixels fields. Alternatively, the | 284 // thread, by resetting the texture and pixels fields. Alternatively, the |
284 // thread marks that it handles the request by resetting the pixels field | 285 // thread marks that it handles the request by resetting the pixels field |
285 // (meaning it guarantees that the callback with be called). | 286 // (meaning it guarantees that the callback with be called). |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 size.width(), | 575 size.width(), |
575 size.height(), | 576 size.height(), |
576 GL_RGBA, | 577 GL_RGBA, |
577 GL_UNSIGNED_BYTE, | 578 GL_UNSIGNED_BYTE, |
578 out); | 579 out); |
579 } | 580 } |
580 | 581 |
581 WebKit::WebGLId GLHelper::CopyTextureToImpl::CopyAndScaleTexture( | 582 WebKit::WebGLId GLHelper::CopyTextureToImpl::CopyAndScaleTexture( |
582 WebGLId src_texture, | 583 WebGLId src_texture, |
583 const gfx::Size& src_size, | 584 const gfx::Size& src_size, |
| 585 const gfx::Rect& src_rect, |
584 const gfx::Size& dst_size, | 586 const gfx::Size& dst_size, |
585 bool vertically_flip_texture) { | 587 bool vertically_flip_texture) { |
586 return ScaleTexture(src_texture, | 588 return ScaleTexture(src_texture, |
587 src_size, | 589 src_size, |
588 gfx::Rect(src_size), | 590 src_rect, |
589 dst_size, | 591 dst_size, |
590 vertically_flip_texture); | 592 vertically_flip_texture); |
591 } | 593 } |
592 | 594 |
593 void GLHelper::CopyTextureToImpl::ReadBackFramebuffer( | 595 void GLHelper::CopyTextureToImpl::ReadBackFramebuffer( |
594 scoped_refptr<Request> request, | 596 scoped_refptr<Request> request, |
595 WebGraphicsContext3D* context, | 597 WebGraphicsContext3D* context, |
596 scoped_refptr<base::TaskRunner> reply_loop) { | 598 scoped_refptr<base::TaskRunner> reply_loop) { |
597 DCHECK(context); | 599 DCHECK(context); |
598 if (!context->makeContextCurrent() || context->isContextLost()) { | 600 if (!context->makeContextCurrent() || context->isContextLost()) { |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
746 copy_texture_to_impl_->ReadbackTextureSync(texture, | 748 copy_texture_to_impl_->ReadbackTextureSync(texture, |
747 size, | 749 size, |
748 out); | 750 out); |
749 } | 751 } |
750 | 752 |
751 WebKit::WebGLId GLHelper::CopyTexture(WebKit::WebGLId texture, | 753 WebKit::WebGLId GLHelper::CopyTexture(WebKit::WebGLId texture, |
752 const gfx::Size& size) { | 754 const gfx::Size& size) { |
753 InitCopyTextToImpl(); | 755 InitCopyTextToImpl(); |
754 return copy_texture_to_impl_->CopyAndScaleTexture(texture, | 756 return copy_texture_to_impl_->CopyAndScaleTexture(texture, |
755 size, | 757 size, |
| 758 gfx::Rect(size), |
756 size, | 759 size, |
757 false); | 760 false); |
758 } | 761 } |
759 | 762 |
760 WebKit::WebGLId GLHelper::CopyAndScaleTexture(WebKit::WebGLId texture, | 763 WebKit::WebGLId GLHelper::CopyAndScaleTexture(WebKit::WebGLId texture, |
761 const gfx::Size& src_size, | 764 const gfx::Size& src_size, |
| 765 const gfx::Rect& src_rect, |
762 const gfx::Size& dst_size, | 766 const gfx::Size& dst_size, |
763 bool vertically_flip_texture) { | 767 bool vertically_flip_texture) { |
764 InitCopyTextToImpl(); | 768 InitCopyTextToImpl(); |
765 return copy_texture_to_impl_->CopyAndScaleTexture(texture, | 769 return copy_texture_to_impl_->CopyAndScaleTexture(texture, |
766 src_size, | 770 src_size, |
| 771 src_rect, |
767 dst_size, | 772 dst_size, |
768 vertically_flip_texture); | 773 vertically_flip_texture); |
769 } | 774 } |
770 | 775 |
771 WebGLId GLHelper::CompileShaderFromSource( | 776 WebGLId GLHelper::CompileShaderFromSource( |
772 const WebKit::WGC3Dchar* source, | 777 const WebKit::WGC3Dchar* source, |
773 WebKit::WGC3Denum type) { | 778 WebKit::WGC3Denum type) { |
774 ScopedShader shader(context_, context_->createShader(type)); | 779 ScopedShader shader(context_, context_->createShader(type)); |
775 context_->shaderSource(shader, source); | 780 context_->shaderSource(shader, source); |
776 context_->compileShader(shader); | 781 context_->compileShader(shader); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
812 context_->copyTexSubImage2D(GL_TEXTURE_2D, 0, | 817 context_->copyTexSubImage2D(GL_TEXTURE_2D, 0, |
813 rect.x(), rect.y(), | 818 rect.x(), rect.y(), |
814 rect.x(), rect.y(), | 819 rect.x(), rect.y(), |
815 rect.width(), rect.height()); | 820 rect.width(), rect.height()); |
816 } | 821 } |
817 context_->flush(); | 822 context_->flush(); |
818 } | 823 } |
819 } | 824 } |
820 | 825 |
821 } // namespace content | 826 } // namespace content |
OLD | NEW |