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 <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 GLC(gl_, gl_->LineWidth(quad->width)); | 618 GLC(gl_, gl_->LineWidth(quad->width)); |
619 | 619 |
620 // The indices for the line are stored in the same array as the triangle | 620 // The indices for the line are stored in the same array as the triangle |
621 // indices. | 621 // indices. |
622 GLC(gl_, gl_->DrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_SHORT, 0)); | 622 GLC(gl_, gl_->DrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_SHORT, 0)); |
623 } | 623 } |
624 | 624 |
625 static skia::RefPtr<SkImage> ApplyImageFilter( | 625 static skia::RefPtr<SkImage> ApplyImageFilter( |
626 scoped_ptr<GLRenderer::ScopedUseGrContext> use_gr_context, | 626 scoped_ptr<GLRenderer::ScopedUseGrContext> use_gr_context, |
627 ResourceProvider* resource_provider, | 627 ResourceProvider* resource_provider, |
628 const gfx::Point& origin, | 628 const gfx::Rect& rect, |
629 const gfx::Vector2dF& scale, | 629 const gfx::Vector2dF& scale, |
630 SkImageFilter* filter, | 630 SkImageFilter* filter, |
631 ScopedResource* source_texture_resource) { | 631 ScopedResource* source_texture_resource) { |
632 if (!filter) | 632 if (!filter) |
633 return skia::RefPtr<SkImage>(); | 633 return skia::RefPtr<SkImage>(); |
634 | 634 |
635 if (!use_gr_context) | 635 if (!use_gr_context) |
636 return skia::RefPtr<SkImage>(); | 636 return skia::RefPtr<SkImage>(); |
637 | 637 |
638 ResourceProvider::ScopedReadLockGL lock(resource_provider, | 638 ResourceProvider::ScopedReadLockGL lock(resource_provider, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
687 // Create surface to draw into. | 687 // Create surface to draw into. |
688 skia::RefPtr<SkSurface> surface = skia::AdoptRef( | 688 skia::RefPtr<SkSurface> surface = skia::AdoptRef( |
689 SkSurface::NewRenderTargetDirect(backing_store->asRenderTarget())); | 689 SkSurface::NewRenderTargetDirect(backing_store->asRenderTarget())); |
690 skia::RefPtr<SkCanvas> canvas = skia::SharePtr(surface->getCanvas()); | 690 skia::RefPtr<SkCanvas> canvas = skia::SharePtr(surface->getCanvas()); |
691 | 691 |
692 // Draw the source bitmap through the filter to the canvas. | 692 // Draw the source bitmap through the filter to the canvas. |
693 SkPaint paint; | 693 SkPaint paint; |
694 paint.setImageFilter(filter); | 694 paint.setImageFilter(filter); |
695 canvas->clear(SK_ColorTRANSPARENT); | 695 canvas->clear(SK_ColorTRANSPARENT); |
696 | 696 |
697 canvas->translate(SkIntToScalar(-origin.x()), SkIntToScalar(-origin.y())); | 697 // The origin of the filter is top-left and the origin of the source is |
| 698 // bottom-left, but the orientation is the same, so we must translate the |
| 699 // filter so that it renders at the bottom of the texture to avoid |
| 700 // misregistration. |
| 701 int y_translate = source.height() - rect.height() - rect.origin().y(); |
| 702 canvas->translate(-rect.origin().x(), y_translate); |
698 canvas->scale(scale.x(), scale.y()); | 703 canvas->scale(scale.x(), scale.y()); |
699 canvas->drawSprite(source, 0, 0, &paint); | 704 canvas->drawSprite(source, 0, 0, &paint); |
700 | 705 |
701 skia::RefPtr<SkImage> image = skia::AdoptRef(surface->newImageSnapshot()); | 706 skia::RefPtr<SkImage> image = skia::AdoptRef(surface->newImageSnapshot()); |
702 if (!image || !image->getTexture()) { | 707 if (!image || !image->getTexture()) { |
703 return skia::RefPtr<SkImage>(); | 708 return skia::RefPtr<SkImage>(); |
704 } | 709 } |
705 | 710 |
706 // Flush the GrContext to ensure all buffered GL calls are drawn to the | 711 // Flush the GrContext to ensure all buffered GL calls are drawn to the |
707 // backing store before we access and return it, and have cc begin using the | 712 // backing store before we access and return it, and have cc begin using the |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
852 } | 857 } |
853 | 858 |
854 skia::RefPtr<SkImage> GLRenderer::ApplyBackgroundFilters( | 859 skia::RefPtr<SkImage> GLRenderer::ApplyBackgroundFilters( |
855 DrawingFrame* frame, | 860 DrawingFrame* frame, |
856 const RenderPassDrawQuad* quad, | 861 const RenderPassDrawQuad* quad, |
857 ScopedResource* background_texture) { | 862 ScopedResource* background_texture) { |
858 DCHECK(ShouldApplyBackgroundFilters(frame, quad)); | 863 DCHECK(ShouldApplyBackgroundFilters(frame, quad)); |
859 skia::RefPtr<SkImageFilter> filter = RenderSurfaceFilters::BuildImageFilter( | 864 skia::RefPtr<SkImageFilter> filter = RenderSurfaceFilters::BuildImageFilter( |
860 quad->background_filters, background_texture->size()); | 865 quad->background_filters, background_texture->size()); |
861 | 866 |
862 skia::RefPtr<SkImage> background_with_filters = | 867 skia::RefPtr<SkImage> background_with_filters = ApplyImageFilter( |
863 ApplyImageFilter(ScopedUseGrContext::Create(this, frame), | 868 ScopedUseGrContext::Create(this, frame), resource_provider_, quad->rect, |
864 resource_provider_, | 869 quad->filters_scale, filter.get(), background_texture); |
865 quad->rect.origin(), | |
866 quad->filters_scale, | |
867 filter.get(), | |
868 background_texture); | |
869 return background_with_filters; | 870 return background_with_filters; |
870 } | 871 } |
871 | 872 |
872 void GLRenderer::DrawRenderPassQuad(DrawingFrame* frame, | 873 void GLRenderer::DrawRenderPassQuad(DrawingFrame* frame, |
873 const RenderPassDrawQuad* quad) { | 874 const RenderPassDrawQuad* quad) { |
874 ScopedResource* contents_texture = | 875 ScopedResource* contents_texture = |
875 render_pass_textures_.get(quad->render_pass_id); | 876 render_pass_textures_.get(quad->render_pass_id); |
876 if (!contents_texture || !contents_texture->id()) | 877 if (!contents_texture || !contents_texture->id()) |
877 return; | 878 return; |
878 | 879 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
964 SkColorFilter* colorfilter_rawptr = NULL; | 965 SkColorFilter* colorfilter_rawptr = NULL; |
965 filter->asColorFilter(&colorfilter_rawptr); | 966 filter->asColorFilter(&colorfilter_rawptr); |
966 cf = skia::AdoptRef(colorfilter_rawptr); | 967 cf = skia::AdoptRef(colorfilter_rawptr); |
967 } | 968 } |
968 | 969 |
969 if (cf && cf->asColorMatrix(color_matrix) && !filter->getInput(0)) { | 970 if (cf && cf->asColorMatrix(color_matrix) && !filter->getInput(0)) { |
970 // We have a single color matrix as a filter; apply it locally | 971 // We have a single color matrix as a filter; apply it locally |
971 // in the compositor. | 972 // in the compositor. |
972 use_color_matrix = true; | 973 use_color_matrix = true; |
973 } else { | 974 } else { |
974 filter_image = ApplyImageFilter(ScopedUseGrContext::Create(this, frame), | 975 filter_image = ApplyImageFilter( |
975 resource_provider_, | 976 ScopedUseGrContext::Create(this, frame), resource_provider_, |
976 quad->rect.origin(), | 977 quad->rect, quad->filters_scale, filter.get(), contents_texture); |
977 quad->filters_scale, | |
978 filter.get(), | |
979 contents_texture); | |
980 } | 978 } |
981 } | 979 } |
982 } | 980 } |
983 | 981 |
984 scoped_ptr<ResourceProvider::ScopedSamplerGL> mask_resource_lock; | 982 scoped_ptr<ResourceProvider::ScopedSamplerGL> mask_resource_lock; |
985 unsigned mask_texture_id = 0; | 983 unsigned mask_texture_id = 0; |
986 SamplerType mask_sampler = SamplerTypeNA; | 984 SamplerType mask_sampler = SamplerTypeNA; |
987 if (quad->mask_resource_id) { | 985 if (quad->mask_resource_id) { |
988 mask_resource_lock.reset(new ResourceProvider::ScopedSamplerGL( | 986 mask_resource_lock.reset(new ResourceProvider::ScopedSamplerGL( |
989 resource_provider_, quad->mask_resource_id, GL_TEXTURE1, GL_LINEAR)); | 987 resource_provider_, quad->mask_resource_id, GL_TEXTURE1, GL_LINEAR)); |
(...skipping 2318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3308 context_support_->ScheduleOverlayPlane( | 3306 context_support_->ScheduleOverlayPlane( |
3309 overlay.plane_z_order, | 3307 overlay.plane_z_order, |
3310 overlay.transform, | 3308 overlay.transform, |
3311 pending_overlay_resources_.back()->texture_id(), | 3309 pending_overlay_resources_.back()->texture_id(), |
3312 overlay.display_rect, | 3310 overlay.display_rect, |
3313 overlay.uv_rect); | 3311 overlay.uv_rect); |
3314 } | 3312 } |
3315 } | 3313 } |
3316 | 3314 |
3317 } // namespace cc | 3315 } // namespace cc |
OLD | NEW |