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

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

Issue 1980613003: cc: correctly fix edge-AA for filtered render surfaces. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix typo Created 4 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 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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 881 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 } 892 }
893 893
894 void GLRenderer::DrawRenderPassQuad(DrawingFrame* frame, 894 void GLRenderer::DrawRenderPassQuad(DrawingFrame* frame,
895 const RenderPassDrawQuad* quad, 895 const RenderPassDrawQuad* quad,
896 const gfx::QuadF* clip_region) { 896 const gfx::QuadF* clip_region) {
897 ScopedResource* contents_texture = 897 ScopedResource* contents_texture =
898 render_pass_textures_[quad->render_pass_id].get(); 898 render_pass_textures_[quad->render_pass_id].get();
899 DCHECK(contents_texture); 899 DCHECK(contents_texture);
900 DCHECK(contents_texture->id()); 900 DCHECK(contents_texture->id());
901 901
902 SkMatrix scale_matrix;
903 scale_matrix.setScale(quad->filters_scale.x(), quad->filters_scale.y());
904 gfx::RectF dst_rect(quad->filters.MapRect(quad->rect, scale_matrix));
902 gfx::Transform quad_rect_matrix; 905 gfx::Transform quad_rect_matrix;
903 QuadRectTransform(&quad_rect_matrix, 906 QuadRectTransform(&quad_rect_matrix,
904 quad->shared_quad_state->quad_to_target_transform, 907 quad->shared_quad_state->quad_to_target_transform,
905 gfx::RectF(quad->rect)); 908 dst_rect);
906 gfx::Transform contents_device_transform = 909 gfx::Transform contents_device_transform =
907 frame->window_matrix * frame->projection_matrix * quad_rect_matrix; 910 frame->window_matrix * frame->projection_matrix * quad_rect_matrix;
908 contents_device_transform.FlattenTo2d(); 911 contents_device_transform.FlattenTo2d();
909 912
910 // Can only draw surface if device matrix is invertible. 913 // Can only draw surface if device matrix is invertible.
911 if (!contents_device_transform.IsInvertible()) 914 if (!contents_device_transform.IsInvertible())
912 return; 915 return;
913 916
914 gfx::QuadF surface_quad = SharedGeometryQuad(); 917 gfx::QuadF surface_quad = SharedGeometryQuad();
915 918
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1009 sk_sp<SkColorFilter> cf(colorfilter_rawptr); 1012 sk_sp<SkColorFilter> cf(colorfilter_rawptr);
1010 1013
1011 if (cf && cf->asColorMatrix(color_matrix)) { 1014 if (cf && cf->asColorMatrix(color_matrix)) {
1012 // We have a color matrix at the root of the filter DAG; apply it 1015 // We have a color matrix at the root of the filter DAG; apply it
1013 // locally in the compositor and process the rest of the DAG (if any) 1016 // locally in the compositor and process the rest of the DAG (if any)
1014 // in Skia. 1017 // in Skia.
1015 use_color_matrix = true; 1018 use_color_matrix = true;
1016 filter = sk_ref_sp(filter->getInput(0)); 1019 filter = sk_ref_sp(filter->getInput(0));
1017 } 1020 }
1018 if (filter) { 1021 if (filter) {
1019 gfx::Vector2dF scale = quad->filters_scale;
1020 SkMatrix scale_matrix;
1021 scale_matrix.setScale(scale.x(), scale.y());
1022 SkIRect result_rect =
1023 filter->filterBounds(gfx::RectToSkIRect(quad->rect), scale_matrix,
1024 SkImageFilter::kForward_MapDirection);
1025 gfx::RectF dst_rect = gfx::SkRectToRectF(SkRect::Make(result_rect));
1026 // If the destination rect is not the same as the source rect, the edges
1027 // previously computed for AA will be wrong. Rather than recompute them
1028 // here, disable antialiasing and use a 1-pixel transparent
1029 // border to achieve a similar effect.
1030 if (use_aa && dst_rect != rect) {
1031 dst_rect.Inset(-1.0f, -1.0f);
1032 use_aa = false;
1033 }
1034 gfx::Rect clip_rect = quad->shared_quad_state->clip_rect; 1022 gfx::Rect clip_rect = quad->shared_quad_state->clip_rect;
1035 if (clip_rect.IsEmpty()) { 1023 if (clip_rect.IsEmpty()) {
1036 clip_rect = current_draw_rect_; 1024 clip_rect = current_draw_rect_;
1037 } 1025 }
1038 gfx::Transform transform = 1026 gfx::Transform transform =
1039 quad->shared_quad_state->quad_to_target_transform; 1027 quad->shared_quad_state->quad_to_target_transform;
1040 gfx::QuadF clip_quad = gfx::QuadF(gfx::RectF(clip_rect)); 1028 gfx::QuadF clip_quad = gfx::QuadF(gfx::RectF(clip_rect));
1041 gfx::QuadF local_clip = MapQuadToLocalSpace(transform, clip_quad); 1029 gfx::QuadF local_clip = MapQuadToLocalSpace(transform, clip_quad);
1042 dst_rect.Intersect(local_clip.BoundingBox()); 1030 dst_rect.Intersect(local_clip.BoundingBox());
1043 // If we've been fully clipped out (by crop rect or clipping), there's 1031 // If we've been fully clipped out (by crop rect or clipping), there's
1044 // nothing to draw. 1032 // nothing to draw.
1045 if (dst_rect.IsEmpty()) { 1033 if (dst_rect.IsEmpty()) {
1046 return; 1034 return;
1047 } 1035 }
1048 // Expand dst_rect size to the nearest power of 2, in order to get 1036 // Expand dst_rect size to the nearest power of 2, in order to get
1049 // more cache hits in Skia's texture cache. 1037 // more cache hits in Skia's texture cache.
1050 RoundUpToPow2(&dst_rect); 1038 RoundUpToPow2(&dst_rect);
1051 filter_image = ApplyImageFilter( 1039 filter_image = ApplyImageFilter(
1052 ScopedUseGrContext::Create(this, frame), resource_provider_, rect, 1040 ScopedUseGrContext::Create(this, frame), resource_provider_, rect,
1053 dst_rect, scale, std::move(filter), contents_texture); 1041 dst_rect, quad->filters_scale, std::move(filter), contents_texture);
1054 if (filter_image) { 1042 if (!filter_image) {
1055 filter_image_id = skia::GrBackendObjectToGrGLTextureInfo( 1043 return;
1056 filter_image->getTextureHandle(true))
1057 ->fID;
1058 DCHECK(filter_image_id);
1059 rect = dst_rect;
1060 } 1044 }
1045 filter_image_id = skia::GrBackendObjectToGrGLTextureInfo(
1046 filter_image->getTextureHandle(true))
1047 ->fID;
1048 DCHECK(filter_image_id);
1061 } 1049 }
1062 } 1050 }
1063 } 1051 }
1064 1052
1065 std::unique_ptr<ResourceProvider::ScopedSamplerGL> mask_resource_lock; 1053 std::unique_ptr<ResourceProvider::ScopedSamplerGL> mask_resource_lock;
1066 unsigned mask_texture_id = 0; 1054 unsigned mask_texture_id = 0;
1067 SamplerType mask_sampler = SAMPLER_TYPE_NA; 1055 SamplerType mask_sampler = SAMPLER_TYPE_NA;
1068 if (quad->mask_resource_id()) { 1056 if (quad->mask_resource_id()) {
1069 mask_resource_lock.reset(new ResourceProvider::ScopedSamplerGL( 1057 mask_resource_lock.reset(new ResourceProvider::ScopedSamplerGL(
1070 resource_provider_, quad->mask_resource_id(), GL_TEXTURE1, GL_LINEAR)); 1058 resource_provider_, quad->mask_resource_id(), GL_TEXTURE1, GL_LINEAR));
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
1269 resource_provider_, background_texture->id(), 1257 resource_provider_, background_texture->id(),
1270 GL_TEXTURE0 + last_texture_unit, GL_LINEAR)); 1258 GL_TEXTURE0 + last_texture_unit, GL_LINEAR));
1271 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), 1259 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D),
1272 shader_background_sampler_lock->target()); 1260 shader_background_sampler_lock->target());
1273 } 1261 }
1274 } 1262 }
1275 1263
1276 SetShaderOpacity(quad->shared_quad_state->opacity, locations.alpha); 1264 SetShaderOpacity(quad->shared_quad_state->opacity, locations.alpha);
1277 SetShaderQuadF(surface_quad, locations.quad); 1265 SetShaderQuadF(surface_quad, locations.quad);
1278 DrawQuadGeometry(frame, quad->shared_quad_state->quad_to_target_transform, 1266 DrawQuadGeometry(frame, quad->shared_quad_state->quad_to_target_transform,
1279 rect, locations.matrix); 1267 dst_rect, locations.matrix);
1280 1268
1281 // Flush the compositor context before the filter bitmap goes out of 1269 // Flush the compositor context before the filter bitmap goes out of
1282 // scope, so the draw gets processed before the filter texture gets deleted. 1270 // scope, so the draw gets processed before the filter texture gets deleted.
1283 if (filter_image_id) 1271 if (filter_image_id)
1284 gl_->Flush(); 1272 gl_->Flush();
1285 1273
1286 if (!use_shaders_for_blending) 1274 if (!use_shaders_for_blending)
1287 RestoreBlendFuncToDefault(blend_mode); 1275 RestoreBlendFuncToDefault(blend_mode);
1288 } 1276 }
1289 1277
(...skipping 2374 matching lines...) Expand 10 before | Expand all | Expand 10 after
3664 texture_id = pending_overlay_resources_.back()->texture_id(); 3652 texture_id = pending_overlay_resources_.back()->texture_id();
3665 } 3653 }
3666 3654
3667 context_support_->ScheduleOverlayPlane( 3655 context_support_->ScheduleOverlayPlane(
3668 overlay.plane_z_order, overlay.transform, texture_id, 3656 overlay.plane_z_order, overlay.transform, texture_id,
3669 ToNearestRect(overlay.display_rect), overlay.uv_rect); 3657 ToNearestRect(overlay.display_rect), overlay.uv_rect);
3670 } 3658 }
3671 } 3659 }
3672 3660
3673 } // namespace cc 3661 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698