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

Side by Side Diff: components/viz/display_compositor/gl_helper.cc

Issue 2873243002: Move components/display_compositor to components/viz/display_compositor (Closed)
Patch Set: Rebase Created 3 years, 7 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
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 "components/display_compositor/gl_helper.h" 5 #include "components/viz/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 "components/display_compositor/gl_helper_readback_support.h" 22 #include "components/viz/display_compositor/gl_helper_readback_support.h"
23 #include "components/display_compositor/gl_helper_scaling.h" 23 #include "components/viz/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
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 display_compositor::ScopedTextureBinder<GL_TEXTURE_2D> texture_binder( 55 viz::ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl, texture_);
56 gl, texture_);
57 gl->TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size.width(), size.height(), 0, 56 gl->TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size.width(), size.height(), 0,
58 GL_RGBA, GL_UNSIGNED_BYTE, NULL); 57 GL_RGBA, GL_UNSIGNED_BYTE, NULL);
59 display_compositor::ScopedFramebufferBinder<GL_FRAMEBUFFER> 58 viz::ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder(
60 framebuffer_binder(gl, framebuffer_); 59 gl, framebuffer_);
61 gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, 60 gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
62 GL_TEXTURE_2D, texture_, 0); 61 GL_TEXTURE_2D, texture_, 0);
63 } 62 }
64 63
65 GLuint texture() const { return texture_.id(); } 64 GLuint texture() const { return texture_.id(); }
66 GLuint framebuffer() const { return framebuffer_.id(); } 65 GLuint framebuffer() const { return framebuffer_.id(); }
67 gfx::Size size() const { return size_; } 66 gfx::Size size() const { return size_; }
68 67
69 private: 68 private:
70 display_compositor::ScopedTexture texture_; 69 viz::ScopedTexture texture_;
71 display_compositor::ScopedFramebuffer framebuffer_; 70 viz::ScopedFramebuffer framebuffer_;
72 gfx::Size size_; 71 gfx::Size size_;
73 72
74 DISALLOW_COPY_AND_ASSIGN(TextureFrameBufferPair); 73 DISALLOW_COPY_AND_ASSIGN(TextureFrameBufferPair);
75 }; 74 };
76 75
77 // Helper class for holding a scaler, a texture for the output of that 76 // Helper class for holding a scaler, a texture for the output of that
78 // 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
79 // 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.
80 class ScalerHolder { 79 class ScalerHolder {
81 public: 80 public:
82 ScalerHolder(GLES2Interface* gl, 81 ScalerHolder(GLES2Interface* gl, viz::GLHelper::ScalerInterface* scaler)
83 display_compositor::GLHelper::ScalerInterface* scaler)
84 : texture_and_framebuffer_(gl, scaler->DstSize()), scaler_(scaler) {} 82 : texture_and_framebuffer_(gl, scaler->DstSize()), scaler_(scaler) {}
85 83
86 void Scale(GLuint src_texture) { 84 void Scale(GLuint src_texture) {
87 scaler_->Scale(src_texture, texture_and_framebuffer_.texture()); 85 scaler_->Scale(src_texture, texture_and_framebuffer_.texture());
88 } 86 }
89 87
90 display_compositor::GLHelper::ScalerInterface* scaler() const { 88 viz::GLHelper::ScalerInterface* scaler() const { return scaler_.get(); }
91 return scaler_.get();
92 }
93 TextureFrameBufferPair* texture_and_framebuffer() { 89 TextureFrameBufferPair* texture_and_framebuffer() {
94 return &texture_and_framebuffer_; 90 return &texture_and_framebuffer_;
95 } 91 }
96 GLuint texture() const { return texture_and_framebuffer_.texture(); } 92 GLuint texture() const { return texture_and_framebuffer_.texture(); }
97 93
98 private: 94 private:
99 TextureFrameBufferPair texture_and_framebuffer_; 95 TextureFrameBufferPair texture_and_framebuffer_;
100 std::unique_ptr<display_compositor::GLHelper::ScalerInterface> scaler_; 96 std::unique_ptr<viz::GLHelper::ScalerInterface> scaler_;
101 97
102 DISALLOW_COPY_AND_ASSIGN(ScalerHolder); 98 DISALLOW_COPY_AND_ASSIGN(ScalerHolder);
103 }; 99 };
104 100
105 } // namespace 101 } // namespace
106 102
107 namespace display_compositor { 103 namespace viz {
108 typedef GLHelperReadbackSupport::FormatSupport FormatSupport; 104 typedef GLHelperReadbackSupport::FormatSupport FormatSupport;
109 105
110 // Implements GLHelper::CropScaleReadbackAndCleanTexture and encapsulates 106 // Implements GLHelper::CropScaleReadbackAndCleanTexture and encapsulates
111 // the data needed for it. 107 // the data needed for it.
112 class GLHelper::CopyTextureToImpl 108 class GLHelper::CopyTextureToImpl
113 : public base::SupportsWeakPtr<GLHelper::CopyTextureToImpl> { 109 : public base::SupportsWeakPtr<GLHelper::CopyTextureToImpl> {
114 public: 110 public:
115 CopyTextureToImpl(GLES2Interface* gl, 111 CopyTextureToImpl(GLES2Interface* gl,
116 gpu::ContextSupport* context_support, 112 gpu::ContextSupport* context_support,
117 GLHelper* helper) 113 GLHelper* helper)
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 323
328 ScalerInterface* scaler() override { return scaler_.scaler(); } 324 ScalerInterface* scaler() override { return scaler_.scaler(); }
329 325
330 private: 326 private:
331 GLES2Interface* gl_; 327 GLES2Interface* gl_;
332 CopyTextureToImpl* copy_impl_; 328 CopyTextureToImpl* copy_impl_;
333 gfx::Size dst_size_; 329 gfx::Size dst_size_;
334 GLHelper::ScalerQuality quality_; 330 GLHelper::ScalerQuality quality_;
335 ReadbackSwizzle swizzle_; 331 ReadbackSwizzle swizzle_;
336 ScalerHolder scaler_; 332 ScalerHolder scaler_;
337 std::unique_ptr<display_compositor::GLHelperScaling::ShaderInterface> 333 std::unique_ptr<GLHelperScaling::ShaderInterface> pass1_shader_;
338 pass1_shader_; 334 std::unique_ptr<GLHelperScaling::ShaderInterface> pass2_shader_;
339 std::unique_ptr<display_compositor::GLHelperScaling::ShaderInterface>
340 pass2_shader_;
341 TextureFrameBufferPair y_; 335 TextureFrameBufferPair y_;
342 ScopedTexture uv_; 336 ScopedTexture uv_;
343 TextureFrameBufferPair u_; 337 TextureFrameBufferPair u_;
344 TextureFrameBufferPair v_; 338 TextureFrameBufferPair v_;
345 339
346 DISALLOW_COPY_AND_ASSIGN(ReadbackYUV_MRT); 340 DISALLOW_COPY_AND_ASSIGN(ReadbackYUV_MRT);
347 }; 341 };
348 342
349 // Copies the block of pixels specified with |src_subrect| from |src_texture|, 343 // Copies the block of pixels specified with |src_subrect| from |src_texture|,
350 // scales it to |dst_size|, writes it into a texture, and returns its ID. 344 // scales it to |dst_size|, writes it into a texture, and returns its ID.
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 // out_color_type is kAlpha_8_SkColorType, so let's skip the scaling step 535 // out_color_type is kAlpha_8_SkColorType, so let's skip the scaling step
542 // in that case. 536 // in that case.
543 bool scale_texture = out_color_type != kAlpha_8_SkColorType || 537 bool scale_texture = out_color_type != kAlpha_8_SkColorType ||
544 quality != GLHelper::SCALER_QUALITY_FAST; 538 quality != GLHelper::SCALER_QUALITY_FAST;
545 if (scale_texture) { 539 if (scale_texture) {
546 // Don't swizzle during the scale step for kAlpha_8_SkColorType. 540 // Don't swizzle during the scale step for kAlpha_8_SkColorType.
547 // We will swizzle in the encode step below if needed. 541 // We will swizzle in the encode step below if needed.
548 bool scale_swizzle = out_color_type == kAlpha_8_SkColorType 542 bool scale_swizzle = out_color_type == kAlpha_8_SkColorType
549 ? false 543 ? false
550 : supported == GLHelperReadbackSupport::SWIZZLE; 544 : supported == GLHelperReadbackSupport::SWIZZLE;
551 texture = ScaleTexture(src_texture, src_size, src_subrect, dst_size, true, 545 texture = ScaleTexture(
552 scale_swizzle, out_color_type == kAlpha_8_SkColorType 546 src_texture, src_size, src_subrect, dst_size, true, scale_swizzle,
553 ? kN32_SkColorType 547 out_color_type == kAlpha_8_SkColorType ? kN32_SkColorType
554 : out_color_type, 548 : out_color_type,
555 quality); 549 quality);
556 DCHECK(texture); 550 DCHECK(texture);
557 } 551 }
558 552
559 gfx::Size readback_texture_size = dst_size; 553 gfx::Size readback_texture_size = dst_size;
560 // Encode texture to grayscale if needed. 554 // Encode texture to grayscale if needed.
561 if (out_color_type == kAlpha_8_SkColorType) { 555 if (out_color_type == kAlpha_8_SkColorType) {
562 // Do the vertical flip here if we haven't already done it when we scaled 556 // Do the vertical flip here if we haven't already done it when we scaled
563 // the texture. 557 // the texture.
564 bool encode_as_grayscale_vertical_flip = !scale_texture; 558 bool encode_as_grayscale_vertical_flip = !scale_texture;
565 // EncodeTextureAsGrayscale by default creates a texture which should be 559 // EncodeTextureAsGrayscale by default creates a texture which should be
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
867 rect.width(), rect.height()); 861 rect.width(), rect.height());
868 } 862 }
869 gl_->BindTexture(target, 0); 863 gl_->BindTexture(target, 0);
870 gl_->Flush(); 864 gl_->Flush();
871 } 865 }
872 } 866 }
873 867
874 GLuint GLHelper::CreateTexture() { 868 GLuint GLHelper::CreateTexture() {
875 GLuint texture = 0u; 869 GLuint texture = 0u;
876 gl_->GenTextures(1, &texture); 870 gl_->GenTextures(1, &texture);
877 display_compositor::ScopedTextureBinder<GL_TEXTURE_2D> texture_binder( 871 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, texture);
878 gl_, texture);
879 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 872 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
880 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 873 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
881 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 874 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
882 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 875 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
883 return texture; 876 return texture;
884 } 877 }
885 878
886 void GLHelper::DeleteTexture(GLuint texture_id) { 879 void GLHelper::DeleteTexture(GLuint texture_id) {
887 gl_->DeleteTextures(1, &texture_id); 880 gl_->DeleteTextures(1, &texture_id);
888 } 881 }
(...skipping 25 matching lines...) Expand all
914 if (mailbox.IsZero()) 907 if (mailbox.IsZero())
915 return 0; 908 return 0;
916 if (sync_token.HasData()) 909 if (sync_token.HasData())
917 WaitSyncToken(sync_token); 910 WaitSyncToken(sync_token);
918 GLuint texture = 911 GLuint texture =
919 gl_->CreateAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); 912 gl_->CreateAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name);
920 return texture; 913 return texture;
921 } 914 }
922 915
923 void GLHelper::ResizeTexture(GLuint texture, const gfx::Size& size) { 916 void GLHelper::ResizeTexture(GLuint texture, const gfx::Size& size) {
924 display_compositor::ScopedTextureBinder<GL_TEXTURE_2D> texture_binder( 917 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, texture);
925 gl_, texture);
926 gl_->TexImage2D(GL_TEXTURE_2D, 0, GL_RGB, size.width(), size.height(), 0, 918 gl_->TexImage2D(GL_TEXTURE_2D, 0, GL_RGB, size.width(), size.height(), 0,
927 GL_RGB, GL_UNSIGNED_BYTE, NULL); 919 GL_RGB, GL_UNSIGNED_BYTE, NULL);
928 } 920 }
929 921
930 void GLHelper::CopyTextureSubImage(GLuint texture, const gfx::Rect& rect) { 922 void GLHelper::CopyTextureSubImage(GLuint texture, const gfx::Rect& rect) {
931 display_compositor::ScopedTextureBinder<GL_TEXTURE_2D> texture_binder( 923 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, texture);
932 gl_, texture);
933 gl_->CopyTexSubImage2D(GL_TEXTURE_2D, 0, rect.x(), rect.y(), rect.x(), 924 gl_->CopyTexSubImage2D(GL_TEXTURE_2D, 0, rect.x(), rect.y(), rect.x(),
934 rect.y(), rect.width(), rect.height()); 925 rect.y(), rect.width(), rect.height());
935 } 926 }
936 927
937 void GLHelper::CopyTextureFullImage(GLuint texture, const gfx::Size& size) { 928 void GLHelper::CopyTextureFullImage(GLuint texture, const gfx::Size& size) {
938 display_compositor::ScopedTextureBinder<GL_TEXTURE_2D> texture_binder( 929 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, texture);
939 gl_, texture);
940 gl_->CopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, size.width(), 930 gl_->CopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, size.width(),
941 size.height(), 0); 931 size.height(), 0);
942 } 932 }
943 933
944 void GLHelper::Flush() { 934 void GLHelper::Flush() {
945 gl_->Flush(); 935 gl_->Flush();
946 } 936 }
947 937
948 void GLHelper::InsertOrderingBarrier() { 938 void GLHelper::InsertOrderingBarrier() {
949 gl_->OrderingBarrierCHROMIUM(); 939 gl_->OrderingBarrierCHROMIUM();
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
1120 GLHelperScaling::SHADER_YUV_MRT_PASS2)), 1110 GLHelperScaling::SHADER_YUV_MRT_PASS2)),
1121 y_(gl, gfx::Size((dst_size.width() + 3) / 4, dst_size.height())), 1111 y_(gl, gfx::Size((dst_size.width() + 3) / 4, dst_size.height())),
1122 uv_(gl), 1112 uv_(gl),
1123 u_(gl, 1113 u_(gl,
1124 gfx::Size((dst_size.width() + 7) / 8, (dst_size.height() + 1) / 2)), 1114 gfx::Size((dst_size.width() + 7) / 8, (dst_size.height() + 1) / 2)),
1125 v_(gl, 1115 v_(gl,
1126 gfx::Size((dst_size.width() + 7) / 8, (dst_size.height() + 1) / 2)) { 1116 gfx::Size((dst_size.width() + 7) / 8, (dst_size.height() + 1) / 2)) {
1127 DCHECK(!(dst_size.width() & 1)); 1117 DCHECK(!(dst_size.width() & 1));
1128 DCHECK(!(dst_size.height() & 1)); 1118 DCHECK(!(dst_size.height() & 1));
1129 1119
1130 display_compositor::ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl, 1120 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl, uv_);
1131 uv_);
1132 gl->TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (dst_size.width() + 3) / 4, 1121 gl->TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (dst_size.width() + 3) / 4,
1133 dst_size.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); 1122 dst_size.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
1134 } 1123 }
1135 1124
1136 void GLHelper::CopyTextureToImpl::ReadbackYUV_MRT::ReadbackYUV( 1125 void GLHelper::CopyTextureToImpl::ReadbackYUV_MRT::ReadbackYUV(
1137 const gpu::Mailbox& mailbox, 1126 const gpu::Mailbox& mailbox,
1138 const gpu::SyncToken& sync_token, 1127 const gpu::SyncToken& sync_token,
1139 const gfx::Rect& target_visible_rect, 1128 const gfx::Rect& target_visible_rect,
1140 int y_plane_row_stride_bytes, 1129 int y_plane_row_stride_bytes,
1141 unsigned char* y_plane_data, 1130 unsigned char* y_plane_data,
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1238 const gfx::Size& src_size, 1227 const gfx::Size& src_size,
1239 const gfx::Rect& src_subrect, 1228 const gfx::Rect& src_subrect,
1240 const gfx::Size& dst_size, 1229 const gfx::Size& dst_size,
1241 bool flip_vertically, 1230 bool flip_vertically,
1242 bool use_mrt) { 1231 bool use_mrt) {
1243 InitCopyTextToImpl(); 1232 InitCopyTextToImpl();
1244 return copy_texture_to_impl_->CreateReadbackPipelineYUV( 1233 return copy_texture_to_impl_->CreateReadbackPipelineYUV(
1245 quality, src_size, src_subrect, dst_size, flip_vertically, use_mrt); 1234 quality, src_size, src_subrect, dst_size, flip_vertically, use_mrt);
1246 } 1235 }
1247 1236
1248 } // namespace display_compositor 1237 } // namespace viz
OLDNEW
« no previous file with comments | « components/viz/display_compositor/gl_helper.h ('k') | components/viz/display_compositor/gl_helper_benchmark.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698