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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
170 return SamplerType2D; | 170 return SamplerType2D; |
171 } | 171 } |
172 } | 172 } |
173 | 173 |
174 // Smallest unit that impact anti-aliasing output. We use this to | 174 // Smallest unit that impact anti-aliasing output. We use this to |
175 // determine when anti-aliasing is unnecessary. | 175 // determine when anti-aliasing is unnecessary. |
176 const float kAntiAliasingEpsilon = 1.0f / 1024.0f; | 176 const float kAntiAliasingEpsilon = 1.0f / 1024.0f; |
177 | 177 |
178 } // anonymous namespace | 178 } // anonymous namespace |
179 | 179 |
180 class GLRenderer::ScopedUseGrContext { | |
181 public: | |
182 static scoped_ptr<ScopedUseGrContext> Create(GLRenderer* renderer, | |
183 DrawingFrame* frame) { | |
184 if (!renderer->output_surface_->context_provider()->GrContext()) | |
185 return scoped_ptr<ScopedUseGrContext>(); | |
186 return make_scoped_ptr(new ScopedUseGrContext(renderer, frame)); | |
187 } | |
188 | |
189 ~ScopedUseGrContext() { PassControlToGLRenderer(); } | |
190 | |
191 GrContext* context() const { | |
192 return renderer_->output_surface_->context_provider()->GrContext(); | |
193 } | |
194 | |
195 private: | |
196 ScopedUseGrContext(GLRenderer* renderer, DrawingFrame* frame) | |
197 : renderer_(renderer), frame_(frame) { | |
198 PassControlToSkia(); | |
199 } | |
200 | |
201 void PassControlToSkia() { context()->resetContext(); } | |
202 | |
203 void PassControlToGLRenderer() { | |
204 renderer_->RestoreGLState(); | |
205 renderer_->RestoreFramebuffer(frame_); | |
206 } | |
207 | |
208 GLRenderer* renderer_; | |
209 DrawingFrame* frame_; | |
210 | |
211 DISALLOW_COPY_AND_ASSIGN(ScopedUseGrContext); | |
212 }; | |
213 | |
180 struct GLRenderer::PendingAsyncReadPixels { | 214 struct GLRenderer::PendingAsyncReadPixels { |
181 PendingAsyncReadPixels() : buffer(0) {} | 215 PendingAsyncReadPixels() : buffer(0) {} |
182 | 216 |
183 scoped_ptr<CopyOutputRequest> copy_request; | 217 scoped_ptr<CopyOutputRequest> copy_request; |
184 base::CancelableClosure finished_read_pixels_callback; | 218 base::CancelableClosure finished_read_pixels_callback; |
185 unsigned buffer; | 219 unsigned buffer; |
186 | 220 |
187 private: | 221 private: |
188 DISALLOW_COPY_AND_ASSIGN(PendingAsyncReadPixels); | 222 DISALLOW_COPY_AND_ASSIGN(PendingAsyncReadPixels); |
189 }; | 223 }; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
293 capabilities_.max_texture_size = resource_provider_->max_texture_size(); | 327 capabilities_.max_texture_size = resource_provider_->max_texture_size(); |
294 capabilities_.best_texture_format = resource_provider_->best_texture_format(); | 328 capabilities_.best_texture_format = resource_provider_->best_texture_format(); |
295 | 329 |
296 // The updater can access textures while the GLRenderer is using them. | 330 // The updater can access textures while the GLRenderer is using them. |
297 capabilities_.allow_partial_texture_updates = true; | 331 capabilities_.allow_partial_texture_updates = true; |
298 | 332 |
299 // Check for texture fast paths. Currently we always use MO8 textures, | 333 // Check for texture fast paths. Currently we always use MO8 textures, |
300 // so we only need to avoid POT textures if we have an NPOT fast-path. | 334 // so we only need to avoid POT textures if we have an NPOT fast-path. |
301 capabilities_.avoid_pow2_textures = context_caps.gpu.fast_npot_mo8_textures; | 335 capabilities_.avoid_pow2_textures = context_caps.gpu.fast_npot_mo8_textures; |
302 | 336 |
303 capabilities_.using_offscreen_context3d = true; | 337 capabilities_.using_offscreen_context3d = false; |
304 | 338 |
305 capabilities_.using_map_image = | 339 capabilities_.using_map_image = |
306 settings_->use_map_image && context_caps.gpu.map_image; | 340 settings_->use_map_image && context_caps.gpu.map_image; |
307 | 341 |
308 capabilities_.using_discard_framebuffer = | 342 capabilities_.using_discard_framebuffer = |
309 context_caps.gpu.discard_framebuffer; | 343 context_caps.gpu.discard_framebuffer; |
310 | 344 |
311 capabilities_.allow_rasterize_on_demand = true; | 345 capabilities_.allow_rasterize_on_demand = true; |
312 | 346 |
313 use_sync_query_ = context_caps.gpu.sync_query; | 347 use_sync_query_ = context_caps.gpu.sync_query; |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
562 (SkColorGetB(color) * (1.0f / 255.0f)) * alpha, | 596 (SkColorGetB(color) * (1.0f / 255.0f)) * alpha, |
563 alpha)); | 597 alpha)); |
564 | 598 |
565 GLC(gl_, gl_->LineWidth(quad->width)); | 599 GLC(gl_, gl_->LineWidth(quad->width)); |
566 | 600 |
567 // The indices for the line are stored in the same array as the triangle | 601 // The indices for the line are stored in the same array as the triangle |
568 // indices. | 602 // indices. |
569 GLC(gl_, gl_->DrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_SHORT, 0)); | 603 GLC(gl_, gl_->DrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_SHORT, 0)); |
570 } | 604 } |
571 | 605 |
572 static SkBitmap ApplyImageFilter(GLRenderer* renderer, | 606 static SkBitmap ApplyImageFilter( |
573 ContextProvider* offscreen_contexts, | 607 scoped_ptr<GLRenderer::ScopedUseGrContext> use_gr_context, |
574 const gfx::Point& origin, | 608 ResourceProvider* resource_provider, |
575 SkImageFilter* filter, | 609 const gfx::Point& origin, |
576 ScopedResource* source_texture_resource) { | 610 SkImageFilter* filter, |
611 ScopedResource* source_texture_resource) { | |
577 if (!filter) | 612 if (!filter) |
578 return SkBitmap(); | 613 return SkBitmap(); |
579 | 614 |
580 if (!offscreen_contexts || !offscreen_contexts->GrContext()) | 615 if (!use_gr_context) |
581 return SkBitmap(); | 616 return SkBitmap(); |
582 | 617 |
583 ResourceProvider::ScopedReadLockGL lock(renderer->resource_provider(), | 618 ResourceProvider::ScopedReadLockGL lock(resource_provider, |
584 source_texture_resource->id()); | 619 source_texture_resource->id()); |
585 | 620 |
586 // Flush the compositor context to ensure that textures there are available | |
587 // in the shared context. Do this after locking/creating the compositor | |
588 // texture. | |
589 renderer->resource_provider()->Flush(); | |
590 | |
591 // Wrap the source texture in a Ganesh platform texture. | 621 // Wrap the source texture in a Ganesh platform texture. |
592 GrBackendTextureDesc backend_texture_description; | 622 GrBackendTextureDesc backend_texture_description; |
593 backend_texture_description.fWidth = source_texture_resource->size().width(); | 623 backend_texture_description.fWidth = source_texture_resource->size().width(); |
594 backend_texture_description.fHeight = | 624 backend_texture_description.fHeight = |
595 source_texture_resource->size().height(); | 625 source_texture_resource->size().height(); |
596 backend_texture_description.fConfig = kSkia8888_GrPixelConfig; | 626 backend_texture_description.fConfig = kSkia8888_GrPixelConfig; |
597 backend_texture_description.fTextureHandle = lock.texture_id(); | 627 backend_texture_description.fTextureHandle = lock.texture_id(); |
598 backend_texture_description.fOrigin = kBottomLeft_GrSurfaceOrigin; | 628 backend_texture_description.fOrigin = kBottomLeft_GrSurfaceOrigin; |
599 skia::RefPtr<GrTexture> texture = | 629 skia::RefPtr<GrTexture> texture = |
600 skia::AdoptRef(offscreen_contexts->GrContext()->wrapBackendTexture( | 630 skia::AdoptRef(use_gr_context->context()->wrapBackendTexture( |
601 backend_texture_description)); | 631 backend_texture_description)); |
602 | 632 |
603 SkImageInfo info = { | 633 SkImageInfo info = { |
604 source_texture_resource->size().width(), | 634 source_texture_resource->size().width(), |
605 source_texture_resource->size().height(), | 635 source_texture_resource->size().height(), |
606 kPMColor_SkColorType, | 636 kPMColor_SkColorType, |
607 kPremul_SkAlphaType | 637 kPremul_SkAlphaType |
608 }; | 638 }; |
609 // Place the platform texture inside an SkBitmap. | 639 // Place the platform texture inside an SkBitmap. |
610 SkBitmap source; | 640 SkBitmap source; |
611 source.setConfig(info); | 641 source.setConfig(info); |
612 skia::RefPtr<SkGrPixelRef> pixel_ref = | 642 skia::RefPtr<SkGrPixelRef> pixel_ref = |
613 skia::AdoptRef(new SkGrPixelRef(info, texture.get())); | 643 skia::AdoptRef(new SkGrPixelRef(info, texture.get())); |
614 source.setPixelRef(pixel_ref.get()); | 644 source.setPixelRef(pixel_ref.get()); |
615 | 645 |
616 // Create a scratch texture for backing store. | 646 // Create a scratch texture for backing store. |
617 GrTextureDesc desc; | 647 GrTextureDesc desc; |
618 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; | 648 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; |
619 desc.fSampleCnt = 0; | 649 desc.fSampleCnt = 0; |
620 desc.fWidth = source.width(); | 650 desc.fWidth = source.width(); |
621 desc.fHeight = source.height(); | 651 desc.fHeight = source.height(); |
622 desc.fConfig = kSkia8888_GrPixelConfig; | 652 desc.fConfig = kSkia8888_GrPixelConfig; |
623 desc.fOrigin = kBottomLeft_GrSurfaceOrigin; | 653 desc.fOrigin = kBottomLeft_GrSurfaceOrigin; |
624 GrAutoScratchTexture scratch_texture( | 654 GrAutoScratchTexture scratch_texture( |
625 offscreen_contexts->GrContext(), desc, GrContext::kExact_ScratchTexMatch); | 655 use_gr_context->context(), desc, GrContext::kExact_ScratchTexMatch); |
626 skia::RefPtr<GrTexture> backing_store = | 656 skia::RefPtr<GrTexture> backing_store = |
627 skia::AdoptRef(scratch_texture.detach()); | 657 skia::AdoptRef(scratch_texture.detach()); |
628 | 658 |
629 // Create a device and canvas using that backing store. | 659 // Create a device and canvas using that backing store. |
630 SkGpuDevice device(offscreen_contexts->GrContext(), backing_store.get()); | 660 SkGpuDevice device(use_gr_context->context(), backing_store.get()); |
631 SkCanvas canvas(&device); | 661 SkCanvas canvas(&device); |
632 | 662 |
633 // Draw the source bitmap through the filter to the canvas. | 663 // Draw the source bitmap through the filter to the canvas. |
634 SkPaint paint; | 664 SkPaint paint; |
635 paint.setImageFilter(filter); | 665 paint.setImageFilter(filter); |
636 canvas.clear(SK_ColorTRANSPARENT); | 666 canvas.clear(SK_ColorTRANSPARENT); |
637 | 667 |
638 // TODO(senorblanco): in addition to the origin translation here, the canvas | 668 // TODO(senorblanco): in addition to the origin translation here, the canvas |
639 // should also be scaled to accomodate device pixel ratio and pinch zoom. See | 669 // should also be scaled to accomodate device pixel ratio and pinch zoom. See |
640 // crbug.com/281516 and crbug.com/281518. | 670 // crbug.com/281516 and crbug.com/281518. |
641 canvas.translate(SkIntToScalar(-origin.x()), SkIntToScalar(-origin.y())); | 671 canvas.translate(SkIntToScalar(-origin.x()), SkIntToScalar(-origin.y())); |
642 canvas.drawSprite(source, 0, 0, &paint); | 672 canvas.drawSprite(source, 0, 0, &paint); |
643 | 673 |
644 // Flush skia context so that all the rendered stuff appears on the | 674 // Flush the GrContext to ensure everything is run on the GL context. |
645 // texture. | 675 use_gr_context->context()->flush(); |
646 offscreen_contexts->GrContext()->flush(); | |
647 | |
648 // Flush the GL context so rendering results from this context are | |
649 // visible in the compositor's context. | |
650 offscreen_contexts->ContextGL()->Flush(); | |
651 | 676 |
652 return device.accessBitmap(false); | 677 return device.accessBitmap(false); |
653 } | 678 } |
654 | 679 |
655 static SkBitmap ApplyBlendModeWithBackdrop( | 680 static SkBitmap ApplyBlendModeWithBackdrop( |
656 GLRenderer* renderer, | 681 scoped_ptr<GLRenderer::ScopedUseGrContext> use_gr_context, |
657 ContextProvider* offscreen_contexts, | 682 ResourceProvider* resource_provider, |
658 SkBitmap source_bitmap_with_filters, | 683 SkBitmap source_bitmap_with_filters, |
659 ScopedResource* source_texture_resource, | 684 ScopedResource* source_texture_resource, |
660 ScopedResource* background_texture_resource, | 685 ScopedResource* background_texture_resource, |
661 SkXfermode::Mode blend_mode) { | 686 SkXfermode::Mode blend_mode) { |
662 if (!offscreen_contexts || !offscreen_contexts->GrContext()) | 687 if (!use_gr_context) |
663 return source_bitmap_with_filters; | 688 return source_bitmap_with_filters; |
664 | 689 |
665 DCHECK(background_texture_resource); | 690 DCHECK(background_texture_resource); |
666 DCHECK(source_texture_resource); | 691 DCHECK(source_texture_resource); |
667 | 692 |
668 gfx::Size source_size = source_texture_resource->size(); | 693 gfx::Size source_size = source_texture_resource->size(); |
669 gfx::Size background_size = background_texture_resource->size(); | 694 gfx::Size background_size = background_texture_resource->size(); |
670 | 695 |
671 DCHECK_LE(background_size.width(), source_size.width()); | 696 DCHECK_LE(background_size.width(), source_size.width()); |
672 DCHECK_LE(background_size.height(), source_size.height()); | 697 DCHECK_LE(background_size.height(), source_size.height()); |
673 | 698 |
674 int source_texture_with_filters_id; | 699 int source_texture_with_filters_id; |
675 scoped_ptr<ResourceProvider::ScopedReadLockGL> lock; | 700 scoped_ptr<ResourceProvider::ScopedReadLockGL> lock; |
676 if (source_bitmap_with_filters.getTexture()) { | 701 if (source_bitmap_with_filters.getTexture()) { |
677 DCHECK_EQ(source_size.width(), source_bitmap_with_filters.width()); | 702 DCHECK_EQ(source_size.width(), source_bitmap_with_filters.width()); |
678 DCHECK_EQ(source_size.height(), source_bitmap_with_filters.height()); | 703 DCHECK_EQ(source_size.height(), source_bitmap_with_filters.height()); |
679 GrTexture* texture = | 704 GrTexture* texture = |
680 reinterpret_cast<GrTexture*>(source_bitmap_with_filters.getTexture()); | 705 reinterpret_cast<GrTexture*>(source_bitmap_with_filters.getTexture()); |
681 source_texture_with_filters_id = texture->getTextureHandle(); | 706 source_texture_with_filters_id = texture->getTextureHandle(); |
682 } else { | 707 } else { |
683 lock.reset(new ResourceProvider::ScopedReadLockGL( | 708 lock.reset(new ResourceProvider::ScopedReadLockGL( |
684 renderer->resource_provider(), source_texture_resource->id())); | 709 resource_provider, source_texture_resource->id())); |
685 source_texture_with_filters_id = lock->texture_id(); | 710 source_texture_with_filters_id = lock->texture_id(); |
686 } | 711 } |
687 | 712 |
688 ResourceProvider::ScopedReadLockGL lock_background( | 713 ResourceProvider::ScopedReadLockGL lock_background( |
689 renderer->resource_provider(), background_texture_resource->id()); | 714 resource_provider, background_texture_resource->id()); |
690 | |
691 // Flush the compositor context to ensure that textures there are available | |
692 // in the shared context. Do this after locking/creating the compositor | |
693 // texture. | |
694 renderer->resource_provider()->Flush(); | |
695 | 715 |
696 // Wrap the source texture in a Ganesh platform texture. | 716 // Wrap the source texture in a Ganesh platform texture. |
697 GrBackendTextureDesc backend_texture_description; | 717 GrBackendTextureDesc backend_texture_description; |
698 backend_texture_description.fConfig = kSkia8888_GrPixelConfig; | 718 backend_texture_description.fConfig = kSkia8888_GrPixelConfig; |
699 backend_texture_description.fOrigin = kBottomLeft_GrSurfaceOrigin; | 719 backend_texture_description.fOrigin = kBottomLeft_GrSurfaceOrigin; |
700 | 720 |
701 backend_texture_description.fWidth = source_size.width(); | 721 backend_texture_description.fWidth = source_size.width(); |
702 backend_texture_description.fHeight = source_size.height(); | 722 backend_texture_description.fHeight = source_size.height(); |
703 backend_texture_description.fTextureHandle = source_texture_with_filters_id; | 723 backend_texture_description.fTextureHandle = source_texture_with_filters_id; |
704 skia::RefPtr<GrTexture> source_texture = | 724 skia::RefPtr<GrTexture> source_texture = |
705 skia::AdoptRef(offscreen_contexts->GrContext()->wrapBackendTexture( | 725 skia::AdoptRef(use_gr_context->context()->wrapBackendTexture( |
706 backend_texture_description)); | 726 backend_texture_description)); |
707 | 727 |
708 backend_texture_description.fWidth = background_size.width(); | 728 backend_texture_description.fWidth = background_size.width(); |
709 backend_texture_description.fHeight = background_size.height(); | 729 backend_texture_description.fHeight = background_size.height(); |
710 backend_texture_description.fTextureHandle = lock_background.texture_id(); | 730 backend_texture_description.fTextureHandle = lock_background.texture_id(); |
711 skia::RefPtr<GrTexture> background_texture = | 731 skia::RefPtr<GrTexture> background_texture = |
712 skia::AdoptRef(offscreen_contexts->GrContext()->wrapBackendTexture( | 732 skia::AdoptRef(use_gr_context->context()->wrapBackendTexture( |
713 backend_texture_description)); | 733 backend_texture_description)); |
714 | 734 |
715 SkImageInfo source_info = { | 735 SkImageInfo source_info = { |
716 source_size.width(), | 736 source_size.width(), |
717 source_size.height(), | 737 source_size.height(), |
718 kPMColor_SkColorType, | 738 kPMColor_SkColorType, |
719 kPremul_SkAlphaType | 739 kPremul_SkAlphaType |
720 }; | 740 }; |
721 // Place the platform texture inside an SkBitmap. | 741 // Place the platform texture inside an SkBitmap. |
722 SkBitmap source; | 742 SkBitmap source; |
(...skipping 18 matching lines...) Expand all Loading... | |
741 | 761 |
742 // Create a scratch texture for backing store. | 762 // Create a scratch texture for backing store. |
743 GrTextureDesc desc; | 763 GrTextureDesc desc; |
744 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; | 764 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; |
745 desc.fSampleCnt = 0; | 765 desc.fSampleCnt = 0; |
746 desc.fWidth = source.width(); | 766 desc.fWidth = source.width(); |
747 desc.fHeight = source.height(); | 767 desc.fHeight = source.height(); |
748 desc.fConfig = kSkia8888_GrPixelConfig; | 768 desc.fConfig = kSkia8888_GrPixelConfig; |
749 desc.fOrigin = kBottomLeft_GrSurfaceOrigin; | 769 desc.fOrigin = kBottomLeft_GrSurfaceOrigin; |
750 GrAutoScratchTexture scratch_texture( | 770 GrAutoScratchTexture scratch_texture( |
751 offscreen_contexts->GrContext(), desc, GrContext::kExact_ScratchTexMatch); | 771 use_gr_context->context(), desc, GrContext::kExact_ScratchTexMatch); |
752 skia::RefPtr<GrTexture> backing_store = | 772 skia::RefPtr<GrTexture> backing_store = |
753 skia::AdoptRef(scratch_texture.detach()); | 773 skia::AdoptRef(scratch_texture.detach()); |
754 | 774 |
755 // Create a device and canvas using that backing store. | 775 // Create a device and canvas using that backing store. |
756 SkGpuDevice device(offscreen_contexts->GrContext(), backing_store.get()); | 776 SkGpuDevice device(use_gr_context->context(), backing_store.get()); |
757 SkCanvas canvas(&device); | 777 SkCanvas canvas(&device); |
758 | 778 |
759 // Draw the source bitmap through the filter to the canvas. | 779 // Draw the source bitmap through the filter to the canvas. |
760 canvas.clear(SK_ColorTRANSPARENT); | 780 canvas.clear(SK_ColorTRANSPARENT); |
761 canvas.drawSprite(background, 0, 0); | 781 canvas.drawSprite(background, 0, 0); |
762 SkPaint paint; | 782 SkPaint paint; |
763 paint.setXfermodeMode(blend_mode); | 783 paint.setXfermodeMode(blend_mode); |
764 canvas.drawSprite(source, 0, 0, &paint); | 784 canvas.drawSprite(source, 0, 0, &paint); |
765 | 785 |
766 // Flush skia context so that all the rendered stuff appears on the | 786 // Flush the GrContext to ensure everything is run on the GL context. |
Stephen White
2014/04/23 21:57:21
Nit: I think the old comment is a bit clearer; eit
danakj
2014/04/23 22:00:14
k, added to the comment.
| |
767 // texture. | 787 use_gr_context->context()->flush(); |
768 offscreen_contexts->GrContext()->flush(); | |
769 | |
770 // Flush the GL context so rendering results from this context are | |
771 // visible in the compositor's context. | |
772 offscreen_contexts->ContextGL()->Flush(); | |
773 | 788 |
774 return device.accessBitmap(false); | 789 return device.accessBitmap(false); |
775 } | 790 } |
776 | 791 |
777 scoped_ptr<ScopedResource> GLRenderer::GetBackgroundWithFilters( | 792 scoped_ptr<ScopedResource> GLRenderer::GetBackgroundWithFilters( |
778 DrawingFrame* frame, | 793 DrawingFrame* frame, |
779 const RenderPassDrawQuad* quad, | 794 const RenderPassDrawQuad* quad, |
780 const gfx::Transform& contents_device_transform, | 795 const gfx::Transform& contents_device_transform, |
781 const gfx::Transform& contents_device_transform_inverse, | 796 const gfx::Transform& contents_device_transform_inverse, |
782 bool* background_changed) { | 797 bool* background_changed) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
840 GetFramebufferTexture( | 855 GetFramebufferTexture( |
841 lock.texture_id(), device_background_texture->format(), window_rect); | 856 lock.texture_id(), device_background_texture->format(), window_rect); |
842 } | 857 } |
843 | 858 |
844 skia::RefPtr<SkImageFilter> filter = RenderSurfaceFilters::BuildImageFilter( | 859 skia::RefPtr<SkImageFilter> filter = RenderSurfaceFilters::BuildImageFilter( |
845 quad->background_filters, device_background_texture->size()); | 860 quad->background_filters, device_background_texture->size()); |
846 | 861 |
847 SkBitmap filtered_device_background; | 862 SkBitmap filtered_device_background; |
848 if (apply_background_filters) { | 863 if (apply_background_filters) { |
849 filtered_device_background = | 864 filtered_device_background = |
850 ApplyImageFilter(this, | 865 ApplyImageFilter(ScopedUseGrContext::Create(this, frame), |
851 frame->offscreen_context_provider, | 866 resource_provider_, |
852 quad->rect.origin(), | 867 quad->rect.origin(), |
853 filter.get(), | 868 filter.get(), |
854 device_background_texture.get()); | 869 device_background_texture.get()); |
855 } | 870 } |
856 *background_changed = (filtered_device_background.getTexture() != NULL); | 871 *background_changed = (filtered_device_background.getTexture() != NULL); |
857 | 872 |
858 int filtered_device_background_texture_id = 0; | 873 int filtered_device_background_texture_id = 0; |
859 scoped_ptr<ResourceProvider::ScopedReadLockGL> lock; | 874 scoped_ptr<ResourceProvider::ScopedReadLockGL> lock; |
860 if (filtered_device_background.getTexture()) { | 875 if (filtered_device_background.getTexture()) { |
861 GrTexture* texture = | 876 GrTexture* texture = |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
952 | 967 |
953 if (disable_blending) | 968 if (disable_blending) |
954 SetBlendEnabled(true); | 969 SetBlendEnabled(true); |
955 } | 970 } |
956 | 971 |
957 // TODO(senorblanco): Cache this value so that we don't have to do it for both | 972 // TODO(senorblanco): Cache this value so that we don't have to do it for both |
958 // the surface and its replica. Apply filters to the contents texture. | 973 // the surface and its replica. Apply filters to the contents texture. |
959 SkBitmap filter_bitmap; | 974 SkBitmap filter_bitmap; |
960 SkScalar color_matrix[20]; | 975 SkScalar color_matrix[20]; |
961 bool use_color_matrix = false; | 976 bool use_color_matrix = false; |
962 // TODO(ajuma): Always use RenderSurfaceFilters::BuildImageFilter, not just | |
963 // when we have a reference filter. | |
964 if (!quad->filters.IsEmpty()) { | 977 if (!quad->filters.IsEmpty()) { |
965 skia::RefPtr<SkImageFilter> filter = RenderSurfaceFilters::BuildImageFilter( | 978 skia::RefPtr<SkImageFilter> filter = RenderSurfaceFilters::BuildImageFilter( |
966 quad->filters, contents_texture->size()); | 979 quad->filters, contents_texture->size()); |
967 if (filter) { | 980 if (filter) { |
968 skia::RefPtr<SkColorFilter> cf; | 981 skia::RefPtr<SkColorFilter> cf; |
969 | 982 |
970 { | 983 { |
971 SkColorFilter* colorfilter_rawptr = NULL; | 984 SkColorFilter* colorfilter_rawptr = NULL; |
972 filter->asColorFilter(&colorfilter_rawptr); | 985 filter->asColorFilter(&colorfilter_rawptr); |
973 cf = skia::AdoptRef(colorfilter_rawptr); | 986 cf = skia::AdoptRef(colorfilter_rawptr); |
974 } | 987 } |
975 | 988 |
976 if (cf && cf->asColorMatrix(color_matrix) && !filter->getInput(0)) { | 989 if (cf && cf->asColorMatrix(color_matrix) && !filter->getInput(0)) { |
977 // We have a single color matrix as a filter; apply it locally | 990 // We have a single color matrix as a filter; apply it locally |
978 // in the compositor. | 991 // in the compositor. |
979 use_color_matrix = true; | 992 use_color_matrix = true; |
980 } else { | 993 } else { |
981 filter_bitmap = ApplyImageFilter(this, | 994 filter_bitmap = |
982 frame->offscreen_context_provider, | 995 ApplyImageFilter(ScopedUseGrContext::Create(this, frame), |
983 quad->rect.origin(), | 996 resource_provider_, |
984 filter.get(), | 997 quad->rect.origin(), |
985 contents_texture); | 998 filter.get(), |
999 contents_texture); | |
986 } | 1000 } |
987 } | 1001 } |
988 } | 1002 } |
989 | 1003 |
990 if (quad->shared_quad_state->blend_mode != SkXfermode::kSrcOver_Mode && | 1004 if (quad->shared_quad_state->blend_mode != SkXfermode::kSrcOver_Mode && |
991 background_texture) { | 1005 background_texture) { |
992 filter_bitmap = | 1006 filter_bitmap = |
993 ApplyBlendModeWithBackdrop(this, | 1007 ApplyBlendModeWithBackdrop(ScopedUseGrContext::Create(this, frame), |
994 frame->offscreen_context_provider, | 1008 resource_provider_, |
995 filter_bitmap, | 1009 filter_bitmap, |
996 contents_texture, | 1010 contents_texture, |
997 background_texture.get(), | 1011 background_texture.get(), |
998 quad->shared_quad_state->blend_mode); | 1012 quad->shared_quad_state->blend_mode); |
999 } | 1013 } |
1000 | 1014 |
1001 // Draw the background texture if it has some filters applied. | 1015 // Draw the background texture if it has some filters applied. |
1002 if (background_texture && background_changed) { | 1016 if (background_texture && background_changed) { |
1003 DCHECK(background_texture->size() == quad->rect.size()); | 1017 DCHECK(background_texture->size() == quad->rect.size()); |
1004 ResourceProvider::ScopedReadLockGL lock(resource_provider_, | 1018 ResourceProvider::ScopedReadLockGL lock(resource_provider_, |
(...skipping 2099 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3104 if (offscreen_framebuffer_id_) | 3118 if (offscreen_framebuffer_id_) |
3105 GLC(gl_, gl_->DeleteFramebuffers(1, &offscreen_framebuffer_id_)); | 3119 GLC(gl_, gl_->DeleteFramebuffers(1, &offscreen_framebuffer_id_)); |
3106 | 3120 |
3107 if (on_demand_tile_raster_resource_id_) | 3121 if (on_demand_tile_raster_resource_id_) |
3108 resource_provider_->DeleteResource(on_demand_tile_raster_resource_id_); | 3122 resource_provider_->DeleteResource(on_demand_tile_raster_resource_id_); |
3109 | 3123 |
3110 ReleaseRenderPassTextures(); | 3124 ReleaseRenderPassTextures(); |
3111 } | 3125 } |
3112 | 3126 |
3113 void GLRenderer::ReinitializeGLState() { | 3127 void GLRenderer::ReinitializeGLState() { |
3114 // Bind the common vertex attributes used for drawing all the layers. | 3128 is_scissor_enabled_ = false; |
3129 scissor_rect_needs_reset_ = true; | |
3130 stencil_shadow_ = false; | |
3131 blend_shadow_ = true; | |
3132 program_shadow_ = 0; | |
3133 | |
3134 RestoreGLState(); | |
3135 } | |
3136 | |
3137 void GLRenderer::RestoreGLState() { | |
3138 // This restores the current GLRenderer state to the GL context. | |
3139 | |
3115 shared_geometry_->PrepareForDraw(); | 3140 shared_geometry_->PrepareForDraw(); |
3116 | 3141 |
3117 GLC(gl_, gl_->Disable(GL_DEPTH_TEST)); | 3142 GLC(gl_, gl_->Disable(GL_DEPTH_TEST)); |
3118 GLC(gl_, gl_->Disable(GL_CULL_FACE)); | 3143 GLC(gl_, gl_->Disable(GL_CULL_FACE)); |
3119 GLC(gl_, gl_->ColorMask(true, true, true, true)); | 3144 GLC(gl_, gl_->ColorMask(true, true, true, true)); |
3120 GLC(gl_, gl_->Disable(GL_STENCIL_TEST)); | |
3121 stencil_shadow_ = false; | |
3122 GLC(gl_, gl_->Enable(GL_BLEND)); | |
3123 blend_shadow_ = true; | |
3124 GLC(gl_, gl_->BlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); | 3145 GLC(gl_, gl_->BlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); |
3125 GLC(gl_, gl_->ActiveTexture(GL_TEXTURE0)); | 3146 GLC(gl_, gl_->ActiveTexture(GL_TEXTURE0)); |
3126 program_shadow_ = 0; | |
3127 | 3147 |
3128 // Make sure scissoring starts as disabled. | 3148 if (program_shadow_) |
3129 is_scissor_enabled_ = false; | 3149 gl_->UseProgram(program_shadow_); |
3130 GLC(gl_, gl_->Disable(GL_SCISSOR_TEST)); | 3150 |
3131 scissor_rect_needs_reset_ = true; | 3151 if (stencil_shadow_) |
3152 GLC(gl_, gl_->Enable(GL_STENCIL_TEST)); | |
3153 else | |
3154 GLC(gl_, gl_->Disable(GL_STENCIL_TEST)); | |
3155 | |
3156 if (blend_shadow_) | |
3157 GLC(gl_, gl_->Enable(GL_BLEND)); | |
3158 else | |
3159 GLC(gl_, gl_->Disable(GL_BLEND)); | |
3160 | |
3161 if (is_scissor_enabled_) { | |
3162 GLC(gl_, gl_->Enable(GL_SCISSOR_TEST)); | |
3163 GLC(gl_, | |
3164 gl_->Scissor(scissor_rect_.x(), | |
3165 scissor_rect_.y(), | |
3166 scissor_rect_.width(), | |
3167 scissor_rect_.height())); | |
3168 } else { | |
3169 GLC(gl_, gl_->Disable(GL_SCISSOR_TEST)); | |
3170 } | |
3171 } | |
3172 | |
3173 void GLRenderer::RestoreFramebuffer(DrawingFrame* frame) { | |
3174 UseRenderPass(frame, frame->current_render_pass); | |
3132 } | 3175 } |
3133 | 3176 |
3134 bool GLRenderer::IsContextLost() { | 3177 bool GLRenderer::IsContextLost() { |
3135 return output_surface_->context_provider()->IsContextLost(); | 3178 return output_surface_->context_provider()->IsContextLost(); |
3136 } | 3179 } |
3137 | 3180 |
3138 void GLRenderer::ScheduleOverlays(DrawingFrame* frame) { | 3181 void GLRenderer::ScheduleOverlays(DrawingFrame* frame) { |
3139 if (!frame->overlay_list.size()) | 3182 if (!frame->overlay_list.size()) |
3140 return; | 3183 return; |
3141 | 3184 |
3142 ResourceProvider::ResourceIdArray resources; | 3185 ResourceProvider::ResourceIdArray resources; |
3143 OverlayCandidateList& overlays = frame->overlay_list; | 3186 OverlayCandidateList& overlays = frame->overlay_list; |
3144 OverlayCandidateList::iterator it; | 3187 OverlayCandidateList::iterator it; |
3145 for (it = overlays.begin(); it != overlays.end(); ++it) { | 3188 for (it = overlays.begin(); it != overlays.end(); ++it) { |
3146 const OverlayCandidate& overlay = *it; | 3189 const OverlayCandidate& overlay = *it; |
3147 // Skip primary plane. | 3190 // Skip primary plane. |
3148 if (overlay.plane_z_order == 0) | 3191 if (overlay.plane_z_order == 0) |
3149 continue; | 3192 continue; |
3150 | 3193 |
3151 pending_overlay_resources_.push_back( | 3194 pending_overlay_resources_.push_back( |
3152 make_scoped_ptr(new ResourceProvider::ScopedReadLockGL( | 3195 make_scoped_ptr(new ResourceProvider::ScopedReadLockGL( |
3153 resource_provider(), overlay.resource_id))); | 3196 resource_provider_, overlay.resource_id))); |
3154 | 3197 |
3155 context_support_->ScheduleOverlayPlane( | 3198 context_support_->ScheduleOverlayPlane( |
3156 overlay.plane_z_order, | 3199 overlay.plane_z_order, |
3157 overlay.transform, | 3200 overlay.transform, |
3158 pending_overlay_resources_.back()->texture_id(), | 3201 pending_overlay_resources_.back()->texture_id(), |
3159 overlay.display_rect, | 3202 overlay.display_rect, |
3160 overlay.uv_rect); | 3203 overlay.uv_rect); |
3161 } | 3204 } |
3162 } | 3205 } |
3163 | 3206 |
3164 } // namespace cc | 3207 } // namespace cc |
OLD | NEW |