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

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

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

Powered by Google App Engine
This is Rietveld 408576698