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

Side by Side Diff: cc/output/gl_renderer.cc

Issue 723343002: Update from https://crrev.com/304121 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « cc/output/gl_renderer.h ('k') | cc/output/gl_renderer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 The Chromium Authors. All rights reserved. 1 // Copyright 2010 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 "cc/output/gl_renderer.h" 5 #include "cc/output/gl_renderer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 default: 91 default:
92 NOTREACHED(); 92 NOTREACHED();
93 return SamplerType2D; 93 return SamplerType2D;
94 } 94 }
95 } 95 }
96 96
97 BlendMode BlendModeFromSkXfermode(SkXfermode::Mode mode) { 97 BlendMode BlendModeFromSkXfermode(SkXfermode::Mode mode) {
98 switch (mode) { 98 switch (mode) {
99 case SkXfermode::kSrcOver_Mode: 99 case SkXfermode::kSrcOver_Mode:
100 return BlendModeNormal; 100 return BlendModeNormal;
101 case SkXfermode::kScreen_Mode:
102 return BlendModeScreen;
101 case SkXfermode::kOverlay_Mode: 103 case SkXfermode::kOverlay_Mode:
102 return BlendModeOverlay; 104 return BlendModeOverlay;
103 case SkXfermode::kDarken_Mode: 105 case SkXfermode::kDarken_Mode:
104 return BlendModeDarken; 106 return BlendModeDarken;
105 case SkXfermode::kLighten_Mode: 107 case SkXfermode::kLighten_Mode:
106 return BlendModeLighten; 108 return BlendModeLighten;
107 case SkXfermode::kColorDodge_Mode: 109 case SkXfermode::kColorDodge_Mode:
108 return BlendModeColorDodge; 110 return BlendModeColorDodge;
109 case SkXfermode::kColorBurn_Mode: 111 case SkXfermode::kColorBurn_Mode:
110 return BlendModeColorBurn; 112 return BlendModeColorBurn;
(...skipping 10 matching lines...) Expand all
121 case SkXfermode::kHue_Mode: 123 case SkXfermode::kHue_Mode:
122 return BlendModeHue; 124 return BlendModeHue;
123 case SkXfermode::kSaturation_Mode: 125 case SkXfermode::kSaturation_Mode:
124 return BlendModeSaturation; 126 return BlendModeSaturation;
125 case SkXfermode::kColor_Mode: 127 case SkXfermode::kColor_Mode:
126 return BlendModeColor; 128 return BlendModeColor;
127 case SkXfermode::kLuminosity_Mode: 129 case SkXfermode::kLuminosity_Mode:
128 return BlendModeLuminosity; 130 return BlendModeLuminosity;
129 default: 131 default:
130 NOTREACHED(); 132 NOTREACHED();
131 return BlendModeNormal; 133 return BlendModeNone;
132 } 134 }
133 } 135 }
134 136
135 // Smallest unit that impact anti-aliasing output. We use this to 137 // Smallest unit that impact anti-aliasing output. We use this to
136 // determine when anti-aliasing is unnecessary. 138 // determine when anti-aliasing is unnecessary.
137 const float kAntiAliasingEpsilon = 1.0f / 1024.0f; 139 const float kAntiAliasingEpsilon = 1.0f / 1024.0f;
138 140
139 // Block or crash if the number of pending sync queries reach this high as 141 // Block or crash if the number of pending sync queries reach this high as
140 // something is seriously wrong on the service side if this happens. 142 // something is seriously wrong on the service side if this happens.
141 const size_t kMaxPendingSyncQueries = 16; 143 const size_t kMaxPendingSyncQueries = 16;
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after
858 skia::RefPtr<SkImage> background_with_filters = 860 skia::RefPtr<SkImage> background_with_filters =
859 ApplyImageFilter(ScopedUseGrContext::Create(this, frame), 861 ApplyImageFilter(ScopedUseGrContext::Create(this, frame),
860 resource_provider_, 862 resource_provider_,
861 quad->rect.origin(), 863 quad->rect.origin(),
862 quad->filters_scale, 864 quad->filters_scale,
863 filter.get(), 865 filter.get(),
864 background_texture); 866 background_texture);
865 return background_with_filters; 867 return background_with_filters;
866 } 868 }
867 869
868 scoped_ptr<ScopedResource>
869 GLRenderer::ApplyInverseTransformForBackgroundFilters(
870 DrawingFrame* frame,
871 const RenderPassDrawQuad* quad,
872 const gfx::Transform& contents_device_transform,
873 skia::RefPtr<SkImage> filtered_device_background,
874 const gfx::Rect& backdrop_bounding_rect) {
875 // This method draws a background filter, which applies a filter to any pixels
876 // behind the quad and seen through its background. The algorithm works as
877 // follows:
878 // 1. Read the pixels in the bounding box into a buffer.
879 // Moved to GLRenderer::GetBackdropBoundingBoxForRenderPassQuad().
880 // 2. Read the pixels in the bounding box into a buffer R.
881 // Moved to GLRenderer::GetBackdropTexture().
882 // 3. Apply the background filter to R, so that it is applied in the pixels'
883 // coordinate space. Moved to GLRenderer::ApplyBackgroundFilters().
884 // 4. Apply the quad's inverse transform to map the pixels in R into the
885 // quad's content space. This implicitly clips R by the content bounds of the
886 // quad since the destination texture has bounds matching the quad's content.
887 // 5. Draw the background texture for the contents using the same transform as
888 // used to draw the contents itself. This is done without blending to replace
889 // the current background pixels with the new filtered background.
890 // 6. Draw the contents of the quad over drop of the new background with
891 // blending, as per usual. The filtered background pixels will show through
892 // any non-opaque pixels in this draws.
893 //
894 // Pixel copies in this algorithm occur at steps 2, 3, 4, and 5.
895
896 // TODO(danakj): When this algorithm changes, update
897 // LayerTreeHost::PrioritizeTextures() accordingly.
898
899 DCHECK(filtered_device_background);
900
901 GrTexture* texture = filtered_device_background->getTexture();
902
903 scoped_ptr<ScopedResource> background_texture =
904 ScopedResource::Create(resource_provider_);
905 background_texture->Allocate(
906 quad->rect.size(),
907 ResourceProvider::TextureHintImmutableFramebuffer,
908 RGBA_8888);
909
910 const RenderPass* target_render_pass = frame->current_render_pass;
911 bool using_background_texture =
912 UseScopedTexture(frame, background_texture.get(), quad->rect);
913
914 if (using_background_texture) {
915 // Copy the readback pixels from device to the background texture for the
916 // surface.
917
918 gfx::Transform contents_device_transform_inverse(
919 gfx::Transform::kSkipInitialization);
920 bool did_invert = contents_device_transform.GetInverse(
921 &contents_device_transform_inverse);
922 DCHECK(did_invert);
923 gfx::Transform device_to_framebuffer_transform;
924 QuadRectTransform(
925 &device_to_framebuffer_transform, gfx::Transform(), quad->rect);
926 device_to_framebuffer_transform.PreconcatTransform(
927 contents_device_transform_inverse);
928
929 #ifndef NDEBUG
930 GLC(gl_, gl_->ClearColor(0, 0, 1, 1));
931 gl_->Clear(GL_COLOR_BUFFER_BIT);
932 #endif
933
934 // The background_texture is oriented the same as the frame buffer.
935 // The transform we are copying with has a vertical flip, as well as
936 // the |device_to_framebuffer_transform|, which cancel each other out. So do
937 // not flip the contents in the shader to maintain orientation.
938 bool flip_vertically = false;
939
940 CopyTextureToFramebuffer(frame,
941 texture->getTextureHandle(),
942 backdrop_bounding_rect,
943 device_to_framebuffer_transform,
944 flip_vertically);
945 }
946
947 UseRenderPass(frame, target_render_pass);
948
949 if (!using_background_texture)
950 return nullptr;
951 return background_texture.Pass();
952 }
953
954 void GLRenderer::DrawRenderPassQuad(DrawingFrame* frame, 870 void GLRenderer::DrawRenderPassQuad(DrawingFrame* frame,
955 const RenderPassDrawQuad* quad) { 871 const RenderPassDrawQuad* quad) {
956 SkXfermode::Mode blend_mode = quad->shared_quad_state->blend_mode;
957 SetBlendEnabled(
958 CanApplyBlendModeUsingBlendFunc(blend_mode) &&
959 (quad->ShouldDrawWithBlending() || !IsDefaultBlendMode(blend_mode)));
960
961 ScopedResource* contents_texture = 872 ScopedResource* contents_texture =
962 render_pass_textures_.get(quad->render_pass_id); 873 render_pass_textures_.get(quad->render_pass_id);
963 if (!contents_texture || !contents_texture->id()) 874 if (!contents_texture || !contents_texture->id())
964 return; 875 return;
965 876
966 gfx::Transform quad_rect_matrix; 877 gfx::Transform quad_rect_matrix;
967 QuadRectTransform(&quad_rect_matrix, quad->quadTransform(), quad->rect); 878 QuadRectTransform(&quad_rect_matrix, quad->quadTransform(), quad->rect);
968 gfx::Transform contents_device_transform = 879 gfx::Transform contents_device_transform =
969 frame->window_matrix * frame->projection_matrix * quad_rect_matrix; 880 frame->window_matrix * frame->projection_matrix * quad_rect_matrix;
970 contents_device_transform.FlattenTo2d(); 881 contents_device_transform.FlattenTo2d();
971 882
972 // Can only draw surface if device matrix is invertible. 883 // Can only draw surface if device matrix is invertible.
973 if (!contents_device_transform.IsInvertible()) 884 if (!contents_device_transform.IsInvertible())
974 return; 885 return;
975 886
976 gfx::QuadF surface_quad = SharedGeometryQuad(); 887 gfx::QuadF surface_quad = SharedGeometryQuad();
977 float edge[24]; 888 float edge[24];
978 bool use_aa = settings_->allow_antialiasing && 889 bool use_aa = settings_->allow_antialiasing &&
979 ShouldAntialiasQuad(contents_device_transform, quad, 890 ShouldAntialiasQuad(contents_device_transform, quad,
980 settings_->force_antialiasing); 891 settings_->force_antialiasing);
981 892
982 if (use_aa) 893 if (use_aa)
983 SetupQuadForAntialiasing(contents_device_transform, quad, 894 SetupQuadForAntialiasing(contents_device_transform, quad,
984 &surface_quad, edge); 895 &surface_quad, edge);
985 896
986 bool need_background_texture = !CanApplyBlendModeUsingBlendFunc(blend_mode) || 897 SkXfermode::Mode blend_mode = quad->shared_quad_state->blend_mode;
987 ShouldApplyBackgroundFilters(frame, quad); 898 bool use_shaders_for_blending =
899 !CanApplyBlendModeUsingBlendFunc(blend_mode) ||
900 ShouldApplyBackgroundFilters(frame, quad) ||
901 settings_->force_blending_with_shaders;
988 902
989 scoped_ptr<ScopedResource> background_texture; 903 scoped_ptr<ScopedResource> background_texture;
990 skia::RefPtr<SkImage> background_image; 904 skia::RefPtr<SkImage> background_image;
991 gfx::Rect background_rect; 905 gfx::Rect background_rect;
992 if (need_background_texture) { 906 if (use_shaders_for_blending) {
993 // Compute a bounding box around the pixels that will be visible through 907 // Compute a bounding box around the pixels that will be visible through
994 // the quad. 908 // the quad.
995 background_rect = GetBackdropBoundingBoxForRenderPassQuad( 909 background_rect = GetBackdropBoundingBoxForRenderPassQuad(
996 frame, quad, contents_device_transform, use_aa); 910 frame, quad, contents_device_transform, use_aa);
997 }
998 911
999 if (!background_rect.IsEmpty()) { 912 if (!background_rect.IsEmpty()) {
1000 // The pixels from the filtered background should completely replace the 913 // The pixels from the filtered background should completely replace the
1001 // current pixel values. 914 // current pixel values.
1002 bool disable_blending = blend_enabled(); 915 if (blend_enabled())
1003 if (disable_blending) 916 SetBlendEnabled(false);
1004 SetBlendEnabled(false);
1005 917
1006 // Read the pixels in the bounding box into a buffer R. 918 // Read the pixels in the bounding box into a buffer R.
1007 scoped_ptr<ScopedResource> scoped_background_texture = 919 // This function allocates a texture, which should contribute to the
1008 GetBackdropTexture(background_rect); 920 // amount of memory used by render surfaces:
921 // LayerTreeHost::CalculateMemoryForRenderSurfaces.
922 background_texture = GetBackdropTexture(background_rect);
1009 923
1010 skia::RefPtr<SkImage> background_with_filters; 924 if (ShouldApplyBackgroundFilters(frame, quad) && background_texture) {
1011 if (ShouldApplyBackgroundFilters(frame, quad) && 925 // Apply the background filters to R, so that it is applied in the
1012 scoped_background_texture) { 926 // pixels' coordinate space.
1013 // Apply the background filters to R, so that it is applied in the pixels' 927 background_image =
1014 // coordinate space. 928 ApplyBackgroundFilters(frame, quad, background_texture.get());
1015 background_with_filters =
1016 ApplyBackgroundFilters(frame, quad, scoped_background_texture.get());
1017 }
1018
1019 if (CanApplyBlendModeUsingBlendFunc(blend_mode) &&
1020 background_with_filters) {
1021 // The background with filters will be copied to the frame buffer.
1022 // Apply the quad's inverse transform to map the pixels in R into the
1023 // quad's content space. This implicitly clips R by the content bounds of
1024 // the quad since the destination texture has bounds matching the quad's
1025 // content.
1026 background_texture = ApplyInverseTransformForBackgroundFilters(
1027 frame, quad, contents_device_transform, background_with_filters,
1028 background_rect);
1029 } else if (!CanApplyBlendModeUsingBlendFunc(blend_mode)) {
1030 if (background_with_filters) {
1031 // The background with filters will be used as backdrop for blending.
1032 background_image = background_with_filters;
1033 } else {
1034 background_texture = scoped_background_texture.Pass();
1035 } 929 }
1036 } 930 }
1037 931
1038 if (disable_blending) 932 if (!background_texture) {
1039 SetBlendEnabled(true); 933 // Something went wrong with reading the backdrop.
934 DCHECK(!background_image);
935 use_shaders_for_blending = false;
936 } else if (background_image) {
937 background_texture.reset();
938 } else if (CanApplyBlendModeUsingBlendFunc(blend_mode) &&
939 ShouldApplyBackgroundFilters(frame, quad)) {
940 // Something went wrong with applying background filters to the backdrop.
941 use_shaders_for_blending = false;
942 background_texture.reset();
943 }
1040 } 944 }
1041 945
946 SetBlendEnabled(
947 !use_shaders_for_blending &&
948 (quad->ShouldDrawWithBlending() || !IsDefaultBlendMode(blend_mode)));
949
1042 // TODO(senorblanco): Cache this value so that we don't have to do it for both 950 // TODO(senorblanco): Cache this value so that we don't have to do it for both
1043 // the surface and its replica. Apply filters to the contents texture. 951 // the surface and its replica. Apply filters to the contents texture.
1044 skia::RefPtr<SkImage> filter_image; 952 skia::RefPtr<SkImage> filter_image;
1045 SkScalar color_matrix[20]; 953 SkScalar color_matrix[20];
1046 bool use_color_matrix = false; 954 bool use_color_matrix = false;
1047 if (!quad->filters.IsEmpty()) { 955 if (!quad->filters.IsEmpty()) {
1048 skia::RefPtr<SkImageFilter> filter = RenderSurfaceFilters::BuildImageFilter( 956 skia::RefPtr<SkImageFilter> filter = RenderSurfaceFilters::BuildImageFilter(
1049 quad->filters, contents_texture->size()); 957 quad->filters, contents_texture->size());
1050 if (filter) { 958 if (filter) {
1051 skia::RefPtr<SkColorFilter> cf; 959 skia::RefPtr<SkColorFilter> cf;
(...skipping 12 matching lines...) Expand all
1064 filter_image = ApplyImageFilter(ScopedUseGrContext::Create(this, frame), 972 filter_image = ApplyImageFilter(ScopedUseGrContext::Create(this, frame),
1065 resource_provider_, 973 resource_provider_,
1066 quad->rect.origin(), 974 quad->rect.origin(),
1067 quad->filters_scale, 975 quad->filters_scale,
1068 filter.get(), 976 filter.get(),
1069 contents_texture); 977 contents_texture);
1070 } 978 }
1071 } 979 }
1072 } 980 }
1073 981
1074 if (background_texture && ShouldApplyBackgroundFilters(frame, quad)) {
1075 // Draw the background texture if it has some filters applied.
1076 DCHECK(CanApplyBlendModeUsingBlendFunc(blend_mode));
1077 DCHECK(background_texture->size() == quad->rect.size());
1078 ResourceProvider::ScopedReadLockGL lock(resource_provider_,
1079 background_texture->id());
1080
1081 // The background_texture is oriented the same as the frame buffer. The
1082 // transform we are copying with has a vertical flip, so flip the contents
1083 // in the shader to maintain orientation
1084 bool flip_vertically = true;
1085
1086 CopyTextureToFramebuffer(frame,
1087 lock.texture_id(),
1088 quad->rect,
1089 quad->quadTransform(),
1090 flip_vertically);
1091 }
1092
1093 scoped_ptr<ResourceProvider::ScopedSamplerGL> mask_resource_lock; 982 scoped_ptr<ResourceProvider::ScopedSamplerGL> mask_resource_lock;
1094 unsigned mask_texture_id = 0; 983 unsigned mask_texture_id = 0;
1095 SamplerType mask_sampler = SamplerTypeNA; 984 SamplerType mask_sampler = SamplerTypeNA;
1096 if (quad->mask_resource_id) { 985 if (quad->mask_resource_id) {
1097 mask_resource_lock.reset(new ResourceProvider::ScopedSamplerGL( 986 mask_resource_lock.reset(new ResourceProvider::ScopedSamplerGL(
1098 resource_provider_, quad->mask_resource_id, GL_TEXTURE1, GL_LINEAR)); 987 resource_provider_, quad->mask_resource_id, GL_TEXTURE1, GL_LINEAR));
1099 mask_texture_id = mask_resource_lock->texture_id(); 988 mask_texture_id = mask_resource_lock->texture_id();
1100 mask_sampler = SamplerTypeFromTextureTarget(mask_resource_lock->target()); 989 mask_sampler = SamplerTypeFromTextureTarget(mask_resource_lock->target());
1101 } 990 }
1102 991
1103 // TODO(danakj): use the background_texture and blend the background in with
1104 // this draw instead of having a separate copy of the background texture.
1105
1106 scoped_ptr<ResourceProvider::ScopedSamplerGL> contents_resource_lock; 992 scoped_ptr<ResourceProvider::ScopedSamplerGL> contents_resource_lock;
1107 if (filter_image) { 993 if (filter_image) {
1108 GrTexture* texture = filter_image->getTexture(); 994 GrTexture* texture = filter_image->getTexture();
1109 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_)); 995 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_));
1110 gl_->BindTexture(GL_TEXTURE_2D, texture->getTextureHandle()); 996 gl_->BindTexture(GL_TEXTURE_2D, texture->getTextureHandle());
1111 } else { 997 } else {
1112 contents_resource_lock = 998 contents_resource_lock =
1113 make_scoped_ptr(new ResourceProvider::ScopedSamplerGL( 999 make_scoped_ptr(new ResourceProvider::ScopedSamplerGL(
1114 resource_provider_, contents_texture->id(), GL_LINEAR)); 1000 resource_provider_, contents_texture->id(), GL_LINEAR));
1115 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), 1001 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D),
1116 contents_resource_lock->target()); 1002 contents_resource_lock->target());
1117 } 1003 }
1118 1004
1119 if (CanApplyBlendModeUsingBlendFunc(blend_mode)) { 1005 if (!use_shaders_for_blending) {
1120 if (!use_blend_equation_advanced_coherent_ && use_blend_equation_advanced_) 1006 if (!use_blend_equation_advanced_coherent_ && use_blend_equation_advanced_)
1121 GLC(gl_, gl_->BlendBarrierKHR()); 1007 GLC(gl_, gl_->BlendBarrierKHR());
1122 1008
1123 ApplyBlendModeUsingBlendFunc(blend_mode); 1009 ApplyBlendModeUsingBlendFunc(blend_mode);
1124 } 1010 }
1125 1011
1126 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( 1012 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired(
1127 gl_, 1013 gl_,
1128 &highp_threshold_cache_, 1014 &highp_threshold_cache_,
1129 highp_threshold_min_, 1015 highp_threshold_min_,
1130 quad->shared_quad_state->visible_content_rect.bottom_right()); 1016 quad->shared_quad_state->visible_content_rect.bottom_right());
1131 1017
1132 int shader_quad_location = -1; 1018 int shader_quad_location = -1;
1133 int shader_edge_location = -1; 1019 int shader_edge_location = -1;
1134 int shader_viewport_location = -1; 1020 int shader_viewport_location = -1;
1135 int shader_mask_sampler_location = -1; 1021 int shader_mask_sampler_location = -1;
1136 int shader_mask_tex_coord_scale_location = -1; 1022 int shader_mask_tex_coord_scale_location = -1;
1137 int shader_mask_tex_coord_offset_location = -1; 1023 int shader_mask_tex_coord_offset_location = -1;
1138 int shader_matrix_location = -1; 1024 int shader_matrix_location = -1;
1139 int shader_alpha_location = -1; 1025 int shader_alpha_location = -1;
1140 int shader_color_matrix_location = -1; 1026 int shader_color_matrix_location = -1;
1141 int shader_color_offset_location = -1; 1027 int shader_color_offset_location = -1;
1142 int shader_tex_transform_location = -1; 1028 int shader_tex_transform_location = -1;
1143 int shader_backdrop_location = -1; 1029 int shader_backdrop_location = -1;
1144 int shader_backdrop_rect_location = -1; 1030 int shader_backdrop_rect_location = -1;
1145 1031
1146 BlendMode shader_blend_mode = ((background_texture || background_image) && 1032 DCHECK_EQ(background_texture || background_image, use_shaders_for_blending);
1147 !CanApplyBlendModeUsingBlendFunc(blend_mode)) 1033 BlendMode shader_blend_mode = use_shaders_for_blending
1148 ? BlendModeFromSkXfermode(blend_mode) 1034 ? BlendModeFromSkXfermode(blend_mode)
1149 : BlendModeNormal; 1035 : BlendModeNone;
1150 1036
1151 if (use_aa && mask_texture_id && !use_color_matrix) { 1037 if (use_aa && mask_texture_id && !use_color_matrix) {
1152 const RenderPassMaskProgramAA* program = GetRenderPassMaskProgramAA( 1038 const RenderPassMaskProgramAA* program = GetRenderPassMaskProgramAA(
1153 tex_coord_precision, mask_sampler, shader_blend_mode); 1039 tex_coord_precision, mask_sampler, shader_blend_mode);
1154 SetUseProgram(program->program()); 1040 SetUseProgram(program->program());
1155 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0)); 1041 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0));
1156 1042
1157 shader_quad_location = program->vertex_shader().quad_location(); 1043 shader_quad_location = program->vertex_shader().quad_location();
1158 shader_edge_location = program->vertex_shader().edge_location(); 1044 shader_edge_location = program->vertex_shader().edge_location();
1159 shader_viewport_location = program->vertex_shader().viewport_location(); 1045 shader_viewport_location = program->vertex_shader().viewport_location();
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
1416 SetShaderOpacity(quad->opacity(), shader_alpha_location); 1302 SetShaderOpacity(quad->opacity(), shader_alpha_location);
1417 SetShaderQuadF(surface_quad, shader_quad_location); 1303 SetShaderQuadF(surface_quad, shader_quad_location);
1418 DrawQuadGeometry( 1304 DrawQuadGeometry(
1419 frame, quad->quadTransform(), quad->rect, shader_matrix_location); 1305 frame, quad->quadTransform(), quad->rect, shader_matrix_location);
1420 1306
1421 // Flush the compositor context before the filter bitmap goes out of 1307 // Flush the compositor context before the filter bitmap goes out of
1422 // scope, so the draw gets processed before the filter texture gets deleted. 1308 // scope, so the draw gets processed before the filter texture gets deleted.
1423 if (filter_image) 1309 if (filter_image)
1424 GLC(gl_, gl_->Flush()); 1310 GLC(gl_, gl_->Flush());
1425 1311
1426 if (CanApplyBlendModeUsingBlendFunc(blend_mode)) 1312 if (!use_shaders_for_blending)
1427 RestoreBlendFuncToDefault(blend_mode); 1313 RestoreBlendFuncToDefault(blend_mode);
1428 } 1314 }
1429 1315
1430 struct SolidColorProgramUniforms { 1316 struct SolidColorProgramUniforms {
1431 unsigned program; 1317 unsigned program;
1432 unsigned matrix_location; 1318 unsigned matrix_location;
1433 unsigned viewport_location; 1319 unsigned viewport_location;
1434 unsigned quad_location; 1320 unsigned quad_location;
1435 unsigned edge_location; 1321 unsigned edge_location;
1436 unsigned color_location; 1322 unsigned color_location;
(...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after
2089 on_demand_tile_raster_resource_id_ = resource_provider_->CreateGLTexture( 1975 on_demand_tile_raster_resource_id_ = resource_provider_->CreateGLTexture(
2090 quad->texture_size, 1976 quad->texture_size,
2091 GL_TEXTURE_2D, 1977 GL_TEXTURE_2D,
2092 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM, 1978 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM,
2093 GL_CLAMP_TO_EDGE, 1979 GL_CLAMP_TO_EDGE,
2094 ResourceProvider::TextureHintImmutable, 1980 ResourceProvider::TextureHintImmutable,
2095 quad->texture_format); 1981 quad->texture_format);
2096 } 1982 }
2097 1983
2098 SkCanvas canvas(on_demand_tile_raster_bitmap_); 1984 SkCanvas canvas(on_demand_tile_raster_bitmap_);
2099 quad->picture_pile->PlaybackToCanvas(&canvas, quad->content_rect, 1985 quad->raster_source->PlaybackToCanvas(&canvas, quad->content_rect,
2100 quad->contents_scale); 1986 quad->contents_scale);
2101 1987
2102 uint8_t* bitmap_pixels = NULL; 1988 uint8_t* bitmap_pixels = NULL;
2103 SkBitmap on_demand_tile_raster_bitmap_dest; 1989 SkBitmap on_demand_tile_raster_bitmap_dest;
2104 SkColorType colorType = ResourceFormatToSkColorType(quad->texture_format); 1990 SkColorType colorType = ResourceFormatToSkColorType(quad->texture_format);
2105 if (on_demand_tile_raster_bitmap_.colorType() != colorType) { 1991 if (on_demand_tile_raster_bitmap_.colorType() != colorType) {
2106 on_demand_tile_raster_bitmap_.copyTo(&on_demand_tile_raster_bitmap_dest, 1992 on_demand_tile_raster_bitmap_.copyTo(&on_demand_tile_raster_bitmap_dest,
2107 colorType); 1993 colorType);
2108 // TODO(kaanb): The GL pipeline assumes a 4-byte alignment for the 1994 // TODO(kaanb): The GL pipeline assumes a 4-byte alignment for the
2109 // bitmap data. This check will be removed once crbug.com/293728 is fixed. 1995 // bitmap data. This check will be removed once crbug.com/293728 is fixed.
2110 CHECK_EQ(0u, on_demand_tile_raster_bitmap_dest.rowBytes() % 4); 1996 CHECK_EQ(0u, on_demand_tile_raster_bitmap_dest.rowBytes() % 4);
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
2444 int matrix_location) { 2330 int matrix_location) {
2445 gfx::Transform quad_rect_matrix; 2331 gfx::Transform quad_rect_matrix;
2446 QuadRectTransform(&quad_rect_matrix, draw_transform, quad_rect); 2332 QuadRectTransform(&quad_rect_matrix, draw_transform, quad_rect);
2447 static float gl_matrix[16]; 2333 static float gl_matrix[16];
2448 ToGLMatrix(&gl_matrix[0], frame->projection_matrix * quad_rect_matrix); 2334 ToGLMatrix(&gl_matrix[0], frame->projection_matrix * quad_rect_matrix);
2449 GLC(gl_, gl_->UniformMatrix4fv(matrix_location, 1, false, &gl_matrix[0])); 2335 GLC(gl_, gl_->UniformMatrix4fv(matrix_location, 1, false, &gl_matrix[0]));
2450 2336
2451 GLC(gl_, gl_->DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0)); 2337 GLC(gl_, gl_->DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0));
2452 } 2338 }
2453 2339
2454 void GLRenderer::CopyTextureToFramebuffer(const DrawingFrame* frame,
2455 int texture_id,
2456 const gfx::Rect& rect,
2457 const gfx::Transform& draw_matrix,
2458 bool flip_vertically) {
2459 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired(
2460 gl_, &highp_threshold_cache_, highp_threshold_min_, rect.bottom_right());
2461
2462 const RenderPassProgram* program =
2463 GetRenderPassProgram(tex_coord_precision, BlendModeNormal);
2464 SetUseProgram(program->program());
2465
2466 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0));
2467
2468 if (flip_vertically) {
2469 GLC(gl_,
2470 gl_->Uniform4f(program->vertex_shader().tex_transform_location(),
2471 0.f,
2472 1.f,
2473 1.f,
2474 -1.f));
2475 } else {
2476 GLC(gl_,
2477 gl_->Uniform4f(program->vertex_shader().tex_transform_location(),
2478 0.f,
2479 0.f,
2480 1.f,
2481 1.f));
2482 }
2483
2484 SetShaderOpacity(1.f, program->fragment_shader().alpha_location());
2485 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_));
2486 GLC(gl_, gl_->BindTexture(GL_TEXTURE_2D, texture_id));
2487 DrawQuadGeometry(
2488 frame, draw_matrix, rect, program->vertex_shader().matrix_location());
2489 }
2490
2491 void GLRenderer::Finish() { 2340 void GLRenderer::Finish() {
2492 TRACE_EVENT0("cc", "GLRenderer::Finish"); 2341 TRACE_EVENT0("cc", "GLRenderer::Finish");
2493 GLC(gl_, gl_->Finish()); 2342 GLC(gl_, gl_->Finish());
2494 } 2343 }
2495 2344
2496 void GLRenderer::SwapBuffers(const CompositorFrameMetadata& metadata) { 2345 void GLRenderer::SwapBuffers(const CompositorFrameMetadata& metadata) {
2497 DCHECK(!is_backbuffer_discarded_); 2346 DCHECK(!is_backbuffer_discarded_);
2498 2347
2499 TRACE_EVENT0("cc,benchmark", "GLRenderer::SwapBuffers"); 2348 TRACE_EVENT0("cc,benchmark", "GLRenderer::SwapBuffers");
2500 // We're done! Time to swapbuffers! 2349 // We're done! Time to swapbuffers!
(...skipping 933 matching lines...) Expand 10 before | Expand all | Expand 10 after
3434 context_support_->ScheduleOverlayPlane( 3283 context_support_->ScheduleOverlayPlane(
3435 overlay.plane_z_order, 3284 overlay.plane_z_order,
3436 overlay.transform, 3285 overlay.transform,
3437 pending_overlay_resources_.back()->texture_id(), 3286 pending_overlay_resources_.back()->texture_id(),
3438 overlay.display_rect, 3287 overlay.display_rect,
3439 overlay.uv_rect); 3288 overlay.uv_rect);
3440 } 3289 }
3441 } 3290 }
3442 3291
3443 } // namespace cc 3292 } // namespace cc
OLDNEW
« no previous file with comments | « cc/output/gl_renderer.h ('k') | cc/output/gl_renderer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698