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 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
587 (SkColorGetG(color) * (1.0f / 255.0f)) * alpha, | 587 (SkColorGetG(color) * (1.0f / 255.0f)) * alpha, |
588 (SkColorGetB(color) * (1.0f / 255.0f)) * alpha, alpha); | 588 (SkColorGetB(color) * (1.0f / 255.0f)) * alpha, alpha); |
589 | 589 |
590 gl_->LineWidth(quad->width); | 590 gl_->LineWidth(quad->width); |
591 | 591 |
592 // The indices for the line are stored in the same array as the triangle | 592 // The indices for the line are stored in the same array as the triangle |
593 // indices. | 593 // indices. |
594 gl_->DrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_SHORT, 0); | 594 gl_->DrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_SHORT, 0); |
595 } | 595 } |
596 | 596 |
597 static skia::RefPtr<SkImage> ApplyImageFilter( | 597 static sk_sp<SkImage> ApplyImageFilter( |
598 std::unique_ptr<GLRenderer::ScopedUseGrContext> use_gr_context, | 598 std::unique_ptr<GLRenderer::ScopedUseGrContext> use_gr_context, |
599 ResourceProvider* resource_provider, | 599 ResourceProvider* resource_provider, |
600 const gfx::RectF& src_rect, | 600 const gfx::RectF& src_rect, |
601 const gfx::RectF& dst_rect, | 601 const gfx::RectF& dst_rect, |
602 const gfx::Vector2dF& scale, | 602 const gfx::Vector2dF& scale, |
603 SkImageFilter* filter, | 603 SkImageFilter* filter, |
604 ScopedResource* source_texture_resource) { | 604 ScopedResource* source_texture_resource) { |
605 if (!filter) | 605 if (!filter) |
606 return skia::RefPtr<SkImage>(); | 606 return nullptr; |
607 | 607 |
608 if (!use_gr_context) | 608 if (!use_gr_context) |
609 return skia::RefPtr<SkImage>(); | 609 return nullptr; |
610 | 610 |
611 ResourceProvider::ScopedReadLockGL lock(resource_provider, | 611 ResourceProvider::ScopedReadLockGL lock(resource_provider, |
612 source_texture_resource->id()); | 612 source_texture_resource->id()); |
613 | 613 |
614 // Wrap the source texture in a Ganesh platform texture. | 614 // Wrap the source texture in a Ganesh platform texture. |
615 GrBackendTextureDesc backend_texture_description; | 615 GrBackendTextureDesc backend_texture_description; |
616 GrGLTextureInfo texture_info; | 616 GrGLTextureInfo texture_info; |
617 texture_info.fTarget = lock.target(); | 617 texture_info.fTarget = lock.target(); |
618 texture_info.fID = lock.texture_id(); | 618 texture_info.fID = lock.texture_id(); |
619 backend_texture_description.fWidth = source_texture_resource->size().width(); | 619 backend_texture_description.fWidth = source_texture_resource->size().width(); |
620 backend_texture_description.fHeight = | 620 backend_texture_description.fHeight = |
621 source_texture_resource->size().height(); | 621 source_texture_resource->size().height(); |
622 backend_texture_description.fConfig = kSkia8888_GrPixelConfig; | 622 backend_texture_description.fConfig = kSkia8888_GrPixelConfig; |
623 backend_texture_description.fTextureHandle = | 623 backend_texture_description.fTextureHandle = |
624 skia::GrGLTextureInfoToGrBackendObject(texture_info); | 624 skia::GrGLTextureInfoToGrBackendObject(texture_info); |
625 backend_texture_description.fOrigin = kBottomLeft_GrSurfaceOrigin; | 625 backend_texture_description.fOrigin = kBottomLeft_GrSurfaceOrigin; |
626 | 626 |
627 skia::RefPtr<SkImage> srcImage = skia::AdoptRef(SkImage::NewFromTexture( | 627 sk_sp<SkImage> srcImage = SkImage::MakeFromTexture( |
danakj
2016/04/25 22:06:23
nit: while you're here.. src_image?
tomhudson
2016/04/27 12:06:47
Done.
| |
628 use_gr_context->context(), backend_texture_description)); | 628 use_gr_context->context(), backend_texture_description); |
629 if (!srcImage.get()) { | 629 if (!srcImage) { |
630 TRACE_EVENT_INSTANT0("cc", | 630 TRACE_EVENT_INSTANT0("cc", |
631 "ApplyImageFilter wrap background texture failed", | 631 "ApplyImageFilter wrap background texture failed", |
632 TRACE_EVENT_SCOPE_THREAD); | 632 TRACE_EVENT_SCOPE_THREAD); |
633 return skia::RefPtr<SkImage>(); | 633 return nullptr; |
634 } | 634 } |
635 | 635 |
636 // Create surface to draw into. | 636 // Create surface to draw into. |
637 SkImageInfo dst_info = | 637 SkImageInfo dst_info = |
638 SkImageInfo::MakeN32Premul(dst_rect.width(), dst_rect.height()); | 638 SkImageInfo::MakeN32Premul(dst_rect.width(), dst_rect.height()); |
639 sk_sp<SkSurface> surface = SkSurface::MakeRenderTarget( | 639 sk_sp<SkSurface> surface = SkSurface::MakeRenderTarget( |
640 use_gr_context->context(), SkBudgeted::kYes, dst_info); | 640 use_gr_context->context(), SkBudgeted::kYes, dst_info); |
641 if (!surface) { | 641 if (!surface) { |
642 TRACE_EVENT_INSTANT0("cc", "ApplyImageFilter surface allocation failed", | 642 TRACE_EVENT_INSTANT0("cc", "ApplyImageFilter surface allocation failed", |
643 TRACE_EVENT_SCOPE_THREAD); | 643 TRACE_EVENT_SCOPE_THREAD); |
644 return skia::RefPtr<SkImage>(); | 644 return nullptr; |
645 } | 645 } |
646 | 646 |
647 SkMatrix local_matrix; | 647 SkMatrix local_matrix; |
648 local_matrix.setScale(scale.x(), scale.y()); | 648 local_matrix.setScale(scale.x(), scale.y()); |
649 | 649 |
650 SkPaint paint; | 650 SkPaint paint; |
651 paint.setImageFilter(filter->makeWithLocalMatrix(local_matrix)); | 651 paint.setImageFilter(filter->makeWithLocalMatrix(local_matrix)); |
danakj
2016/04/25 22:06:23
The SkPaint is taking ownership of this filter rig
tomhudson
2016/04/27 12:06:47
Done.
| |
652 surface->getCanvas()->translate(-dst_rect.x(), -dst_rect.y()); | 652 surface->getCanvas()->translate(-dst_rect.x(), -dst_rect.y()); |
653 surface->getCanvas()->drawImage(srcImage.get(), src_rect.x(), src_rect.y(), | 653 surface->getCanvas()->drawImage(srcImage, src_rect.x(), src_rect.y(), &paint); |
danakj
2016/04/25 22:06:23
I found it a bit surprising that drawImage takes o
tomhudson
2016/04/27 12:06:47
As I understand it there are times when parts of t
f(malita)
2016/04/27 14:00:41
The most common case I believe is a recording canv
tomhudson
2016/04/27 14:43:12
OK, slightly better if still not completely unders
| |
654 &paint); | |
655 // Flush the drawing before source texture read lock goes out of scope. | 654 // Flush the drawing before source texture read lock goes out of scope. |
656 // Skia API does not guarantee that when the SkImage goes out of scope, | 655 // Skia API does not guarantee that when the SkImage goes out of scope, |
657 // its externally referenced resources would force the rendering to be | 656 // its externally referenced resources would force the rendering to be |
658 // flushed. | 657 // flushed. |
659 surface->getCanvas()->flush(); | 658 surface->getCanvas()->flush(); |
660 skia::RefPtr<SkImage> image = skia::AdoptRef(surface->newImageSnapshot()); | 659 sk_sp<SkImage> image = surface->makeImageSnapshot(); |
661 if (!image || !image->isTextureBacked()) { | 660 if (!image || !image->isTextureBacked()) { |
662 return skia::RefPtr<SkImage>(); | 661 return nullptr; |
663 } | 662 } |
664 | 663 |
665 CHECK(image->isTextureBacked()); | 664 CHECK(image->isTextureBacked()); |
666 return image; | 665 return image; |
667 } | 666 } |
668 | 667 |
669 bool GLRenderer::CanApplyBlendModeUsingBlendFunc(SkXfermode::Mode blend_mode) { | 668 bool GLRenderer::CanApplyBlendModeUsingBlendFunc(SkXfermode::Mode blend_mode) { |
670 return use_blend_equation_advanced_ || | 669 return use_blend_equation_advanced_ || |
671 blend_mode == SkXfermode::kScreen_Mode || | 670 blend_mode == SkXfermode::kScreen_Mode || |
672 blend_mode == SkXfermode::kSrcOver_Mode; | 671 blend_mode == SkXfermode::kSrcOver_Mode; |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
841 bounding_rect.size(), ResourceProvider::TEXTURE_HINT_DEFAULT, | 840 bounding_rect.size(), ResourceProvider::TEXTURE_HINT_DEFAULT, |
842 resource_provider_->best_texture_format()); | 841 resource_provider_->best_texture_format()); |
843 { | 842 { |
844 ResourceProvider::ScopedWriteLockGL lock(resource_provider_, | 843 ResourceProvider::ScopedWriteLockGL lock(resource_provider_, |
845 device_background_texture->id()); | 844 device_background_texture->id()); |
846 GetFramebufferTexture(lock.texture_id(), RGBA_8888, bounding_rect); | 845 GetFramebufferTexture(lock.texture_id(), RGBA_8888, bounding_rect); |
847 } | 846 } |
848 return device_background_texture; | 847 return device_background_texture; |
849 } | 848 } |
850 | 849 |
851 skia::RefPtr<SkImage> GLRenderer::ApplyBackgroundFilters( | 850 sk_sp<SkImage> GLRenderer::ApplyBackgroundFilters( |
852 DrawingFrame* frame, | 851 DrawingFrame* frame, |
853 const RenderPassDrawQuad* quad, | 852 const RenderPassDrawQuad* quad, |
854 ScopedResource* background_texture, | 853 ScopedResource* background_texture, |
855 const gfx::RectF& rect) { | 854 const gfx::RectF& rect) { |
856 DCHECK(ShouldApplyBackgroundFilters(quad)); | 855 DCHECK(ShouldApplyBackgroundFilters(quad)); |
857 skia::RefPtr<SkImageFilter> filter = RenderSurfaceFilters::BuildImageFilter( | 856 sk_sp<SkImageFilter> filter = RenderSurfaceFilters::BuildImageFilter( |
858 quad->background_filters, gfx::SizeF(background_texture->size())); | 857 quad->background_filters, gfx::SizeF(background_texture->size())); |
859 | 858 |
860 skia::RefPtr<SkImage> background_with_filters = ApplyImageFilter( | 859 sk_sp<SkImage> background_with_filters = ApplyImageFilter( |
861 ScopedUseGrContext::Create(this, frame), resource_provider_, rect, rect, | 860 ScopedUseGrContext::Create(this, frame), resource_provider_, rect, rect, |
862 quad->filters_scale, filter.get(), background_texture); | 861 quad->filters_scale, filter.get(), background_texture); |
danakj
2016/04/25 22:06:23
and we can move the filter here
tomhudson
2016/04/27 12:06:47
Done.
| |
863 return background_with_filters; | 862 return background_with_filters; |
864 } | 863 } |
865 | 864 |
866 // Map device space quad to local space. Device_transform has no 3d | 865 // Map device space quad to local space. Device_transform has no 3d |
867 // component since it was flattened, so we don't need to project. We should | 866 // component since it was flattened, so we don't need to project. We should |
868 // have already checked that the transform was uninvertible before this call. | 867 // have already checked that the transform was uninvertible before this call. |
869 gfx::QuadF MapQuadToLocalSpace(const gfx::Transform& device_transform, | 868 gfx::QuadF MapQuadToLocalSpace(const gfx::Transform& device_transform, |
870 const gfx::QuadF& device_quad) { | 869 const gfx::QuadF& device_quad) { |
871 gfx::Transform inverse_device_transform(gfx::Transform::kSkipInitialization); | 870 gfx::Transform inverse_device_transform(gfx::Transform::kSkipInitialization); |
872 DCHECK(device_transform.IsInvertible()); | 871 DCHECK(device_transform.IsInvertible()); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
918 SetupRenderPassQuadForClippingAndAntialiasing(contents_device_transform, quad, | 917 SetupRenderPassQuadForClippingAndAntialiasing(contents_device_transform, quad, |
919 aa_quad, clip_region, | 918 aa_quad, clip_region, |
920 &surface_quad, edge); | 919 &surface_quad, edge); |
921 SkXfermode::Mode blend_mode = quad->shared_quad_state->blend_mode; | 920 SkXfermode::Mode blend_mode = quad->shared_quad_state->blend_mode; |
922 bool use_shaders_for_blending = | 921 bool use_shaders_for_blending = |
923 !CanApplyBlendModeUsingBlendFunc(blend_mode) || | 922 !CanApplyBlendModeUsingBlendFunc(blend_mode) || |
924 ShouldApplyBackgroundFilters(quad) || | 923 ShouldApplyBackgroundFilters(quad) || |
925 settings_->force_blending_with_shaders; | 924 settings_->force_blending_with_shaders; |
926 | 925 |
927 std::unique_ptr<ScopedResource> background_texture; | 926 std::unique_ptr<ScopedResource> background_texture; |
928 skia::RefPtr<SkImage> background_image; | 927 sk_sp<SkImage> background_image; |
929 GLuint background_image_id = 0; | 928 GLuint background_image_id = 0; |
930 gfx::Rect background_rect; | 929 gfx::Rect background_rect; |
931 if (use_shaders_for_blending) { | 930 if (use_shaders_for_blending) { |
932 // Compute a bounding box around the pixels that will be visible through | 931 // Compute a bounding box around the pixels that will be visible through |
933 // the quad. | 932 // the quad. |
934 background_rect = GetBackdropBoundingBoxForRenderPassQuad( | 933 background_rect = GetBackdropBoundingBoxForRenderPassQuad( |
935 frame, quad, contents_device_transform, clip_region, use_aa); | 934 frame, quad, contents_device_transform, clip_region, use_aa); |
936 | 935 |
937 if (!background_rect.IsEmpty()) { | 936 if (!background_rect.IsEmpty()) { |
938 // The pixels from the filtered background should completely replace the | 937 // The pixels from the filtered background should completely replace the |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
978 bool mask_for_background = | 977 bool mask_for_background = |
979 background_texture && // Have original background texture | 978 background_texture && // Have original background texture |
980 background_image_id && // Have filtered background texture | 979 background_image_id && // Have filtered background texture |
981 quad->mask_resource_id(); // Have mask texture | 980 quad->mask_resource_id(); // Have mask texture |
982 SetBlendEnabled( | 981 SetBlendEnabled( |
983 !use_shaders_for_blending && | 982 !use_shaders_for_blending && |
984 (quad->ShouldDrawWithBlending() || !IsDefaultBlendMode(blend_mode))); | 983 (quad->ShouldDrawWithBlending() || !IsDefaultBlendMode(blend_mode))); |
985 | 984 |
986 // TODO(senorblanco): Cache this value so that we don't have to do it for both | 985 // TODO(senorblanco): Cache this value so that we don't have to do it for both |
987 // the surface and its replica. Apply filters to the contents texture. | 986 // the surface and its replica. Apply filters to the contents texture. |
988 skia::RefPtr<SkImage> filter_image; | 987 sk_sp<SkImage> filter_image; |
989 GLuint filter_image_id = 0; | 988 GLuint filter_image_id = 0; |
990 SkScalar color_matrix[20]; | 989 SkScalar color_matrix[20]; |
991 bool use_color_matrix = false; | 990 bool use_color_matrix = false; |
992 gfx::RectF rect = gfx::RectF(quad->rect); | 991 gfx::RectF rect = gfx::RectF(quad->rect); |
993 if (!quad->filters.IsEmpty()) { | 992 if (!quad->filters.IsEmpty()) { |
994 skia::RefPtr<SkImageFilter> filter = RenderSurfaceFilters::BuildImageFilter( | 993 sk_sp<SkImageFilter> filter = RenderSurfaceFilters::BuildImageFilter( |
995 quad->filters, gfx::SizeF(contents_texture->size())); | 994 quad->filters, gfx::SizeF(contents_texture->size())); |
996 if (filter) { | 995 if (filter) { |
997 SkColorFilter* colorfilter_rawptr = NULL; | 996 SkColorFilter* colorfilter_rawptr = NULL; |
998 filter->asColorFilter(&colorfilter_rawptr); | 997 filter->asColorFilter(&colorfilter_rawptr); |
999 sk_sp<SkColorFilter> cf(colorfilter_rawptr); | 998 sk_sp<SkColorFilter> cf(colorfilter_rawptr); |
1000 | 999 |
1001 if (cf && cf->asColorMatrix(color_matrix) && !filter->getInput(0)) { | 1000 if (cf && cf->asColorMatrix(color_matrix) && !filter->getInput(0)) { |
1002 // We have a single color matrix as a filter; apply it locally | 1001 // We have a single color matrix as a filter; apply it locally |
1003 // in the compositor. | 1002 // in the compositor. |
1004 use_color_matrix = true; | 1003 use_color_matrix = true; |
(...skipping 2633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3638 texture_id = pending_overlay_resources_.back()->texture_id(); | 3637 texture_id = pending_overlay_resources_.back()->texture_id(); |
3639 } | 3638 } |
3640 | 3639 |
3641 context_support_->ScheduleOverlayPlane( | 3640 context_support_->ScheduleOverlayPlane( |
3642 overlay.plane_z_order, overlay.transform, texture_id, | 3641 overlay.plane_z_order, overlay.transform, texture_id, |
3643 ToNearestRect(overlay.display_rect), overlay.uv_rect); | 3642 ToNearestRect(overlay.display_rect), overlay.uv_rect); |
3644 } | 3643 } |
3645 } | 3644 } |
3646 | 3645 |
3647 } // namespace cc | 3646 } // namespace cc |
OLD | NEW |