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 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
658 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; | 658 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; |
659 desc.fSampleCnt = 0; | 659 desc.fSampleCnt = 0; |
660 desc.fWidth = source.width(); | 660 desc.fWidth = source.width(); |
661 desc.fHeight = source.height(); | 661 desc.fHeight = source.height(); |
662 desc.fConfig = kSkia8888_GrPixelConfig; | 662 desc.fConfig = kSkia8888_GrPixelConfig; |
663 desc.fOrigin = kBottomLeft_GrSurfaceOrigin; | 663 desc.fOrigin = kBottomLeft_GrSurfaceOrigin; |
664 GrAutoScratchTexture scratch_texture( | 664 GrAutoScratchTexture scratch_texture( |
665 use_gr_context->context(), desc, GrContext::kExact_ScratchTexMatch); | 665 use_gr_context->context(), desc, GrContext::kExact_ScratchTexMatch); |
666 skia::RefPtr<GrTexture> backing_store = | 666 skia::RefPtr<GrTexture> backing_store = |
667 skia::AdoptRef(scratch_texture.detach()); | 667 skia::AdoptRef(scratch_texture.detach()); |
668 if (backing_store.get() == NULL) | 668 if (backing_store.get() == NULL) { |
| 669 TRACE_EVENT_INSTANT0("cc", |
| 670 "ApplyImageFilter scratch texture allocation failed", |
| 671 TRACE_EVENT_SCOPE_THREAD); |
669 return SkBitmap(); | 672 return SkBitmap(); |
| 673 } |
670 | 674 |
671 // Create a device and canvas using that backing store. | 675 // Create a device and canvas using that backing store. |
672 SkGpuDevice device(use_gr_context->context(), backing_store.get()); | 676 skia::RefPtr<SkGpuDevice> device = |
673 SkCanvas canvas(&device); | 677 skia::AdoptRef(SkGpuDevice::Create(backing_store->asRenderTarget())); |
| 678 DCHECK(device.get()); |
| 679 SkCanvas canvas(device.get()); |
674 | 680 |
675 // Draw the source bitmap through the filter to the canvas. | 681 // Draw the source bitmap through the filter to the canvas. |
676 SkPaint paint; | 682 SkPaint paint; |
677 paint.setImageFilter(filter); | 683 paint.setImageFilter(filter); |
678 canvas.clear(SK_ColorTRANSPARENT); | 684 canvas.clear(SK_ColorTRANSPARENT); |
679 | 685 |
680 // TODO(senorblanco): in addition to the origin translation here, the canvas | 686 // TODO(senorblanco): in addition to the origin translation here, the canvas |
681 // should also be scaled to accomodate device pixel ratio and pinch zoom. See | 687 // should also be scaled to accomodate device pixel ratio and pinch zoom. See |
682 // crbug.com/281516 and crbug.com/281518. | 688 // crbug.com/281516 and crbug.com/281518. |
683 canvas.translate(SkIntToScalar(-origin.x()), SkIntToScalar(-origin.y())); | 689 canvas.translate(SkIntToScalar(-origin.x()), SkIntToScalar(-origin.y())); |
684 canvas.drawSprite(source, 0, 0, &paint); | 690 canvas.drawSprite(source, 0, 0, &paint); |
685 | 691 |
686 // Flush the GrContext to ensure all buffered GL calls are drawn to the | 692 // Flush the GrContext to ensure all buffered GL calls are drawn to the |
687 // backing store before we access and return it, and have cc begin using the | 693 // backing store before we access and return it, and have cc begin using the |
688 // GL context again. | 694 // GL context again. |
689 use_gr_context->context()->flush(); | 695 use_gr_context->context()->flush(); |
690 | 696 |
691 return device.accessBitmap(false); | 697 return device->accessBitmap(false); |
692 } | 698 } |
693 | 699 |
694 static SkBitmap ApplyBlendModeWithBackdrop( | 700 static SkBitmap ApplyBlendModeWithBackdrop( |
695 scoped_ptr<GLRenderer::ScopedUseGrContext> use_gr_context, | 701 scoped_ptr<GLRenderer::ScopedUseGrContext> use_gr_context, |
696 ResourceProvider* resource_provider, | 702 ResourceProvider* resource_provider, |
697 SkBitmap source_bitmap_with_filters, | 703 SkBitmap source_bitmap_with_filters, |
698 ScopedResource* source_texture_resource, | 704 ScopedResource* source_texture_resource, |
699 ScopedResource* background_texture_resource, | 705 ScopedResource* background_texture_resource, |
700 SkXfermode::Mode blend_mode) { | 706 SkXfermode::Mode blend_mode) { |
701 if (!use_gr_context) | 707 if (!use_gr_context) |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
778 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; | 784 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; |
779 desc.fSampleCnt = 0; | 785 desc.fSampleCnt = 0; |
780 desc.fWidth = source.width(); | 786 desc.fWidth = source.width(); |
781 desc.fHeight = source.height(); | 787 desc.fHeight = source.height(); |
782 desc.fConfig = kSkia8888_GrPixelConfig; | 788 desc.fConfig = kSkia8888_GrPixelConfig; |
783 desc.fOrigin = kBottomLeft_GrSurfaceOrigin; | 789 desc.fOrigin = kBottomLeft_GrSurfaceOrigin; |
784 GrAutoScratchTexture scratch_texture( | 790 GrAutoScratchTexture scratch_texture( |
785 use_gr_context->context(), desc, GrContext::kExact_ScratchTexMatch); | 791 use_gr_context->context(), desc, GrContext::kExact_ScratchTexMatch); |
786 skia::RefPtr<GrTexture> backing_store = | 792 skia::RefPtr<GrTexture> backing_store = |
787 skia::AdoptRef(scratch_texture.detach()); | 793 skia::AdoptRef(scratch_texture.detach()); |
| 794 if (backing_store.get() == NULL) { |
| 795 TRACE_EVENT_INSTANT0( |
| 796 "cc", |
| 797 "ApplyBlendModeWithBackdrop scratch texture allocation failed", |
| 798 TRACE_EVENT_SCOPE_THREAD); |
| 799 return source_bitmap_with_filters; |
| 800 } |
788 | 801 |
789 // Create a device and canvas using that backing store. | 802 // Create a device and canvas using that backing store. |
790 SkGpuDevice device(use_gr_context->context(), backing_store.get()); | 803 skia::RefPtr<SkGpuDevice> device = |
791 SkCanvas canvas(&device); | 804 skia::AdoptRef(SkGpuDevice::Create(backing_store->asRenderTarget())); |
| 805 DCHECK(device.get()); |
| 806 SkCanvas canvas(device.get()); |
792 | 807 |
793 // Draw the source bitmap through the filter to the canvas. | 808 // Draw the source bitmap through the filter to the canvas. |
794 canvas.clear(SK_ColorTRANSPARENT); | 809 canvas.clear(SK_ColorTRANSPARENT); |
795 canvas.drawSprite(background, 0, 0); | 810 canvas.drawSprite(background, 0, 0); |
796 SkPaint paint; | 811 SkPaint paint; |
797 paint.setXfermodeMode(blend_mode); | 812 paint.setXfermodeMode(blend_mode); |
798 canvas.drawSprite(source, 0, 0, &paint); | 813 canvas.drawSprite(source, 0, 0, &paint); |
799 | 814 |
800 // Flush the GrContext to ensure all buffered GL calls are drawn to the | 815 // Flush the GrContext to ensure all buffered GL calls are drawn to the |
801 // backing store before we access and return it, and have cc begin using the | 816 // backing store before we access and return it, and have cc begin using the |
802 // GL context again. | 817 // GL context again. |
803 use_gr_context->context()->flush(); | 818 use_gr_context->context()->flush(); |
804 | 819 |
805 return device.accessBitmap(false); | 820 return device->accessBitmap(false); |
806 } | 821 } |
807 | 822 |
808 scoped_ptr<ScopedResource> GLRenderer::GetBackgroundWithFilters( | 823 scoped_ptr<ScopedResource> GLRenderer::GetBackgroundWithFilters( |
809 DrawingFrame* frame, | 824 DrawingFrame* frame, |
810 const RenderPassDrawQuad* quad, | 825 const RenderPassDrawQuad* quad, |
811 const gfx::Transform& contents_device_transform, | 826 const gfx::Transform& contents_device_transform, |
812 const gfx::Transform& contents_device_transform_inverse, | 827 const gfx::Transform& contents_device_transform_inverse, |
813 bool* background_changed) { | 828 bool* background_changed) { |
814 // This method draws a background filter, which applies a filter to any pixels | 829 // This method draws a background filter, which applies a filter to any pixels |
815 // behind the quad and seen through its background. The algorithm works as | 830 // behind the quad and seen through its background. The algorithm works as |
(...skipping 2360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3176 context_support_->ScheduleOverlayPlane( | 3191 context_support_->ScheduleOverlayPlane( |
3177 overlay.plane_z_order, | 3192 overlay.plane_z_order, |
3178 overlay.transform, | 3193 overlay.transform, |
3179 pending_overlay_resources_.back()->texture_id(), | 3194 pending_overlay_resources_.back()->texture_id(), |
3180 overlay.display_rect, | 3195 overlay.display_rect, |
3181 overlay.uv_rect); | 3196 overlay.uv_rect); |
3182 } | 3197 } |
3183 } | 3198 } |
3184 | 3199 |
3185 } // namespace cc | 3200 } // namespace cc |
OLD | NEW |