| 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 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/debug/trace_event.h" | 11 #include "base/debug/trace_event.h" |
| 12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 18 #include "content/common/gpu/client/gl_helper_scaling.h" | 18 #include "content/common/gpu/client/gl_helper_scaling.h" |
| 19 #include "gpu/command_buffer/client/context_support.h" | 19 #include "gpu/command_buffer/client/context_support.h" |
| 20 #include "gpu/command_buffer/common/mailbox.h" | 20 #include "gpu/command_buffer/common/mailbox.h" |
| 21 #include "media/base/video_frame.h" | 21 #include "media/base/video_frame.h" |
| 22 #include "media/base/video_util.h" | 22 #include "media/base/video_util.h" |
| 23 #include "third_party/WebKit/public/platform/WebCString.h" | 23 #include "third_party/WebKit/public/platform/WebCString.h" |
| 24 #include "third_party/skia/include/core/SkRegion.h" | 24 #include "third_party/skia/include/core/SkRegion.h" |
| 25 #include "ui/gfx/rect.h" | 25 #include "ui/gfx/rect.h" |
| 26 #include "ui/gfx/size.h" | 26 #include "ui/gfx/size.h" |
| 27 #include "ui/gl/gl_bindings.h" | 27 #include "ui/gl/gl_bindings.h" |
| 28 | 28 |
| 29 using WebKit::WebGLId; | 29 using blink::WebGLId; |
| 30 using WebKit::WebGraphicsContext3D; | 30 using blink::WebGraphicsContext3D; |
| 31 | 31 |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 // Helper class for allocating and holding an RGBA texture of a given | 34 // Helper class for allocating and holding an RGBA texture of a given |
| 35 // size and an associated framebuffer. | 35 // size and an associated framebuffer. |
| 36 class TextureFrameBufferPair { | 36 class TextureFrameBufferPair { |
| 37 public: | 37 public: |
| 38 TextureFrameBufferPair(WebGraphicsContext3D* context, | 38 TextureFrameBufferPair(WebGraphicsContext3D* context, |
| 39 gfx::Size size) | 39 gfx::Size size) |
| 40 : texture_(context, context->createTexture()), | 40 : texture_(context, context->createTexture()), |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 // scaler and an associated frame buffer. This is inteded to be used | 77 // scaler and an associated frame buffer. This is inteded to be used |
| 78 // when the output of a scaler is to be sent to a readback. | 78 // when the output of a scaler is to be sent to a readback. |
| 79 class ScalerHolder { | 79 class ScalerHolder { |
| 80 public: | 80 public: |
| 81 ScalerHolder(WebGraphicsContext3D* context, | 81 ScalerHolder(WebGraphicsContext3D* context, |
| 82 content::GLHelper::ScalerInterface *scaler) | 82 content::GLHelper::ScalerInterface *scaler) |
| 83 : texture_and_framebuffer_(context, scaler->DstSize()), | 83 : texture_and_framebuffer_(context, scaler->DstSize()), |
| 84 scaler_(scaler) { | 84 scaler_(scaler) { |
| 85 } | 85 } |
| 86 | 86 |
| 87 void Scale(WebKit::WebGLId src_texture) { | 87 void Scale(blink::WebGLId src_texture) { |
| 88 scaler_->Scale(src_texture, texture_and_framebuffer_.texture()); | 88 scaler_->Scale(src_texture, texture_and_framebuffer_.texture()); |
| 89 } | 89 } |
| 90 | 90 |
| 91 content::GLHelper::ScalerInterface* scaler() const { return scaler_.get(); } | 91 content::GLHelper::ScalerInterface* scaler() const { return scaler_.get(); } |
| 92 TextureFrameBufferPair *texture_and_framebuffer() { | 92 TextureFrameBufferPair *texture_and_framebuffer() { |
| 93 return &texture_and_framebuffer_; | 93 return &texture_and_framebuffer_; |
| 94 } | 94 } |
| 95 WebGLId texture() const { return texture_and_framebuffer_.texture(); } | 95 WebGLId texture() const { return texture_and_framebuffer_.texture(); } |
| 96 | 96 |
| 97 private: | 97 private: |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 unsigned char* out, | 155 unsigned char* out, |
| 156 const base::Callback<void(bool)>& callback); | 156 const base::Callback<void(bool)>& callback); |
| 157 | 157 |
| 158 void ReadbackPlane(TextureFrameBufferPair* source, | 158 void ReadbackPlane(TextureFrameBufferPair* source, |
| 159 const scoped_refptr<media::VideoFrame>& target, | 159 const scoped_refptr<media::VideoFrame>& target, |
| 160 int plane, | 160 int plane, |
| 161 int size_shift, | 161 int size_shift, |
| 162 const gfx::Rect& dst_subrect, | 162 const gfx::Rect& dst_subrect, |
| 163 const base::Callback<void(bool)>& callback); | 163 const base::Callback<void(bool)>& callback); |
| 164 | 164 |
| 165 WebKit::WebGLId CopyAndScaleTexture(WebGLId texture, | 165 blink::WebGLId CopyAndScaleTexture(WebGLId texture, |
| 166 const gfx::Size& src_size, | 166 const gfx::Size& src_size, |
| 167 const gfx::Size& dst_size, | 167 const gfx::Size& dst_size, |
| 168 bool vertically_flip_texture, | 168 bool vertically_flip_texture, |
| 169 GLHelper::ScalerQuality quality); | 169 GLHelper::ScalerQuality quality); |
| 170 | 170 |
| 171 ReadbackYUVInterface* CreateReadbackPipelineYUV( | 171 ReadbackYUVInterface* CreateReadbackPipelineYUV( |
| 172 GLHelper::ScalerQuality quality, | 172 GLHelper::ScalerQuality quality, |
| 173 const gfx::Size& src_size, | 173 const gfx::Size& src_size, |
| 174 const gfx::Rect& src_subrect, | 174 const gfx::Rect& src_subrect, |
| 175 const gfx::Size& dst_size, | 175 const gfx::Size& dst_size, |
| 176 const gfx::Rect& dst_subrect, | 176 const gfx::Rect& dst_subrect, |
| 177 bool flip_vertically, | 177 bool flip_vertically, |
| 178 bool use_mrt); | 178 bool use_mrt); |
| 179 | 179 |
| 180 // Returns the maximum number of draw buffers available, | 180 // Returns the maximum number of draw buffers available, |
| 181 // 0 if GL_EXT_draw_buffers is not available. | 181 // 0 if GL_EXT_draw_buffers is not available. |
| 182 WebKit::WGC3Dint MaxDrawBuffers() const { | 182 blink::WGC3Dint MaxDrawBuffers() const { |
| 183 return max_draw_buffers_; | 183 return max_draw_buffers_; |
| 184 } | 184 } |
| 185 | 185 |
| 186 private: | 186 private: |
| 187 // A single request to CropScaleReadbackAndCleanTexture. | 187 // A single request to CropScaleReadbackAndCleanTexture. |
| 188 // The main thread can cancel the request, before it's handled by the helper | 188 // The main thread can cancel the request, before it's handled by the helper |
| 189 // thread, by resetting the texture and pixels fields. Alternatively, the | 189 // thread, by resetting the texture and pixels fields. Alternatively, the |
| 190 // thread marks that it handles the request by resetting the pixels field | 190 // thread marks that it handles the request by resetting the pixels field |
| 191 // (meaning it guarantees that the callback with be called). | 191 // (meaning it guarantees that the callback with be called). |
| 192 // In either case, the callback must be called exactly once, and the texture | 192 // In either case, the callback must be called exactly once, and the texture |
| (...skipping 14 matching lines...) Expand all Loading... |
| 207 query(0) { | 207 query(0) { |
| 208 } | 208 } |
| 209 | 209 |
| 210 bool done; | 210 bool done; |
| 211 gfx::Size size; | 211 gfx::Size size; |
| 212 int bytes_per_row; | 212 int bytes_per_row; |
| 213 int row_stride_bytes; | 213 int row_stride_bytes; |
| 214 unsigned char* pixels; | 214 unsigned char* pixels; |
| 215 base::Callback<void(bool)> callback; | 215 base::Callback<void(bool)> callback; |
| 216 GLuint buffer; | 216 GLuint buffer; |
| 217 WebKit::WebGLId query; | 217 blink::WebGLId query; |
| 218 }; | 218 }; |
| 219 | 219 |
| 220 // A readback pipeline that also converts the data to YUV before | 220 // A readback pipeline that also converts the data to YUV before |
| 221 // reading it back. | 221 // reading it back. |
| 222 class ReadbackYUVImpl : public ReadbackYUVInterface { | 222 class ReadbackYUVImpl : public ReadbackYUVInterface { |
| 223 public: | 223 public: |
| 224 ReadbackYUVImpl(WebGraphicsContext3D* context, | 224 ReadbackYUVImpl(WebGraphicsContext3D* context, |
| 225 CopyTextureToImpl* copy_impl, | 225 CopyTextureToImpl* copy_impl, |
| 226 GLHelperScaling* scaler_impl, | 226 GLHelperScaling* scaler_impl, |
| 227 GLHelper::ScalerQuality quality, | 227 GLHelper::ScalerQuality quality, |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 | 318 |
| 319 WebGraphicsContext3D* context_; | 319 WebGraphicsContext3D* context_; |
| 320 gpu::ContextSupport* context_support_; | 320 gpu::ContextSupport* context_support_; |
| 321 GLHelper* helper_; | 321 GLHelper* helper_; |
| 322 | 322 |
| 323 // A scoped flush that will ensure all resource deletions are flushed when | 323 // A scoped flush that will ensure all resource deletions are flushed when |
| 324 // this object is destroyed. Must be declared before other Scoped* fields. | 324 // this object is destroyed. Must be declared before other Scoped* fields. |
| 325 ScopedFlush flush_; | 325 ScopedFlush flush_; |
| 326 | 326 |
| 327 std::queue<Request*> request_queue_; | 327 std::queue<Request*> request_queue_; |
| 328 WebKit::WGC3Dint max_draw_buffers_; | 328 blink::WGC3Dint max_draw_buffers_; |
| 329 }; | 329 }; |
| 330 | 330 |
| 331 GLHelper::ScalerInterface* GLHelper::CreateScaler( | 331 GLHelper::ScalerInterface* GLHelper::CreateScaler( |
| 332 ScalerQuality quality, | 332 ScalerQuality quality, |
| 333 const gfx::Size& src_size, | 333 const gfx::Size& src_size, |
| 334 const gfx::Rect& src_subrect, | 334 const gfx::Rect& src_subrect, |
| 335 const gfx::Size& dst_size, | 335 const gfx::Size& dst_size, |
| 336 bool vertically_flip_texture, | 336 bool vertically_flip_texture, |
| 337 bool swizzle) { | 337 bool swizzle) { |
| 338 InitScalerImpl(); | 338 InitScalerImpl(); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 0); | 461 0); |
| 462 context_->readPixels(src_rect.x(), | 462 context_->readPixels(src_rect.x(), |
| 463 src_rect.y(), | 463 src_rect.y(), |
| 464 src_rect.width(), | 464 src_rect.width(), |
| 465 src_rect.height(), | 465 src_rect.height(), |
| 466 GL_RGBA, | 466 GL_RGBA, |
| 467 GL_UNSIGNED_BYTE, | 467 GL_UNSIGNED_BYTE, |
| 468 out); | 468 out); |
| 469 } | 469 } |
| 470 | 470 |
| 471 WebKit::WebGLId GLHelper::CopyTextureToImpl::CopyAndScaleTexture( | 471 blink::WebGLId GLHelper::CopyTextureToImpl::CopyAndScaleTexture( |
| 472 WebGLId src_texture, | 472 WebGLId src_texture, |
| 473 const gfx::Size& src_size, | 473 const gfx::Size& src_size, |
| 474 const gfx::Size& dst_size, | 474 const gfx::Size& dst_size, |
| 475 bool vertically_flip_texture, | 475 bool vertically_flip_texture, |
| 476 GLHelper::ScalerQuality quality) { | 476 GLHelper::ScalerQuality quality) { |
| 477 return ScaleTexture(src_texture, | 477 return ScaleTexture(src_texture, |
| 478 src_size, | 478 src_size, |
| 479 gfx::Rect(src_size), | 479 gfx::Rect(src_size), |
| 480 dst_size, | 480 dst_size, |
| 481 vertically_flip_texture, | 481 vertically_flip_texture, |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 delete request; | 543 delete request; |
| 544 } | 544 } |
| 545 | 545 |
| 546 void GLHelper::CopyTextureToImpl::CancelRequests() { | 546 void GLHelper::CopyTextureToImpl::CancelRequests() { |
| 547 while (!request_queue_.empty()) { | 547 while (!request_queue_.empty()) { |
| 548 Request* request = request_queue_.front(); | 548 Request* request = request_queue_.front(); |
| 549 FinishRequest(request, false); | 549 FinishRequest(request, false); |
| 550 } | 550 } |
| 551 } | 551 } |
| 552 | 552 |
| 553 GLHelper::GLHelper(WebKit::WebGraphicsContext3D* context, | 553 GLHelper::GLHelper(blink::WebGraphicsContext3D* context, |
| 554 gpu::ContextSupport* context_support) | 554 gpu::ContextSupport* context_support) |
| 555 : context_(context), | 555 : context_(context), |
| 556 context_support_(context_support) { | 556 context_support_(context_support) { |
| 557 } | 557 } |
| 558 | 558 |
| 559 GLHelper::~GLHelper() { | 559 GLHelper::~GLHelper() { |
| 560 } | 560 } |
| 561 | 561 |
| 562 void GLHelper::CropScaleReadbackAndCleanTexture( | 562 void GLHelper::CropScaleReadbackAndCleanTexture( |
| 563 WebGLId src_texture, | 563 WebGLId src_texture, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 584 const gfx::Rect& src_subrect, | 584 const gfx::Rect& src_subrect, |
| 585 const gfx::Size& dst_size, | 585 const gfx::Size& dst_size, |
| 586 unsigned char* out, | 586 unsigned char* out, |
| 587 const base::Callback<void(bool)>& callback) { | 587 const base::Callback<void(bool)>& callback) { |
| 588 WebGLId mailbox_texture = ConsumeMailboxToTexture(src_mailbox, sync_point); | 588 WebGLId mailbox_texture = ConsumeMailboxToTexture(src_mailbox, sync_point); |
| 589 CropScaleReadbackAndCleanTexture( | 589 CropScaleReadbackAndCleanTexture( |
| 590 mailbox_texture, src_size, src_subrect, dst_size, out, callback); | 590 mailbox_texture, src_size, src_subrect, dst_size, out, callback); |
| 591 context_->deleteTexture(mailbox_texture); | 591 context_->deleteTexture(mailbox_texture); |
| 592 } | 592 } |
| 593 | 593 |
| 594 void GLHelper::ReadbackTextureSync(WebKit::WebGLId texture, | 594 void GLHelper::ReadbackTextureSync(blink::WebGLId texture, |
| 595 const gfx::Rect& src_rect, | 595 const gfx::Rect& src_rect, |
| 596 unsigned char* out) { | 596 unsigned char* out) { |
| 597 InitCopyTextToImpl(); | 597 InitCopyTextToImpl(); |
| 598 copy_texture_to_impl_->ReadbackTextureSync(texture, | 598 copy_texture_to_impl_->ReadbackTextureSync(texture, |
| 599 src_rect, | 599 src_rect, |
| 600 out); | 600 out); |
| 601 } | 601 } |
| 602 | 602 |
| 603 WebKit::WebGLId GLHelper::CopyTexture(WebKit::WebGLId texture, | 603 blink::WebGLId GLHelper::CopyTexture(blink::WebGLId texture, |
| 604 const gfx::Size& size) { | 604 const gfx::Size& size) { |
| 605 InitCopyTextToImpl(); | 605 InitCopyTextToImpl(); |
| 606 return copy_texture_to_impl_->CopyAndScaleTexture( | 606 return copy_texture_to_impl_->CopyAndScaleTexture( |
| 607 texture, | 607 texture, |
| 608 size, | 608 size, |
| 609 size, | 609 size, |
| 610 false, | 610 false, |
| 611 GLHelper::SCALER_QUALITY_FAST); | 611 GLHelper::SCALER_QUALITY_FAST); |
| 612 } | 612 } |
| 613 | 613 |
| 614 WebKit::WebGLId GLHelper::CopyAndScaleTexture( | 614 blink::WebGLId GLHelper::CopyAndScaleTexture( |
| 615 WebKit::WebGLId texture, | 615 blink::WebGLId texture, |
| 616 const gfx::Size& src_size, | 616 const gfx::Size& src_size, |
| 617 const gfx::Size& dst_size, | 617 const gfx::Size& dst_size, |
| 618 bool vertically_flip_texture, | 618 bool vertically_flip_texture, |
| 619 ScalerQuality quality) { | 619 ScalerQuality quality) { |
| 620 InitCopyTextToImpl(); | 620 InitCopyTextToImpl(); |
| 621 return copy_texture_to_impl_->CopyAndScaleTexture(texture, | 621 return copy_texture_to_impl_->CopyAndScaleTexture(texture, |
| 622 src_size, | 622 src_size, |
| 623 dst_size, | 623 dst_size, |
| 624 vertically_flip_texture, | 624 vertically_flip_texture, |
| 625 quality); | 625 quality); |
| 626 } | 626 } |
| 627 | 627 |
| 628 WebGLId GLHelper::CompileShaderFromSource( | 628 WebGLId GLHelper::CompileShaderFromSource( |
| 629 const WebKit::WGC3Dchar* source, | 629 const blink::WGC3Dchar* source, |
| 630 WebKit::WGC3Denum type) { | 630 blink::WGC3Denum type) { |
| 631 ScopedShader shader(context_, context_->createShader(type)); | 631 ScopedShader shader(context_, context_->createShader(type)); |
| 632 context_->shaderSource(shader, source); | 632 context_->shaderSource(shader, source); |
| 633 context_->compileShader(shader); | 633 context_->compileShader(shader); |
| 634 WebKit::WGC3Dint compile_status = 0; | 634 blink::WGC3Dint compile_status = 0; |
| 635 context_->getShaderiv(shader, GL_COMPILE_STATUS, &compile_status); | 635 context_->getShaderiv(shader, GL_COMPILE_STATUS, &compile_status); |
| 636 if (!compile_status) { | 636 if (!compile_status) { |
| 637 LOG(ERROR) << std::string(context_->getShaderInfoLog(shader).utf8()); | 637 LOG(ERROR) << std::string(context_->getShaderInfoLog(shader).utf8()); |
| 638 return 0; | 638 return 0; |
| 639 } | 639 } |
| 640 return shader.Detach(); | 640 return shader.Detach(); |
| 641 } | 641 } |
| 642 | 642 |
| 643 void GLHelper::InitCopyTextToImpl() { | 643 void GLHelper::InitCopyTextToImpl() { |
| 644 // Lazily initialize |copy_texture_to_impl_| | 644 // Lazily initialize |copy_texture_to_impl_| |
| 645 if (!copy_texture_to_impl_) | 645 if (!copy_texture_to_impl_) |
| 646 copy_texture_to_impl_.reset( | 646 copy_texture_to_impl_.reset( |
| 647 new CopyTextureToImpl(context_, context_support_, this)); | 647 new CopyTextureToImpl(context_, context_support_, this)); |
| 648 } | 648 } |
| 649 | 649 |
| 650 void GLHelper::InitScalerImpl() { | 650 void GLHelper::InitScalerImpl() { |
| 651 // Lazily initialize |scaler_impl_| | 651 // Lazily initialize |scaler_impl_| |
| 652 if (!scaler_impl_) | 652 if (!scaler_impl_) |
| 653 scaler_impl_.reset(new GLHelperScaling(context_, this)); | 653 scaler_impl_.reset(new GLHelperScaling(context_, this)); |
| 654 } | 654 } |
| 655 | 655 |
| 656 WebKit::WGC3Dint GLHelper::MaxDrawBuffers() { | 656 blink::WGC3Dint GLHelper::MaxDrawBuffers() { |
| 657 InitCopyTextToImpl(); | 657 InitCopyTextToImpl(); |
| 658 return copy_texture_to_impl_->MaxDrawBuffers(); | 658 return copy_texture_to_impl_->MaxDrawBuffers(); |
| 659 } | 659 } |
| 660 | 660 |
| 661 void GLHelper::CopySubBufferDamage(WebKit::WebGLId texture, | 661 void GLHelper::CopySubBufferDamage(blink::WebGLId texture, |
| 662 WebKit::WebGLId previous_texture, | 662 blink::WebGLId previous_texture, |
| 663 const SkRegion& new_damage, | 663 const SkRegion& new_damage, |
| 664 const SkRegion& old_damage) { | 664 const SkRegion& old_damage) { |
| 665 SkRegion region(old_damage); | 665 SkRegion region(old_damage); |
| 666 if (region.op(new_damage, SkRegion::kDifference_Op)) { | 666 if (region.op(new_damage, SkRegion::kDifference_Op)) { |
| 667 ScopedFramebuffer dst_framebuffer(context_, | 667 ScopedFramebuffer dst_framebuffer(context_, |
| 668 context_->createFramebuffer()); | 668 context_->createFramebuffer()); |
| 669 ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder(context_, | 669 ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder(context_, |
| 670 dst_framebuffer); | 670 dst_framebuffer); |
| 671 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(context_, texture); | 671 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(context_, texture); |
| 672 context_->framebufferTexture2D(GL_FRAMEBUFFER, | 672 context_->framebufferTexture2D(GL_FRAMEBUFFER, |
| 673 GL_COLOR_ATTACHMENT0, | 673 GL_COLOR_ATTACHMENT0, |
| 674 GL_TEXTURE_2D, | 674 GL_TEXTURE_2D, |
| 675 previous_texture, | 675 previous_texture, |
| 676 0); | 676 0); |
| 677 for (SkRegion::Iterator it(region); !it.done(); it.next()) { | 677 for (SkRegion::Iterator it(region); !it.done(); it.next()) { |
| 678 const SkIRect& rect = it.rect(); | 678 const SkIRect& rect = it.rect(); |
| 679 context_->copyTexSubImage2D(GL_TEXTURE_2D, 0, | 679 context_->copyTexSubImage2D(GL_TEXTURE_2D, 0, |
| 680 rect.x(), rect.y(), | 680 rect.x(), rect.y(), |
| 681 rect.x(), rect.y(), | 681 rect.x(), rect.y(), |
| 682 rect.width(), rect.height()); | 682 rect.width(), rect.height()); |
| 683 } | 683 } |
| 684 context_->flush(); | 684 context_->flush(); |
| 685 } | 685 } |
| 686 } | 686 } |
| 687 | 687 |
| 688 WebKit::WebGLId GLHelper::CreateTexture() { | 688 blink::WebGLId GLHelper::CreateTexture() { |
| 689 WebKit::WebGLId texture = context_->createTexture(); | 689 blink::WebGLId texture = context_->createTexture(); |
| 690 content::ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(context_, | 690 content::ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(context_, |
| 691 texture); | 691 texture); |
| 692 context_->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 692 context_->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 693 context_->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 693 context_->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 694 context_->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 694 context_->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 695 context_->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 695 context_->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 696 return texture; | 696 return texture; |
| 697 } | 697 } |
| 698 | 698 |
| 699 WebKit::WebGLId GLHelper::ConsumeMailboxToTexture(const gpu::Mailbox& mailbox, | 699 blink::WebGLId GLHelper::ConsumeMailboxToTexture(const gpu::Mailbox& mailbox, |
| 700 uint32 sync_point) { | 700 uint32 sync_point) { |
| 701 if (mailbox.IsZero()) | 701 if (mailbox.IsZero()) |
| 702 return 0; | 702 return 0; |
| 703 if (sync_point) | 703 if (sync_point) |
| 704 context_->waitSyncPoint(sync_point); | 704 context_->waitSyncPoint(sync_point); |
| 705 WebKit::WebGLId texture = CreateTexture(); | 705 blink::WebGLId texture = CreateTexture(); |
| 706 content::ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(context_, | 706 content::ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(context_, |
| 707 texture); | 707 texture); |
| 708 context_->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); | 708 context_->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); |
| 709 return texture; | 709 return texture; |
| 710 } | 710 } |
| 711 | 711 |
| 712 void GLHelper::ResizeTexture(WebKit::WebGLId texture, const gfx::Size& size) { | 712 void GLHelper::ResizeTexture(blink::WebGLId texture, const gfx::Size& size) { |
| 713 content::ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(context_, texture); | 713 content::ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(context_, texture); |
| 714 context_->texImage2D(GL_TEXTURE_2D, 0, GL_RGB, | 714 context_->texImage2D(GL_TEXTURE_2D, 0, GL_RGB, |
| 715 size.width(), size.height(), 0, | 715 size.width(), size.height(), 0, |
| 716 GL_RGB, GL_UNSIGNED_BYTE, NULL); | 716 GL_RGB, GL_UNSIGNED_BYTE, NULL); |
| 717 } | 717 } |
| 718 | 718 |
| 719 void GLHelper::CopyTextureSubImage(WebKit::WebGLId texture, | 719 void GLHelper::CopyTextureSubImage(blink::WebGLId texture, |
| 720 const gfx::Rect& rect) { | 720 const gfx::Rect& rect) { |
| 721 content::ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(context_, texture); | 721 content::ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(context_, texture); |
| 722 context_->copyTexSubImage2D(GL_TEXTURE_2D, 0, | 722 context_->copyTexSubImage2D(GL_TEXTURE_2D, 0, |
| 723 rect.x(), rect.y(), | 723 rect.x(), rect.y(), |
| 724 rect.x(), rect.y(), rect.width(), rect.height()); | 724 rect.x(), rect.y(), rect.width(), rect.height()); |
| 725 } | 725 } |
| 726 | 726 |
| 727 void GLHelper::CopyTextureFullImage(WebKit::WebGLId texture, | 727 void GLHelper::CopyTextureFullImage(blink::WebGLId texture, |
| 728 const gfx::Size& size) { | 728 const gfx::Size& size) { |
| 729 content::ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(context_, texture); | 729 content::ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(context_, texture); |
| 730 context_->copyTexImage2D(GL_TEXTURE_2D, 0, | 730 context_->copyTexImage2D(GL_TEXTURE_2D, 0, |
| 731 GL_RGB, | 731 GL_RGB, |
| 732 0, 0, | 732 0, 0, |
| 733 size.width(), size.height(), 0); | 733 size.width(), size.height(), 0); |
| 734 } | 734 } |
| 735 | 735 |
| 736 void GLHelper::CopyTextureToImpl::ReadbackPlane( | 736 void GLHelper::CopyTextureToImpl::ReadbackPlane( |
| 737 TextureFrameBufferPair* source, | 737 TextureFrameBufferPair* source, |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 960 // pass, which pass1_shader_ can do just as well, so let's skip | 960 // pass, which pass1_shader_ can do just as well, so let's skip |
| 961 // the actual scaling in that case. | 961 // the actual scaling in that case. |
| 962 texture = mailbox_texture; | 962 texture = mailbox_texture; |
| 963 } else { | 963 } else { |
| 964 // Scale texture to right size. | 964 // Scale texture to right size. |
| 965 scaler_.Scale(mailbox_texture); | 965 scaler_.Scale(mailbox_texture); |
| 966 texture = scaler_.texture(); | 966 texture = scaler_.texture(); |
| 967 } | 967 } |
| 968 | 968 |
| 969 | 969 |
| 970 std::vector<WebKit::WebGLId> outputs(2); | 970 std::vector<blink::WebGLId> outputs(2); |
| 971 // Convert the scaled texture in to Y, U and V planes. | 971 // Convert the scaled texture in to Y, U and V planes. |
| 972 outputs[0] = y_.texture(); | 972 outputs[0] = y_.texture(); |
| 973 outputs[1] = uv_; | 973 outputs[1] = uv_; |
| 974 pass1_shader_->Execute(texture, outputs); | 974 pass1_shader_->Execute(texture, outputs); |
| 975 | 975 |
| 976 context_->deleteTexture(mailbox_texture); | 976 context_->deleteTexture(mailbox_texture); |
| 977 | 977 |
| 978 outputs[0] = u_.texture(); | 978 outputs[0] = u_.texture(); |
| 979 outputs[1] = v_.texture(); | 979 outputs[1] = v_.texture(); |
| 980 pass2_shader_->Execute(uv_, outputs); | 980 pass2_shader_->Execute(uv_, outputs); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1059 quality, | 1059 quality, |
| 1060 src_size, | 1060 src_size, |
| 1061 src_subrect, | 1061 src_subrect, |
| 1062 dst_size, | 1062 dst_size, |
| 1063 dst_subrect, | 1063 dst_subrect, |
| 1064 flip_vertically, | 1064 flip_vertically, |
| 1065 use_mrt); | 1065 use_mrt); |
| 1066 } | 1066 } |
| 1067 | 1067 |
| 1068 } // namespace content | 1068 } // namespace content |
| OLD | NEW |