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

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

Issue 250083002: cc: Use the onscreen context to perform composited ganesh filters. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: onscreenfilters: nit Created 6 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 | Annotate | Revision Log
« no previous file with comments | « cc/output/gl_renderer.h ('k') | cc/trees/layer_tree_host_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <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
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
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
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 all buffered GL calls are drawn to the
645 // texture. 675 // backing store before we access and return it, and have cc begin using the
646 offscreen_contexts->GrContext()->flush(); 676 // GL context again.
647 677 use_gr_context->context()->flush();
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 678
652 return device.accessBitmap(false); 679 return device.accessBitmap(false);
653 } 680 }
654 681
655 static SkBitmap ApplyBlendModeWithBackdrop( 682 static SkBitmap ApplyBlendModeWithBackdrop(
656 GLRenderer* renderer, 683 scoped_ptr<GLRenderer::ScopedUseGrContext> use_gr_context,
657 ContextProvider* offscreen_contexts, 684 ResourceProvider* resource_provider,
658 SkBitmap source_bitmap_with_filters, 685 SkBitmap source_bitmap_with_filters,
659 ScopedResource* source_texture_resource, 686 ScopedResource* source_texture_resource,
660 ScopedResource* background_texture_resource, 687 ScopedResource* background_texture_resource,
661 SkXfermode::Mode blend_mode) { 688 SkXfermode::Mode blend_mode) {
662 if (!offscreen_contexts || !offscreen_contexts->GrContext()) 689 if (!use_gr_context)
663 return source_bitmap_with_filters; 690 return source_bitmap_with_filters;
664 691
665 DCHECK(background_texture_resource); 692 DCHECK(background_texture_resource);
666 DCHECK(source_texture_resource); 693 DCHECK(source_texture_resource);
667 694
668 gfx::Size source_size = source_texture_resource->size(); 695 gfx::Size source_size = source_texture_resource->size();
669 gfx::Size background_size = background_texture_resource->size(); 696 gfx::Size background_size = background_texture_resource->size();
670 697
671 DCHECK_LE(background_size.width(), source_size.width()); 698 DCHECK_LE(background_size.width(), source_size.width());
672 DCHECK_LE(background_size.height(), source_size.height()); 699 DCHECK_LE(background_size.height(), source_size.height());
673 700
674 int source_texture_with_filters_id; 701 int source_texture_with_filters_id;
675 scoped_ptr<ResourceProvider::ScopedReadLockGL> lock; 702 scoped_ptr<ResourceProvider::ScopedReadLockGL> lock;
676 if (source_bitmap_with_filters.getTexture()) { 703 if (source_bitmap_with_filters.getTexture()) {
677 DCHECK_EQ(source_size.width(), source_bitmap_with_filters.width()); 704 DCHECK_EQ(source_size.width(), source_bitmap_with_filters.width());
678 DCHECK_EQ(source_size.height(), source_bitmap_with_filters.height()); 705 DCHECK_EQ(source_size.height(), source_bitmap_with_filters.height());
679 GrTexture* texture = 706 GrTexture* texture =
680 reinterpret_cast<GrTexture*>(source_bitmap_with_filters.getTexture()); 707 reinterpret_cast<GrTexture*>(source_bitmap_with_filters.getTexture());
681 source_texture_with_filters_id = texture->getTextureHandle(); 708 source_texture_with_filters_id = texture->getTextureHandle();
682 } else { 709 } else {
683 lock.reset(new ResourceProvider::ScopedReadLockGL( 710 lock.reset(new ResourceProvider::ScopedReadLockGL(
684 renderer->resource_provider(), source_texture_resource->id())); 711 resource_provider, source_texture_resource->id()));
685 source_texture_with_filters_id = lock->texture_id(); 712 source_texture_with_filters_id = lock->texture_id();
686 } 713 }
687 714
688 ResourceProvider::ScopedReadLockGL lock_background( 715 ResourceProvider::ScopedReadLockGL lock_background(
689 renderer->resource_provider(), background_texture_resource->id()); 716 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 717
696 // Wrap the source texture in a Ganesh platform texture. 718 // Wrap the source texture in a Ganesh platform texture.
697 GrBackendTextureDesc backend_texture_description; 719 GrBackendTextureDesc backend_texture_description;
698 backend_texture_description.fConfig = kSkia8888_GrPixelConfig; 720 backend_texture_description.fConfig = kSkia8888_GrPixelConfig;
699 backend_texture_description.fOrigin = kBottomLeft_GrSurfaceOrigin; 721 backend_texture_description.fOrigin = kBottomLeft_GrSurfaceOrigin;
700 722
701 backend_texture_description.fWidth = source_size.width(); 723 backend_texture_description.fWidth = source_size.width();
702 backend_texture_description.fHeight = source_size.height(); 724 backend_texture_description.fHeight = source_size.height();
703 backend_texture_description.fTextureHandle = source_texture_with_filters_id; 725 backend_texture_description.fTextureHandle = source_texture_with_filters_id;
704 skia::RefPtr<GrTexture> source_texture = 726 skia::RefPtr<GrTexture> source_texture =
705 skia::AdoptRef(offscreen_contexts->GrContext()->wrapBackendTexture( 727 skia::AdoptRef(use_gr_context->context()->wrapBackendTexture(
706 backend_texture_description)); 728 backend_texture_description));
707 729
708 backend_texture_description.fWidth = background_size.width(); 730 backend_texture_description.fWidth = background_size.width();
709 backend_texture_description.fHeight = background_size.height(); 731 backend_texture_description.fHeight = background_size.height();
710 backend_texture_description.fTextureHandle = lock_background.texture_id(); 732 backend_texture_description.fTextureHandle = lock_background.texture_id();
711 skia::RefPtr<GrTexture> background_texture = 733 skia::RefPtr<GrTexture> background_texture =
712 skia::AdoptRef(offscreen_contexts->GrContext()->wrapBackendTexture( 734 skia::AdoptRef(use_gr_context->context()->wrapBackendTexture(
713 backend_texture_description)); 735 backend_texture_description));
714 736
715 SkImageInfo source_info = { 737 SkImageInfo source_info = {
716 source_size.width(), 738 source_size.width(),
717 source_size.height(), 739 source_size.height(),
718 kPMColor_SkColorType, 740 kPMColor_SkColorType,
719 kPremul_SkAlphaType 741 kPremul_SkAlphaType
720 }; 742 };
721 // Place the platform texture inside an SkBitmap. 743 // Place the platform texture inside an SkBitmap.
722 SkBitmap source; 744 SkBitmap source;
(...skipping 18 matching lines...) Expand all
741 763
742 // Create a scratch texture for backing store. 764 // Create a scratch texture for backing store.
743 GrTextureDesc desc; 765 GrTextureDesc desc;
744 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; 766 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit;
745 desc.fSampleCnt = 0; 767 desc.fSampleCnt = 0;
746 desc.fWidth = source.width(); 768 desc.fWidth = source.width();
747 desc.fHeight = source.height(); 769 desc.fHeight = source.height();
748 desc.fConfig = kSkia8888_GrPixelConfig; 770 desc.fConfig = kSkia8888_GrPixelConfig;
749 desc.fOrigin = kBottomLeft_GrSurfaceOrigin; 771 desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
750 GrAutoScratchTexture scratch_texture( 772 GrAutoScratchTexture scratch_texture(
751 offscreen_contexts->GrContext(), desc, GrContext::kExact_ScratchTexMatch); 773 use_gr_context->context(), desc, GrContext::kExact_ScratchTexMatch);
752 skia::RefPtr<GrTexture> backing_store = 774 skia::RefPtr<GrTexture> backing_store =
753 skia::AdoptRef(scratch_texture.detach()); 775 skia::AdoptRef(scratch_texture.detach());
754 776
755 // Create a device and canvas using that backing store. 777 // Create a device and canvas using that backing store.
756 SkGpuDevice device(offscreen_contexts->GrContext(), backing_store.get()); 778 SkGpuDevice device(use_gr_context->context(), backing_store.get());
757 SkCanvas canvas(&device); 779 SkCanvas canvas(&device);
758 780
759 // Draw the source bitmap through the filter to the canvas. 781 // Draw the source bitmap through the filter to the canvas.
760 canvas.clear(SK_ColorTRANSPARENT); 782 canvas.clear(SK_ColorTRANSPARENT);
761 canvas.drawSprite(background, 0, 0); 783 canvas.drawSprite(background, 0, 0);
762 SkPaint paint; 784 SkPaint paint;
763 paint.setXfermodeMode(blend_mode); 785 paint.setXfermodeMode(blend_mode);
764 canvas.drawSprite(source, 0, 0, &paint); 786 canvas.drawSprite(source, 0, 0, &paint);
765 787
766 // Flush skia context so that all the rendered stuff appears on the 788 // Flush the GrContext to ensure all buffered GL calls are drawn to the
767 // texture. 789 // backing store before we access and return it, and have cc begin using the
768 offscreen_contexts->GrContext()->flush(); 790 // GL context again.
769 791 use_gr_context->context()->flush();
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 792
774 return device.accessBitmap(false); 793 return device.accessBitmap(false);
775 } 794 }
776 795
777 scoped_ptr<ScopedResource> GLRenderer::GetBackgroundWithFilters( 796 scoped_ptr<ScopedResource> GLRenderer::GetBackgroundWithFilters(
778 DrawingFrame* frame, 797 DrawingFrame* frame,
779 const RenderPassDrawQuad* quad, 798 const RenderPassDrawQuad* quad,
780 const gfx::Transform& contents_device_transform, 799 const gfx::Transform& contents_device_transform,
781 const gfx::Transform& contents_device_transform_inverse, 800 const gfx::Transform& contents_device_transform_inverse,
782 bool* background_changed) { 801 bool* background_changed) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 GetFramebufferTexture( 859 GetFramebufferTexture(
841 lock.texture_id(), device_background_texture->format(), window_rect); 860 lock.texture_id(), device_background_texture->format(), window_rect);
842 } 861 }
843 862
844 skia::RefPtr<SkImageFilter> filter = RenderSurfaceFilters::BuildImageFilter( 863 skia::RefPtr<SkImageFilter> filter = RenderSurfaceFilters::BuildImageFilter(
845 quad->background_filters, device_background_texture->size()); 864 quad->background_filters, device_background_texture->size());
846 865
847 SkBitmap filtered_device_background; 866 SkBitmap filtered_device_background;
848 if (apply_background_filters) { 867 if (apply_background_filters) {
849 filtered_device_background = 868 filtered_device_background =
850 ApplyImageFilter(this, 869 ApplyImageFilter(ScopedUseGrContext::Create(this, frame),
851 frame->offscreen_context_provider, 870 resource_provider_,
852 quad->rect.origin(), 871 quad->rect.origin(),
853 filter.get(), 872 filter.get(),
854 device_background_texture.get()); 873 device_background_texture.get());
855 } 874 }
856 *background_changed = (filtered_device_background.getTexture() != NULL); 875 *background_changed = (filtered_device_background.getTexture() != NULL);
857 876
858 int filtered_device_background_texture_id = 0; 877 int filtered_device_background_texture_id = 0;
859 scoped_ptr<ResourceProvider::ScopedReadLockGL> lock; 878 scoped_ptr<ResourceProvider::ScopedReadLockGL> lock;
860 if (filtered_device_background.getTexture()) { 879 if (filtered_device_background.getTexture()) {
861 GrTexture* texture = 880 GrTexture* texture =
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
952 971
953 if (disable_blending) 972 if (disable_blending)
954 SetBlendEnabled(true); 973 SetBlendEnabled(true);
955 } 974 }
956 975
957 // TODO(senorblanco): Cache this value so that we don't have to do it for both 976 // 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. 977 // the surface and its replica. Apply filters to the contents texture.
959 SkBitmap filter_bitmap; 978 SkBitmap filter_bitmap;
960 SkScalar color_matrix[20]; 979 SkScalar color_matrix[20];
961 bool use_color_matrix = false; 980 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()) { 981 if (!quad->filters.IsEmpty()) {
965 skia::RefPtr<SkImageFilter> filter = RenderSurfaceFilters::BuildImageFilter( 982 skia::RefPtr<SkImageFilter> filter = RenderSurfaceFilters::BuildImageFilter(
966 quad->filters, contents_texture->size()); 983 quad->filters, contents_texture->size());
967 if (filter) { 984 if (filter) {
968 skia::RefPtr<SkColorFilter> cf; 985 skia::RefPtr<SkColorFilter> cf;
969 986
970 { 987 {
971 SkColorFilter* colorfilter_rawptr = NULL; 988 SkColorFilter* colorfilter_rawptr = NULL;
972 filter->asColorFilter(&colorfilter_rawptr); 989 filter->asColorFilter(&colorfilter_rawptr);
973 cf = skia::AdoptRef(colorfilter_rawptr); 990 cf = skia::AdoptRef(colorfilter_rawptr);
974 } 991 }
975 992
976 if (cf && cf->asColorMatrix(color_matrix) && !filter->getInput(0)) { 993 if (cf && cf->asColorMatrix(color_matrix) && !filter->getInput(0)) {
977 // We have a single color matrix as a filter; apply it locally 994 // We have a single color matrix as a filter; apply it locally
978 // in the compositor. 995 // in the compositor.
979 use_color_matrix = true; 996 use_color_matrix = true;
980 } else { 997 } else {
981 filter_bitmap = ApplyImageFilter(this, 998 filter_bitmap =
982 frame->offscreen_context_provider, 999 ApplyImageFilter(ScopedUseGrContext::Create(this, frame),
983 quad->rect.origin(), 1000 resource_provider_,
984 filter.get(), 1001 quad->rect.origin(),
985 contents_texture); 1002 filter.get(),
1003 contents_texture);
986 } 1004 }
987 } 1005 }
988 } 1006 }
989 1007
990 if (quad->shared_quad_state->blend_mode != SkXfermode::kSrcOver_Mode && 1008 if (quad->shared_quad_state->blend_mode != SkXfermode::kSrcOver_Mode &&
991 background_texture) { 1009 background_texture) {
992 filter_bitmap = 1010 filter_bitmap =
993 ApplyBlendModeWithBackdrop(this, 1011 ApplyBlendModeWithBackdrop(ScopedUseGrContext::Create(this, frame),
994 frame->offscreen_context_provider, 1012 resource_provider_,
995 filter_bitmap, 1013 filter_bitmap,
996 contents_texture, 1014 contents_texture,
997 background_texture.get(), 1015 background_texture.get(),
998 quad->shared_quad_state->blend_mode); 1016 quad->shared_quad_state->blend_mode);
999 } 1017 }
1000 1018
1001 // Draw the background texture if it has some filters applied. 1019 // Draw the background texture if it has some filters applied.
1002 if (background_texture && background_changed) { 1020 if (background_texture && background_changed) {
1003 DCHECK(background_texture->size() == quad->rect.size()); 1021 DCHECK(background_texture->size() == quad->rect.size());
1004 ResourceProvider::ScopedReadLockGL lock(resource_provider_, 1022 ResourceProvider::ScopedReadLockGL lock(resource_provider_,
(...skipping 2099 matching lines...) Expand 10 before | Expand all | Expand 10 after
3104 if (offscreen_framebuffer_id_) 3122 if (offscreen_framebuffer_id_)
3105 GLC(gl_, gl_->DeleteFramebuffers(1, &offscreen_framebuffer_id_)); 3123 GLC(gl_, gl_->DeleteFramebuffers(1, &offscreen_framebuffer_id_));
3106 3124
3107 if (on_demand_tile_raster_resource_id_) 3125 if (on_demand_tile_raster_resource_id_)
3108 resource_provider_->DeleteResource(on_demand_tile_raster_resource_id_); 3126 resource_provider_->DeleteResource(on_demand_tile_raster_resource_id_);
3109 3127
3110 ReleaseRenderPassTextures(); 3128 ReleaseRenderPassTextures();
3111 } 3129 }
3112 3130
3113 void GLRenderer::ReinitializeGLState() { 3131 void GLRenderer::ReinitializeGLState() {
3114 // Bind the common vertex attributes used for drawing all the layers. 3132 is_scissor_enabled_ = false;
3133 scissor_rect_needs_reset_ = true;
3134 stencil_shadow_ = false;
3135 blend_shadow_ = true;
3136 program_shadow_ = 0;
3137
3138 RestoreGLState();
3139 }
3140
3141 void GLRenderer::RestoreGLState() {
3142 // This restores the current GLRenderer state to the GL context.
3143
3115 shared_geometry_->PrepareForDraw(); 3144 shared_geometry_->PrepareForDraw();
3116 3145
3117 GLC(gl_, gl_->Disable(GL_DEPTH_TEST)); 3146 GLC(gl_, gl_->Disable(GL_DEPTH_TEST));
3118 GLC(gl_, gl_->Disable(GL_CULL_FACE)); 3147 GLC(gl_, gl_->Disable(GL_CULL_FACE));
3119 GLC(gl_, gl_->ColorMask(true, true, true, true)); 3148 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)); 3149 GLC(gl_, gl_->BlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA));
3125 GLC(gl_, gl_->ActiveTexture(GL_TEXTURE0)); 3150 GLC(gl_, gl_->ActiveTexture(GL_TEXTURE0));
3126 program_shadow_ = 0;
3127 3151
3128 // Make sure scissoring starts as disabled. 3152 if (program_shadow_)
3129 is_scissor_enabled_ = false; 3153 gl_->UseProgram(program_shadow_);
3130 GLC(gl_, gl_->Disable(GL_SCISSOR_TEST)); 3154
3131 scissor_rect_needs_reset_ = true; 3155 if (stencil_shadow_)
3156 GLC(gl_, gl_->Enable(GL_STENCIL_TEST));
3157 else
3158 GLC(gl_, gl_->Disable(GL_STENCIL_TEST));
3159
3160 if (blend_shadow_)
3161 GLC(gl_, gl_->Enable(GL_BLEND));
3162 else
3163 GLC(gl_, gl_->Disable(GL_BLEND));
3164
3165 if (is_scissor_enabled_) {
3166 GLC(gl_, gl_->Enable(GL_SCISSOR_TEST));
3167 GLC(gl_,
3168 gl_->Scissor(scissor_rect_.x(),
3169 scissor_rect_.y(),
3170 scissor_rect_.width(),
3171 scissor_rect_.height()));
3172 } else {
3173 GLC(gl_, gl_->Disable(GL_SCISSOR_TEST));
3174 }
3175 }
3176
3177 void GLRenderer::RestoreFramebuffer(DrawingFrame* frame) {
3178 UseRenderPass(frame, frame->current_render_pass);
3132 } 3179 }
3133 3180
3134 bool GLRenderer::IsContextLost() { 3181 bool GLRenderer::IsContextLost() {
3135 return output_surface_->context_provider()->IsContextLost(); 3182 return output_surface_->context_provider()->IsContextLost();
3136 } 3183 }
3137 3184
3138 void GLRenderer::ScheduleOverlays(DrawingFrame* frame) { 3185 void GLRenderer::ScheduleOverlays(DrawingFrame* frame) {
3139 if (!frame->overlay_list.size()) 3186 if (!frame->overlay_list.size())
3140 return; 3187 return;
3141 3188
3142 ResourceProvider::ResourceIdArray resources; 3189 ResourceProvider::ResourceIdArray resources;
3143 OverlayCandidateList& overlays = frame->overlay_list; 3190 OverlayCandidateList& overlays = frame->overlay_list;
3144 OverlayCandidateList::iterator it; 3191 OverlayCandidateList::iterator it;
3145 for (it = overlays.begin(); it != overlays.end(); ++it) { 3192 for (it = overlays.begin(); it != overlays.end(); ++it) {
3146 const OverlayCandidate& overlay = *it; 3193 const OverlayCandidate& overlay = *it;
3147 // Skip primary plane. 3194 // Skip primary plane.
3148 if (overlay.plane_z_order == 0) 3195 if (overlay.plane_z_order == 0)
3149 continue; 3196 continue;
3150 3197
3151 pending_overlay_resources_.push_back( 3198 pending_overlay_resources_.push_back(
3152 make_scoped_ptr(new ResourceProvider::ScopedReadLockGL( 3199 make_scoped_ptr(new ResourceProvider::ScopedReadLockGL(
3153 resource_provider(), overlay.resource_id))); 3200 resource_provider_, overlay.resource_id)));
3154 3201
3155 context_support_->ScheduleOverlayPlane( 3202 context_support_->ScheduleOverlayPlane(
3156 overlay.plane_z_order, 3203 overlay.plane_z_order,
3157 overlay.transform, 3204 overlay.transform,
3158 pending_overlay_resources_.back()->texture_id(), 3205 pending_overlay_resources_.back()->texture_id(),
3159 overlay.display_rect, 3206 overlay.display_rect,
3160 overlay.uv_rect); 3207 overlay.uv_rect);
3161 } 3208 }
3162 } 3209 }
3163 3210
3164 } // namespace cc 3211 } // namespace cc
OLDNEW
« no previous file with comments | « cc/output/gl_renderer.h ('k') | cc/trees/layer_tree_host_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698