| 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/browser/compositor/gl_helper.h" | 5 #include "components/display_compositor/gl_helper.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <queue> | 10 #include <queue> |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
| 18 #include "base/message_loop/message_loop.h" | 18 #include "base/message_loop/message_loop.h" |
| 19 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
| 20 #include "base/time/time.h" | 20 #include "base/time/time.h" |
| 21 #include "base/trace_event/trace_event.h" | 21 #include "base/trace_event/trace_event.h" |
| 22 #include "content/browser/compositor/gl_helper_readback_support.h" | 22 #include "components/display_compositor/gl_helper_readback_support.h" |
| 23 #include "content/browser/compositor/gl_helper_scaling.h" | 23 #include "components/display_compositor/gl_helper_scaling.h" |
| 24 #include "gpu/GLES2/gl2extchromium.h" | 24 #include "gpu/GLES2/gl2extchromium.h" |
| 25 #include "gpu/command_buffer/client/context_support.h" | 25 #include "gpu/command_buffer/client/context_support.h" |
| 26 #include "gpu/command_buffer/common/mailbox.h" | 26 #include "gpu/command_buffer/common/mailbox.h" |
| 27 #include "gpu/command_buffer/common/mailbox_holder.h" | 27 #include "gpu/command_buffer/common/mailbox_holder.h" |
| 28 #include "third_party/skia/include/core/SkRegion.h" | 28 #include "third_party/skia/include/core/SkRegion.h" |
| 29 #include "ui/gfx/geometry/point.h" | 29 #include "ui/gfx/geometry/point.h" |
| 30 #include "ui/gfx/geometry/rect.h" | 30 #include "ui/gfx/geometry/rect.h" |
| 31 #include "ui/gfx/geometry/size.h" | 31 #include "ui/gfx/geometry/size.h" |
| 32 | 32 |
| 33 using gpu::gles2::GLES2Interface; | 33 using gpu::gles2::GLES2Interface; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 45 | 45 |
| 46 DISALLOW_COPY_AND_ASSIGN(ScopedFlush); | 46 DISALLOW_COPY_AND_ASSIGN(ScopedFlush); |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 // Helper class for allocating and holding an RGBA texture of a given | 49 // Helper class for allocating and holding an RGBA texture of a given |
| 50 // size and an associated framebuffer. | 50 // size and an associated framebuffer. |
| 51 class TextureFrameBufferPair { | 51 class TextureFrameBufferPair { |
| 52 public: | 52 public: |
| 53 TextureFrameBufferPair(GLES2Interface* gl, gfx::Size size) | 53 TextureFrameBufferPair(GLES2Interface* gl, gfx::Size size) |
| 54 : texture_(gl), framebuffer_(gl), size_(size) { | 54 : texture_(gl), framebuffer_(gl), size_(size) { |
| 55 content::ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl, texture_); | 55 display_compositor::ScopedTextureBinder<GL_TEXTURE_2D> texture_binder( |
| 56 gl, texture_); |
| 56 gl->TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size.width(), size.height(), 0, | 57 gl->TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size.width(), size.height(), 0, |
| 57 GL_RGBA, GL_UNSIGNED_BYTE, NULL); | 58 GL_RGBA, GL_UNSIGNED_BYTE, NULL); |
| 58 content::ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder( | 59 display_compositor::ScopedFramebufferBinder<GL_FRAMEBUFFER> |
| 59 gl, framebuffer_); | 60 framebuffer_binder(gl, framebuffer_); |
| 60 gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, | 61 gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, |
| 61 GL_TEXTURE_2D, texture_, 0); | 62 GL_TEXTURE_2D, texture_, 0); |
| 62 } | 63 } |
| 63 | 64 |
| 64 GLuint texture() const { return texture_.id(); } | 65 GLuint texture() const { return texture_.id(); } |
| 65 GLuint framebuffer() const { return framebuffer_.id(); } | 66 GLuint framebuffer() const { return framebuffer_.id(); } |
| 66 gfx::Size size() const { return size_; } | 67 gfx::Size size() const { return size_; } |
| 67 | 68 |
| 68 private: | 69 private: |
| 69 content::ScopedTexture texture_; | 70 display_compositor::ScopedTexture texture_; |
| 70 content::ScopedFramebuffer framebuffer_; | 71 display_compositor::ScopedFramebuffer framebuffer_; |
| 71 gfx::Size size_; | 72 gfx::Size size_; |
| 72 | 73 |
| 73 DISALLOW_COPY_AND_ASSIGN(TextureFrameBufferPair); | 74 DISALLOW_COPY_AND_ASSIGN(TextureFrameBufferPair); |
| 74 }; | 75 }; |
| 75 | 76 |
| 76 // Helper class for holding a scaler, a texture for the output of that | 77 // Helper class for holding a scaler, a texture for the output of that |
| 77 // scaler and an associated frame buffer. This is inteded to be used | 78 // 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. | 79 // when the output of a scaler is to be sent to a readback. |
| 79 class ScalerHolder { | 80 class ScalerHolder { |
| 80 public: | 81 public: |
| 81 ScalerHolder(GLES2Interface* gl, content::GLHelper::ScalerInterface* scaler) | 82 ScalerHolder(GLES2Interface* gl, |
| 83 display_compositor::GLHelper::ScalerInterface* scaler) |
| 82 : texture_and_framebuffer_(gl, scaler->DstSize()), scaler_(scaler) {} | 84 : texture_and_framebuffer_(gl, scaler->DstSize()), scaler_(scaler) {} |
| 83 | 85 |
| 84 void Scale(GLuint src_texture) { | 86 void Scale(GLuint src_texture) { |
| 85 scaler_->Scale(src_texture, texture_and_framebuffer_.texture()); | 87 scaler_->Scale(src_texture, texture_and_framebuffer_.texture()); |
| 86 } | 88 } |
| 87 | 89 |
| 88 content::GLHelper::ScalerInterface* scaler() const { return scaler_.get(); } | 90 display_compositor::GLHelper::ScalerInterface* scaler() const { |
| 91 return scaler_.get(); |
| 92 } |
| 89 TextureFrameBufferPair* texture_and_framebuffer() { | 93 TextureFrameBufferPair* texture_and_framebuffer() { |
| 90 return &texture_and_framebuffer_; | 94 return &texture_and_framebuffer_; |
| 91 } | 95 } |
| 92 GLuint texture() const { return texture_and_framebuffer_.texture(); } | 96 GLuint texture() const { return texture_and_framebuffer_.texture(); } |
| 93 | 97 |
| 94 private: | 98 private: |
| 95 TextureFrameBufferPair texture_and_framebuffer_; | 99 TextureFrameBufferPair texture_and_framebuffer_; |
| 96 std::unique_ptr<content::GLHelper::ScalerInterface> scaler_; | 100 std::unique_ptr<display_compositor::GLHelper::ScalerInterface> scaler_; |
| 97 | 101 |
| 98 DISALLOW_COPY_AND_ASSIGN(ScalerHolder); | 102 DISALLOW_COPY_AND_ASSIGN(ScalerHolder); |
| 99 }; | 103 }; |
| 100 | 104 |
| 101 } // namespace | 105 } // namespace |
| 102 | 106 |
| 103 namespace content { | 107 namespace display_compositor { |
| 104 typedef GLHelperReadbackSupport::FormatSupport FormatSupport; | 108 typedef GLHelperReadbackSupport::FormatSupport FormatSupport; |
| 105 | 109 |
| 106 // Implements GLHelper::CropScaleReadbackAndCleanTexture and encapsulates | 110 // Implements GLHelper::CropScaleReadbackAndCleanTexture and encapsulates |
| 107 // the data needed for it. | 111 // the data needed for it. |
| 108 class GLHelper::CopyTextureToImpl | 112 class GLHelper::CopyTextureToImpl |
| 109 : public base::SupportsWeakPtr<GLHelper::CopyTextureToImpl> { | 113 : public base::SupportsWeakPtr<GLHelper::CopyTextureToImpl> { |
| 110 public: | 114 public: |
| 111 CopyTextureToImpl(GLES2Interface* gl, | 115 CopyTextureToImpl(GLES2Interface* gl, |
| 112 gpu::ContextSupport* context_support, | 116 gpu::ContextSupport* context_support, |
| 113 GLHelper* helper) | 117 GLHelper* helper) |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 | 327 |
| 324 ScalerInterface* scaler() override { return scaler_.scaler(); } | 328 ScalerInterface* scaler() override { return scaler_.scaler(); } |
| 325 | 329 |
| 326 private: | 330 private: |
| 327 GLES2Interface* gl_; | 331 GLES2Interface* gl_; |
| 328 CopyTextureToImpl* copy_impl_; | 332 CopyTextureToImpl* copy_impl_; |
| 329 gfx::Size dst_size_; | 333 gfx::Size dst_size_; |
| 330 GLHelper::ScalerQuality quality_; | 334 GLHelper::ScalerQuality quality_; |
| 331 ReadbackSwizzle swizzle_; | 335 ReadbackSwizzle swizzle_; |
| 332 ScalerHolder scaler_; | 336 ScalerHolder scaler_; |
| 333 std::unique_ptr<content::GLHelperScaling::ShaderInterface> pass1_shader_; | 337 std::unique_ptr<display_compositor::GLHelperScaling::ShaderInterface> |
| 334 std::unique_ptr<content::GLHelperScaling::ShaderInterface> pass2_shader_; | 338 pass1_shader_; |
| 339 std::unique_ptr<display_compositor::GLHelperScaling::ShaderInterface> |
| 340 pass2_shader_; |
| 335 TextureFrameBufferPair y_; | 341 TextureFrameBufferPair y_; |
| 336 ScopedTexture uv_; | 342 ScopedTexture uv_; |
| 337 TextureFrameBufferPair u_; | 343 TextureFrameBufferPair u_; |
| 338 TextureFrameBufferPair v_; | 344 TextureFrameBufferPair v_; |
| 339 | 345 |
| 340 DISALLOW_COPY_AND_ASSIGN(ReadbackYUV_MRT); | 346 DISALLOW_COPY_AND_ASSIGN(ReadbackYUV_MRT); |
| 341 }; | 347 }; |
| 342 | 348 |
| 343 // Copies the block of pixels specified with |src_subrect| from |src_texture|, | 349 // Copies the block of pixels specified with |src_subrect| from |src_texture|, |
| 344 // scales it to |dst_size|, writes it into a texture, and returns its ID. | 350 // scales it to |dst_size|, writes it into a texture, and returns its ID. |
| (...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 861 rect.width(), rect.height()); | 867 rect.width(), rect.height()); |
| 862 } | 868 } |
| 863 gl_->BindTexture(target, 0); | 869 gl_->BindTexture(target, 0); |
| 864 gl_->Flush(); | 870 gl_->Flush(); |
| 865 } | 871 } |
| 866 } | 872 } |
| 867 | 873 |
| 868 GLuint GLHelper::CreateTexture() { | 874 GLuint GLHelper::CreateTexture() { |
| 869 GLuint texture = 0u; | 875 GLuint texture = 0u; |
| 870 gl_->GenTextures(1, &texture); | 876 gl_->GenTextures(1, &texture); |
| 871 content::ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, texture); | 877 display_compositor::ScopedTextureBinder<GL_TEXTURE_2D> texture_binder( |
| 878 gl_, texture); |
| 872 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 879 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 873 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 880 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 874 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 881 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 875 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 882 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 876 return texture; | 883 return texture; |
| 877 } | 884 } |
| 878 | 885 |
| 879 void GLHelper::DeleteTexture(GLuint texture_id) { | 886 void GLHelper::DeleteTexture(GLuint texture_id) { |
| 880 gl_->DeleteTextures(1, &texture_id); | 887 gl_->DeleteTextures(1, &texture_id); |
| 881 } | 888 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 907 if (mailbox.IsZero()) | 914 if (mailbox.IsZero()) |
| 908 return 0; | 915 return 0; |
| 909 if (sync_token.HasData()) | 916 if (sync_token.HasData()) |
| 910 WaitSyncToken(sync_token); | 917 WaitSyncToken(sync_token); |
| 911 GLuint texture = | 918 GLuint texture = |
| 912 gl_->CreateAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); | 919 gl_->CreateAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); |
| 913 return texture; | 920 return texture; |
| 914 } | 921 } |
| 915 | 922 |
| 916 void GLHelper::ResizeTexture(GLuint texture, const gfx::Size& size) { | 923 void GLHelper::ResizeTexture(GLuint texture, const gfx::Size& size) { |
| 917 content::ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, texture); | 924 display_compositor::ScopedTextureBinder<GL_TEXTURE_2D> texture_binder( |
| 925 gl_, texture); |
| 918 gl_->TexImage2D(GL_TEXTURE_2D, 0, GL_RGB, size.width(), size.height(), 0, | 926 gl_->TexImage2D(GL_TEXTURE_2D, 0, GL_RGB, size.width(), size.height(), 0, |
| 919 GL_RGB, GL_UNSIGNED_BYTE, NULL); | 927 GL_RGB, GL_UNSIGNED_BYTE, NULL); |
| 920 } | 928 } |
| 921 | 929 |
| 922 void GLHelper::CopyTextureSubImage(GLuint texture, const gfx::Rect& rect) { | 930 void GLHelper::CopyTextureSubImage(GLuint texture, const gfx::Rect& rect) { |
| 923 content::ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, texture); | 931 display_compositor::ScopedTextureBinder<GL_TEXTURE_2D> texture_binder( |
| 932 gl_, texture); |
| 924 gl_->CopyTexSubImage2D(GL_TEXTURE_2D, 0, rect.x(), rect.y(), rect.x(), | 933 gl_->CopyTexSubImage2D(GL_TEXTURE_2D, 0, rect.x(), rect.y(), rect.x(), |
| 925 rect.y(), rect.width(), rect.height()); | 934 rect.y(), rect.width(), rect.height()); |
| 926 } | 935 } |
| 927 | 936 |
| 928 void GLHelper::CopyTextureFullImage(GLuint texture, const gfx::Size& size) { | 937 void GLHelper::CopyTextureFullImage(GLuint texture, const gfx::Size& size) { |
| 929 content::ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, texture); | 938 display_compositor::ScopedTextureBinder<GL_TEXTURE_2D> texture_binder( |
| 939 gl_, texture); |
| 930 gl_->CopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, size.width(), | 940 gl_->CopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, size.width(), |
| 931 size.height(), 0); | 941 size.height(), 0); |
| 932 } | 942 } |
| 933 | 943 |
| 934 void GLHelper::Flush() { | 944 void GLHelper::Flush() { |
| 935 gl_->Flush(); | 945 gl_->Flush(); |
| 936 } | 946 } |
| 937 | 947 |
| 938 void GLHelper::InsertOrderingBarrier() { | 948 void GLHelper::InsertOrderingBarrier() { |
| 939 gl_->OrderingBarrierCHROMIUM(); | 949 gl_->OrderingBarrierCHROMIUM(); |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1110 GLHelperScaling::SHADER_YUV_MRT_PASS2)), | 1120 GLHelperScaling::SHADER_YUV_MRT_PASS2)), |
| 1111 y_(gl, gfx::Size((dst_size.width() + 3) / 4, dst_size.height())), | 1121 y_(gl, gfx::Size((dst_size.width() + 3) / 4, dst_size.height())), |
| 1112 uv_(gl), | 1122 uv_(gl), |
| 1113 u_(gl, | 1123 u_(gl, |
| 1114 gfx::Size((dst_size.width() + 7) / 8, (dst_size.height() + 1) / 2)), | 1124 gfx::Size((dst_size.width() + 7) / 8, (dst_size.height() + 1) / 2)), |
| 1115 v_(gl, | 1125 v_(gl, |
| 1116 gfx::Size((dst_size.width() + 7) / 8, (dst_size.height() + 1) / 2)) { | 1126 gfx::Size((dst_size.width() + 7) / 8, (dst_size.height() + 1) / 2)) { |
| 1117 DCHECK(!(dst_size.width() & 1)); | 1127 DCHECK(!(dst_size.width() & 1)); |
| 1118 DCHECK(!(dst_size.height() & 1)); | 1128 DCHECK(!(dst_size.height() & 1)); |
| 1119 | 1129 |
| 1120 content::ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl, uv_); | 1130 display_compositor::ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl, |
| 1131 uv_); |
| 1121 gl->TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (dst_size.width() + 3) / 4, | 1132 gl->TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (dst_size.width() + 3) / 4, |
| 1122 dst_size.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); | 1133 dst_size.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); |
| 1123 } | 1134 } |
| 1124 | 1135 |
| 1125 void GLHelper::CopyTextureToImpl::ReadbackYUV_MRT::ReadbackYUV( | 1136 void GLHelper::CopyTextureToImpl::ReadbackYUV_MRT::ReadbackYUV( |
| 1126 const gpu::Mailbox& mailbox, | 1137 const gpu::Mailbox& mailbox, |
| 1127 const gpu::SyncToken& sync_token, | 1138 const gpu::SyncToken& sync_token, |
| 1128 const gfx::Rect& target_visible_rect, | 1139 const gfx::Rect& target_visible_rect, |
| 1129 int y_plane_row_stride_bytes, | 1140 int y_plane_row_stride_bytes, |
| 1130 unsigned char* y_plane_data, | 1141 unsigned char* y_plane_data, |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1227 const gfx::Size& src_size, | 1238 const gfx::Size& src_size, |
| 1228 const gfx::Rect& src_subrect, | 1239 const gfx::Rect& src_subrect, |
| 1229 const gfx::Size& dst_size, | 1240 const gfx::Size& dst_size, |
| 1230 bool flip_vertically, | 1241 bool flip_vertically, |
| 1231 bool use_mrt) { | 1242 bool use_mrt) { |
| 1232 InitCopyTextToImpl(); | 1243 InitCopyTextToImpl(); |
| 1233 return copy_texture_to_impl_->CreateReadbackPipelineYUV( | 1244 return copy_texture_to_impl_->CreateReadbackPipelineYUV( |
| 1234 quality, src_size, src_subrect, dst_size, flip_vertically, use_mrt); | 1245 quality, src_size, src_subrect, dst_size, flip_vertically, use_mrt); |
| 1235 } | 1246 } |
| 1236 | 1247 |
| 1237 } // namespace content | 1248 } // namespace display_compositor |
| OLD | NEW |