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 sk_sp<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> src_image = SkImage::MakeFromTexture( |
628 use_gr_context->context(), backend_texture_description)); | 628 use_gr_context->context(), backend_texture_description); |
629 if (!srcImage.get()) { | 629 if (!src_image) { |
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)); |
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(src_image, src_rect.x(), src_rect.y(), |
654 &paint); | 654 &paint); |
655 // Flush the drawing before source texture read lock goes out of scope. | 655 // 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, | 656 // Skia API does not guarantee that when the SkImage goes out of scope, |
657 // its externally referenced resources would force the rendering to be | 657 // its externally referenced resources would force the rendering to be |
658 // flushed. | 658 // flushed. |
659 surface->getCanvas()->flush(); | 659 surface->getCanvas()->flush(); |
660 skia::RefPtr<SkImage> image = skia::AdoptRef(surface->newImageSnapshot()); | 660 sk_sp<SkImage> image = surface->makeImageSnapshot(); |
661 if (!image || !image->isTextureBacked()) { | 661 if (!image || !image->isTextureBacked()) { |
662 return skia::RefPtr<SkImage>(); | 662 return nullptr; |
663 } | 663 } |
664 | 664 |
665 CHECK(image->isTextureBacked()); | 665 CHECK(image->isTextureBacked()); |
666 return image; | 666 return image; |
667 } | 667 } |
668 | 668 |
669 bool GLRenderer::CanApplyBlendModeUsingBlendFunc(SkXfermode::Mode blend_mode) { | 669 bool GLRenderer::CanApplyBlendModeUsingBlendFunc(SkXfermode::Mode blend_mode) { |
670 return use_blend_equation_advanced_ || | 670 return use_blend_equation_advanced_ || |
671 blend_mode == SkXfermode::kScreen_Mode || | 671 blend_mode == SkXfermode::kScreen_Mode || |
672 blend_mode == SkXfermode::kSrcOver_Mode; | 672 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, | 841 bounding_rect.size(), ResourceProvider::TEXTURE_HINT_DEFAULT, |
842 resource_provider_->best_texture_format()); | 842 resource_provider_->best_texture_format()); |
843 { | 843 { |
844 ResourceProvider::ScopedWriteLockGL lock(resource_provider_, | 844 ResourceProvider::ScopedWriteLockGL lock(resource_provider_, |
845 device_background_texture->id()); | 845 device_background_texture->id()); |
846 GetFramebufferTexture(lock.texture_id(), RGBA_8888, bounding_rect); | 846 GetFramebufferTexture(lock.texture_id(), RGBA_8888, bounding_rect); |
847 } | 847 } |
848 return device_background_texture; | 848 return device_background_texture; |
849 } | 849 } |
850 | 850 |
851 skia::RefPtr<SkImage> GLRenderer::ApplyBackgroundFilters( | 851 sk_sp<SkImage> GLRenderer::ApplyBackgroundFilters( |
852 DrawingFrame* frame, | 852 DrawingFrame* frame, |
853 const RenderPassDrawQuad* quad, | 853 const RenderPassDrawQuad* quad, |
854 ScopedResource* background_texture, | 854 ScopedResource* background_texture, |
855 const gfx::RectF& rect) { | 855 const gfx::RectF& rect) { |
856 DCHECK(ShouldApplyBackgroundFilters(quad)); | 856 DCHECK(ShouldApplyBackgroundFilters(quad)); |
857 skia::RefPtr<SkImageFilter> filter = RenderSurfaceFilters::BuildImageFilter( | 857 sk_sp<SkImageFilter> filter = RenderSurfaceFilters::BuildImageFilter( |
858 quad->background_filters, gfx::SizeF(background_texture->size())); | 858 quad->background_filters, gfx::SizeF(background_texture->size())); |
859 | 859 |
860 skia::RefPtr<SkImage> background_with_filters = ApplyImageFilter( | 860 sk_sp<SkImage> background_with_filters = ApplyImageFilter( |
861 ScopedUseGrContext::Create(this, frame), resource_provider_, rect, rect, | 861 ScopedUseGrContext::Create(this, frame), resource_provider_, rect, rect, |
862 quad->filters_scale, filter.get(), background_texture); | 862 quad->filters_scale, std::move(filter), background_texture); |
863 return background_with_filters; | 863 return background_with_filters; |
864 } | 864 } |
865 | 865 |
866 // Map device space quad to local space. Device_transform has no 3d | 866 // 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 | 867 // 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. | 868 // have already checked that the transform was uninvertible before this call. |
869 gfx::QuadF MapQuadToLocalSpace(const gfx::Transform& device_transform, | 869 gfx::QuadF MapQuadToLocalSpace(const gfx::Transform& device_transform, |
870 const gfx::QuadF& device_quad) { | 870 const gfx::QuadF& device_quad) { |
871 gfx::Transform inverse_device_transform(gfx::Transform::kSkipInitialization); | 871 gfx::Transform inverse_device_transform(gfx::Transform::kSkipInitialization); |
872 DCHECK(device_transform.IsInvertible()); | 872 DCHECK(device_transform.IsInvertible()); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
918 SetupRenderPassQuadForClippingAndAntialiasing(contents_device_transform, quad, | 918 SetupRenderPassQuadForClippingAndAntialiasing(contents_device_transform, quad, |
919 aa_quad, clip_region, | 919 aa_quad, clip_region, |
920 &surface_quad, edge); | 920 &surface_quad, edge); |
921 SkXfermode::Mode blend_mode = quad->shared_quad_state->blend_mode; | 921 SkXfermode::Mode blend_mode = quad->shared_quad_state->blend_mode; |
922 bool use_shaders_for_blending = | 922 bool use_shaders_for_blending = |
923 !CanApplyBlendModeUsingBlendFunc(blend_mode) || | 923 !CanApplyBlendModeUsingBlendFunc(blend_mode) || |
924 ShouldApplyBackgroundFilters(quad) || | 924 ShouldApplyBackgroundFilters(quad) || |
925 settings_->force_blending_with_shaders; | 925 settings_->force_blending_with_shaders; |
926 | 926 |
927 std::unique_ptr<ScopedResource> background_texture; | 927 std::unique_ptr<ScopedResource> background_texture; |
928 skia::RefPtr<SkImage> background_image; | 928 sk_sp<SkImage> background_image; |
929 GLuint background_image_id = 0; | 929 GLuint background_image_id = 0; |
930 gfx::Rect background_rect; | 930 gfx::Rect background_rect; |
931 if (use_shaders_for_blending) { | 931 if (use_shaders_for_blending) { |
932 // Compute a bounding box around the pixels that will be visible through | 932 // Compute a bounding box around the pixels that will be visible through |
933 // the quad. | 933 // the quad. |
934 background_rect = GetBackdropBoundingBoxForRenderPassQuad( | 934 background_rect = GetBackdropBoundingBoxForRenderPassQuad( |
935 frame, quad, contents_device_transform, clip_region, use_aa); | 935 frame, quad, contents_device_transform, clip_region, use_aa); |
936 | 936 |
937 if (!background_rect.IsEmpty()) { | 937 if (!background_rect.IsEmpty()) { |
938 // The pixels from the filtered background should completely replace the | 938 // 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 = | 978 bool mask_for_background = |
979 background_texture && // Have original background texture | 979 background_texture && // Have original background texture |
980 background_image_id && // Have filtered background texture | 980 background_image_id && // Have filtered background texture |
981 quad->mask_resource_id(); // Have mask texture | 981 quad->mask_resource_id(); // Have mask texture |
982 SetBlendEnabled( | 982 SetBlendEnabled( |
983 !use_shaders_for_blending && | 983 !use_shaders_for_blending && |
984 (quad->ShouldDrawWithBlending() || !IsDefaultBlendMode(blend_mode))); | 984 (quad->ShouldDrawWithBlending() || !IsDefaultBlendMode(blend_mode))); |
985 | 985 |
986 // TODO(senorblanco): Cache this value so that we don't have to do it for both | 986 // 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. | 987 // the surface and its replica. Apply filters to the contents texture. |
988 skia::RefPtr<SkImage> filter_image; | 988 sk_sp<SkImage> filter_image; |
989 GLuint filter_image_id = 0; | 989 GLuint filter_image_id = 0; |
990 SkScalar color_matrix[20]; | 990 SkScalar color_matrix[20]; |
991 bool use_color_matrix = false; | 991 bool use_color_matrix = false; |
992 gfx::RectF rect = gfx::RectF(quad->rect); | 992 gfx::RectF rect = gfx::RectF(quad->rect); |
993 if (!quad->filters.IsEmpty()) { | 993 if (!quad->filters.IsEmpty()) { |
994 skia::RefPtr<SkImageFilter> filter = RenderSurfaceFilters::BuildImageFilter( | 994 sk_sp<SkImageFilter> filter = RenderSurfaceFilters::BuildImageFilter( |
995 quad->filters, gfx::SizeF(contents_texture->size())); | 995 quad->filters, gfx::SizeF(contents_texture->size())); |
996 if (filter) { | 996 if (filter) { |
997 SkColorFilter* colorfilter_rawptr = NULL; | 997 SkColorFilter* colorfilter_rawptr = NULL; |
998 filter->asColorFilter(&colorfilter_rawptr); | 998 filter->asColorFilter(&colorfilter_rawptr); |
999 sk_sp<SkColorFilter> cf(colorfilter_rawptr); | 999 sk_sp<SkColorFilter> cf(colorfilter_rawptr); |
1000 | 1000 |
1001 if (cf && cf->asColorMatrix(color_matrix) && !filter->getInput(0)) { | 1001 if (cf && cf->asColorMatrix(color_matrix) && !filter->getInput(0)) { |
1002 // We have a single color matrix as a filter; apply it locally | 1002 // We have a single color matrix as a filter; apply it locally |
1003 // in the compositor. | 1003 // in the compositor. |
1004 use_color_matrix = true; | 1004 use_color_matrix = true; |
(...skipping 12 matching lines...) Expand all Loading... |
1017 gfx::Transform transform = | 1017 gfx::Transform transform = |
1018 quad->shared_quad_state->quad_to_target_transform; | 1018 quad->shared_quad_state->quad_to_target_transform; |
1019 gfx::QuadF clip_quad = gfx::QuadF(gfx::RectF(clip_rect)); | 1019 gfx::QuadF clip_quad = gfx::QuadF(gfx::RectF(clip_rect)); |
1020 gfx::QuadF local_clip = MapQuadToLocalSpace(transform, clip_quad); | 1020 gfx::QuadF local_clip = MapQuadToLocalSpace(transform, clip_quad); |
1021 dst_rect.Intersect(local_clip.BoundingBox()); | 1021 dst_rect.Intersect(local_clip.BoundingBox()); |
1022 // If we've been fully clipped out (by crop rect or clipping), there's | 1022 // If we've been fully clipped out (by crop rect or clipping), there's |
1023 // nothing to draw. | 1023 // nothing to draw. |
1024 if (dst_rect.IsEmpty()) { | 1024 if (dst_rect.IsEmpty()) { |
1025 return; | 1025 return; |
1026 } | 1026 } |
1027 filter_image = ApplyImageFilter(ScopedUseGrContext::Create(this, frame), | 1027 filter_image = ApplyImageFilter( |
1028 resource_provider_, rect, dst_rect, | 1028 ScopedUseGrContext::Create(this, frame), resource_provider_, rect, |
1029 scale, filter.get(), contents_texture); | 1029 dst_rect, scale, std::move(filter), contents_texture); |
1030 if (filter_image) { | 1030 if (filter_image) { |
1031 filter_image_id = skia::GrBackendObjectToGrGLTextureInfo( | 1031 filter_image_id = skia::GrBackendObjectToGrGLTextureInfo( |
1032 filter_image->getTextureHandle(true)) | 1032 filter_image->getTextureHandle(true)) |
1033 ->fID; | 1033 ->fID; |
1034 DCHECK(filter_image_id); | 1034 DCHECK(filter_image_id); |
1035 rect = dst_rect; | 1035 rect = dst_rect; |
1036 } | 1036 } |
1037 } | 1037 } |
1038 } | 1038 } |
1039 } | 1039 } |
(...skipping 2598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3638 texture_id = pending_overlay_resources_.back()->texture_id(); | 3638 texture_id = pending_overlay_resources_.back()->texture_id(); |
3639 } | 3639 } |
3640 | 3640 |
3641 context_support_->ScheduleOverlayPlane( | 3641 context_support_->ScheduleOverlayPlane( |
3642 overlay.plane_z_order, overlay.transform, texture_id, | 3642 overlay.plane_z_order, overlay.transform, texture_id, |
3643 ToNearestRect(overlay.display_rect), overlay.uv_rect); | 3643 ToNearestRect(overlay.display_rect), overlay.uv_rect); |
3644 } | 3644 } |
3645 } | 3645 } |
3646 | 3646 |
3647 } // namespace cc | 3647 } // namespace cc |
OLD | NEW |