| OLD | NEW |
| 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 844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 855 DCHECK(ShouldApplyBackgroundFilters(quad)); | 855 DCHECK(ShouldApplyBackgroundFilters(quad)); |
| 856 skia::RefPtr<SkImageFilter> filter = RenderSurfaceFilters::BuildImageFilter( | 856 skia::RefPtr<SkImageFilter> filter = RenderSurfaceFilters::BuildImageFilter( |
| 857 quad->background_filters, gfx::SizeF(background_texture->size())); | 857 quad->background_filters, gfx::SizeF(background_texture->size())); |
| 858 | 858 |
| 859 skia::RefPtr<SkImage> background_with_filters = ApplyImageFilter( | 859 skia::RefPtr<SkImage> background_with_filters = ApplyImageFilter( |
| 860 ScopedUseGrContext::Create(this, frame), resource_provider_, rect, rect, | 860 ScopedUseGrContext::Create(this, frame), resource_provider_, rect, rect, |
| 861 quad->filters_scale, filter.get(), background_texture); | 861 quad->filters_scale, filter.get(), background_texture); |
| 862 return background_with_filters; | 862 return background_with_filters; |
| 863 } | 863 } |
| 864 | 864 |
| 865 // Map device space quad to local space. Device_transform has no 3d |
| 866 // component since it was flattened, so we don't need to project. We should |
| 867 // have already checked that the transform was uninvertible before this call. |
| 868 gfx::QuadF MapQuadToLocalSpace(const gfx::Transform& device_transform, |
| 869 const gfx::QuadF& device_quad) { |
| 870 gfx::Transform inverse_device_transform(gfx::Transform::kSkipInitialization); |
| 871 DCHECK(device_transform.IsInvertible()); |
| 872 bool did_invert = device_transform.GetInverse(&inverse_device_transform); |
| 873 DCHECK(did_invert); |
| 874 bool clipped = false; |
| 875 gfx::QuadF local_quad = |
| 876 MathUtil::MapQuad(inverse_device_transform, device_quad, &clipped); |
| 877 // We should not DCHECK(!clipped) here, because anti-aliasing inflation may |
| 878 // cause device_quad to become clipped. To our knowledge this scenario does |
| 879 // not need to be handled differently than the unclipped case. |
| 880 return local_quad; |
| 881 } |
| 882 |
| 865 void GLRenderer::DrawRenderPassQuad(DrawingFrame* frame, | 883 void GLRenderer::DrawRenderPassQuad(DrawingFrame* frame, |
| 866 const RenderPassDrawQuad* quad, | 884 const RenderPassDrawQuad* quad, |
| 867 const gfx::QuadF* clip_region) { | 885 const gfx::QuadF* clip_region) { |
| 868 ScopedResource* contents_texture = | 886 ScopedResource* contents_texture = |
| 869 render_pass_textures_[quad->render_pass_id].get(); | 887 render_pass_textures_[quad->render_pass_id].get(); |
| 870 DCHECK(contents_texture); | 888 DCHECK(contents_texture); |
| 871 DCHECK(contents_texture->id()); | 889 DCHECK(contents_texture->id()); |
| 872 | 890 |
| 873 gfx::Transform quad_rect_matrix; | 891 gfx::Transform quad_rect_matrix; |
| 874 QuadRectTransform(&quad_rect_matrix, | 892 QuadRectTransform(&quad_rect_matrix, |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 979 SkColorFilter* colorfilter_rawptr = NULL; | 997 SkColorFilter* colorfilter_rawptr = NULL; |
| 980 filter->asColorFilter(&colorfilter_rawptr); | 998 filter->asColorFilter(&colorfilter_rawptr); |
| 981 cf = skia::AdoptRef(colorfilter_rawptr); | 999 cf = skia::AdoptRef(colorfilter_rawptr); |
| 982 } | 1000 } |
| 983 | 1001 |
| 984 if (cf && cf->asColorMatrix(color_matrix) && !filter->getInput(0)) { | 1002 if (cf && cf->asColorMatrix(color_matrix) && !filter->getInput(0)) { |
| 985 // We have a single color matrix as a filter; apply it locally | 1003 // We have a single color matrix as a filter; apply it locally |
| 986 // in the compositor. | 1004 // in the compositor. |
| 987 use_color_matrix = true; | 1005 use_color_matrix = true; |
| 988 } else { | 1006 } else { |
| 989 gfx::RectF src_rect = rect; | |
| 990 gfx::Vector2dF scale = quad->filters_scale; | 1007 gfx::Vector2dF scale = quad->filters_scale; |
| 991 SkMatrix scale_matrix; | 1008 SkMatrix scale_matrix; |
| 992 scale_matrix.setScale(scale.x(), scale.y()); | 1009 scale_matrix.setScale(scale.x(), scale.y()); |
| 993 SkIRect result_rect; | 1010 SkIRect result_rect; |
| 994 filter->filterBounds(gfx::RectToSkIRect(quad->rect), scale_matrix, | 1011 filter->filterBounds(gfx::RectToSkIRect(quad->rect), scale_matrix, |
| 995 &result_rect, | 1012 &result_rect, |
| 996 SkImageFilter::kForward_MapDirection); | 1013 SkImageFilter::kForward_MapDirection); |
| 997 rect = gfx::SkRectToRectF(SkRect::Make(result_rect)); | 1014 gfx::RectF dst_rect = gfx::SkRectToRectF(SkRect::Make(result_rect)); |
| 1015 gfx::Rect clip_rect = quad->shared_quad_state->clip_rect; |
| 1016 if (clip_rect.IsEmpty()) { |
| 1017 clip_rect = current_draw_rect_; |
| 1018 } |
| 1019 gfx::Transform transform = |
| 1020 quad->shared_quad_state->quad_to_target_transform; |
| 1021 gfx::QuadF clip_quad = gfx::QuadF(gfx::RectF(clip_rect)); |
| 1022 gfx::QuadF local_clip = MapQuadToLocalSpace(transform, clip_quad); |
| 1023 dst_rect.Intersect(local_clip.BoundingBox()); |
| 1024 // If we've been fully clipped out (by crop rect or clipping), there's |
| 1025 // nothing to draw. |
| 1026 if (dst_rect.IsEmpty()) { |
| 1027 return; |
| 1028 } |
| 998 filter_image = ApplyImageFilter(ScopedUseGrContext::Create(this, frame), | 1029 filter_image = ApplyImageFilter(ScopedUseGrContext::Create(this, frame), |
| 999 resource_provider_, src_rect, rect, | 1030 resource_provider_, rect, dst_rect, |
| 1000 scale, filter.get(), contents_texture); | 1031 scale, filter.get(), contents_texture); |
| 1001 if (filter_image) { | 1032 if (filter_image) { |
| 1002 filter_image_id = filter_image->getTextureHandle(true); | 1033 filter_image_id = filter_image->getTextureHandle(true); |
| 1003 DCHECK(filter_image_id); | 1034 DCHECK(filter_image_id); |
| 1035 rect = dst_rect; |
| 1004 } | 1036 } |
| 1005 } | 1037 } |
| 1006 } | 1038 } |
| 1007 } | 1039 } |
| 1008 | 1040 |
| 1009 scoped_ptr<ResourceProvider::ScopedSamplerGL> mask_resource_lock; | 1041 scoped_ptr<ResourceProvider::ScopedSamplerGL> mask_resource_lock; |
| 1010 unsigned mask_texture_id = 0; | 1042 unsigned mask_texture_id = 0; |
| 1011 SamplerType mask_sampler = SAMPLER_TYPE_NA; | 1043 SamplerType mask_sampler = SAMPLER_TYPE_NA; |
| 1012 if (quad->mask_resource_id()) { | 1044 if (quad->mask_resource_id()) { |
| 1013 mask_resource_lock.reset(new ResourceProvider::ScopedSamplerGL( | 1045 mask_resource_lock.reset(new ResourceProvider::ScopedSamplerGL( |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1377 clipped_quad->Realign(1); | 1409 clipped_quad->Realign(1); |
| 1378 float new_error = GetTotalQuadError(clipped_quad, &bounding_quad); | 1410 float new_error = GetTotalQuadError(clipped_quad, &bounding_quad); |
| 1379 if (new_error < least_error_amount) { | 1411 if (new_error < least_error_amount) { |
| 1380 least_error_amount = new_error; | 1412 least_error_amount = new_error; |
| 1381 best_rotation = *clipped_quad; | 1413 best_rotation = *clipped_quad; |
| 1382 } | 1414 } |
| 1383 } | 1415 } |
| 1384 *clipped_quad = best_rotation; | 1416 *clipped_quad = best_rotation; |
| 1385 } | 1417 } |
| 1386 | 1418 |
| 1387 // Map device space quad to local space. Device_transform has no 3d | |
| 1388 // component since it was flattened, so we don't need to project. We should | |
| 1389 // have already checked that the transform was uninvertible before this call. | |
| 1390 gfx::QuadF MapQuadToLocalSpace(const gfx::Transform& device_transform, | |
| 1391 const gfx::QuadF& device_quad) { | |
| 1392 gfx::Transform inverse_device_transform(gfx::Transform::kSkipInitialization); | |
| 1393 DCHECK(device_transform.IsInvertible()); | |
| 1394 bool did_invert = device_transform.GetInverse(&inverse_device_transform); | |
| 1395 DCHECK(did_invert); | |
| 1396 bool clipped = false; | |
| 1397 gfx::QuadF local_quad = | |
| 1398 MathUtil::MapQuad(inverse_device_transform, device_quad, &clipped); | |
| 1399 // We should not DCHECK(!clipped) here, because anti-aliasing inflation may | |
| 1400 // cause device_quad to become clipped. To our knowledge this scenario does | |
| 1401 // not need to be handled differently than the unclipped case. | |
| 1402 return local_quad; | |
| 1403 } | |
| 1404 | |
| 1405 void InflateAntiAliasingDistances(const gfx::QuadF& quad, | 1419 void InflateAntiAliasingDistances(const gfx::QuadF& quad, |
| 1406 LayerQuad* device_layer_edges, | 1420 LayerQuad* device_layer_edges, |
| 1407 float edge[24]) { | 1421 float edge[24]) { |
| 1408 DCHECK(!quad.BoundingBox().IsEmpty()); | 1422 DCHECK(!quad.BoundingBox().IsEmpty()); |
| 1409 LayerQuad device_layer_bounds(gfx::QuadF(quad.BoundingBox())); | 1423 LayerQuad device_layer_bounds(gfx::QuadF(quad.BoundingBox())); |
| 1410 | 1424 |
| 1411 device_layer_edges->InflateAntiAliasingDistance(); | 1425 device_layer_edges->InflateAntiAliasingDistance(); |
| 1412 device_layer_edges->ToFloatArray(edge); | 1426 device_layer_edges->ToFloatArray(edge); |
| 1413 | 1427 |
| 1414 device_layer_bounds.InflateAntiAliasingDistance(); | 1428 device_layer_bounds.InflateAntiAliasingDistance(); |
| (...skipping 2182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3597 texture_id = pending_overlay_resources_.back()->texture_id(); | 3611 texture_id = pending_overlay_resources_.back()->texture_id(); |
| 3598 } | 3612 } |
| 3599 | 3613 |
| 3600 context_support_->ScheduleOverlayPlane( | 3614 context_support_->ScheduleOverlayPlane( |
| 3601 overlay.plane_z_order, overlay.transform, texture_id, | 3615 overlay.plane_z_order, overlay.transform, texture_id, |
| 3602 ToNearestRect(overlay.display_rect), overlay.uv_rect); | 3616 ToNearestRect(overlay.display_rect), overlay.uv_rect); |
| 3603 } | 3617 } |
| 3604 } | 3618 } |
| 3605 | 3619 |
| 3606 } // namespace cc | 3620 } // namespace cc |
| OLD | NEW |