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

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: 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
« cc/output/gl_renderer.h ('K') | « cc/output/gl_renderer.h ('k') | no next file » | 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::UseGrContext {
enne (OOO) 2014/04/23 19:53:41 ScopedUseGrContext?
Stephen White 2014/04/23 19:57:20 I find this guard class to be too much magic. I li
danakj 2014/04/23 20:11:10 2014/04/23 19:57:20, Stephen White wrote:
181 public:
182 static scoped_ptr<UseGrContext> Create(GLRenderer* renderer,
183 DrawingFrame* frame) {
184 if (!renderer->output_surface_->context_provider()->GrContext())
185 return scoped_ptr<UseGrContext>();
186 return make_scoped_ptr(new UseGrContext(renderer, frame));
187 }
188
189 ~UseGrContext() { PassControlToGLRenderer(); }
190
191 GrContext* context() const {
192 return renderer_->output_surface_->context_provider()->GrContext();
193 }
194
195 private:
196 UseGrContext(GLRenderer* renderer, DrawingFrame* frame)
197 : renderer_(renderer), frame_(frame) {
198 PassControlToSkia();
199 }
200
201 void PassControlToSkia() { context()->resetContext(); }
202
203 void PassControlToGLRenderer() {
204 context()->flush();
205 renderer_->RestoreGLState(frame_);
206 }
207
208 GLRenderer* renderer_;
209 DrawingFrame* frame_;
210 DISALLOW_COPY_AND_ASSIGN(UseGrContext);
enne (OOO) 2014/04/23 19:53:41 Stick a blank line before DISALLOW for readability
211 };
212
180 struct GLRenderer::PendingAsyncReadPixels { 213 struct GLRenderer::PendingAsyncReadPixels {
181 PendingAsyncReadPixels() : buffer(0) {} 214 PendingAsyncReadPixels() : buffer(0) {}
182 215
183 scoped_ptr<CopyOutputRequest> copy_request; 216 scoped_ptr<CopyOutputRequest> copy_request;
184 base::CancelableClosure finished_read_pixels_callback; 217 base::CancelableClosure finished_read_pixels_callback;
185 unsigned buffer; 218 unsigned buffer;
186 219
187 private: 220 private:
188 DISALLOW_COPY_AND_ASSIGN(PendingAsyncReadPixels); 221 DISALLOW_COPY_AND_ASSIGN(PendingAsyncReadPixels);
189 }; 222 };
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 capabilities_.max_texture_size = resource_provider_->max_texture_size(); 326 capabilities_.max_texture_size = resource_provider_->max_texture_size();
294 capabilities_.best_texture_format = resource_provider_->best_texture_format(); 327 capabilities_.best_texture_format = resource_provider_->best_texture_format();
295 328
296 // The updater can access textures while the GLRenderer is using them. 329 // The updater can access textures while the GLRenderer is using them.
297 capabilities_.allow_partial_texture_updates = true; 330 capabilities_.allow_partial_texture_updates = true;
298 331
299 // Check for texture fast paths. Currently we always use MO8 textures, 332 // 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. 333 // 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; 334 capabilities_.avoid_pow2_textures = context_caps.gpu.fast_npot_mo8_textures;
302 335
303 capabilities_.using_offscreen_context3d = true; 336 capabilities_.using_offscreen_context3d = false;
304 337
305 capabilities_.using_map_image = 338 capabilities_.using_map_image =
306 settings_->use_map_image && context_caps.gpu.map_image; 339 settings_->use_map_image && context_caps.gpu.map_image;
307 340
308 capabilities_.using_discard_framebuffer = 341 capabilities_.using_discard_framebuffer =
309 context_caps.gpu.discard_framebuffer; 342 context_caps.gpu.discard_framebuffer;
310 343
311 capabilities_.allow_rasterize_on_demand = true; 344 capabilities_.allow_rasterize_on_demand = true;
312 345
313 use_sync_query_ = context_caps.gpu.sync_query; 346 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, 595 (SkColorGetB(color) * (1.0f / 255.0f)) * alpha,
563 alpha)); 596 alpha));
564 597
565 GLC(gl_, gl_->LineWidth(quad->width)); 598 GLC(gl_, gl_->LineWidth(quad->width));
566 599
567 // The indices for the line are stored in the same array as the triangle 600 // The indices for the line are stored in the same array as the triangle
568 // indices. 601 // indices.
569 GLC(gl_, gl_->DrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_SHORT, 0)); 602 GLC(gl_, gl_->DrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_SHORT, 0));
570 } 603 }
571 604
572 static SkBitmap ApplyImageFilter(GLRenderer* renderer, 605 static SkBitmap ApplyImageFilter(
573 ContextProvider* offscreen_contexts, 606 scoped_ptr<GLRenderer::UseGrContext> use_gr_context,
574 const gfx::Point& origin, 607 ResourceProvider* resource_provider,
575 SkImageFilter* filter, 608 const gfx::Point& origin,
576 ScopedResource* source_texture_resource) { 609 SkImageFilter* filter,
610 ScopedResource* source_texture_resource) {
577 if (!filter) 611 if (!filter)
578 return SkBitmap(); 612 return SkBitmap();
579 613
580 if (!offscreen_contexts || !offscreen_contexts->GrContext()) 614 if (!use_gr_context)
581 return SkBitmap(); 615 return SkBitmap();
582 616
583 ResourceProvider::ScopedReadLockGL lock(renderer->resource_provider(), 617 ResourceProvider::ScopedReadLockGL lock(resource_provider,
584 source_texture_resource->id()); 618 source_texture_resource->id());
585 619
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. 620 // Wrap the source texture in a Ganesh platform texture.
592 GrBackendTextureDesc backend_texture_description; 621 GrBackendTextureDesc backend_texture_description;
593 backend_texture_description.fWidth = source_texture_resource->size().width(); 622 backend_texture_description.fWidth = source_texture_resource->size().width();
594 backend_texture_description.fHeight = 623 backend_texture_description.fHeight =
595 source_texture_resource->size().height(); 624 source_texture_resource->size().height();
596 backend_texture_description.fConfig = kSkia8888_GrPixelConfig; 625 backend_texture_description.fConfig = kSkia8888_GrPixelConfig;
597 backend_texture_description.fTextureHandle = lock.texture_id(); 626 backend_texture_description.fTextureHandle = lock.texture_id();
598 backend_texture_description.fOrigin = kBottomLeft_GrSurfaceOrigin; 627 backend_texture_description.fOrigin = kBottomLeft_GrSurfaceOrigin;
599 skia::RefPtr<GrTexture> texture = 628 skia::RefPtr<GrTexture> texture =
600 skia::AdoptRef(offscreen_contexts->GrContext()->wrapBackendTexture( 629 skia::AdoptRef(use_gr_context->context()->wrapBackendTexture(
601 backend_texture_description)); 630 backend_texture_description));
602 631
603 SkImageInfo info = { 632 SkImageInfo info = {
604 source_texture_resource->size().width(), 633 source_texture_resource->size().width(),
605 source_texture_resource->size().height(), 634 source_texture_resource->size().height(),
606 kPMColor_SkColorType, 635 kPMColor_SkColorType,
607 kPremul_SkAlphaType 636 kPremul_SkAlphaType
608 }; 637 };
609 // Place the platform texture inside an SkBitmap. 638 // Place the platform texture inside an SkBitmap.
610 SkBitmap source; 639 SkBitmap source;
611 source.setConfig(info); 640 source.setConfig(info);
612 skia::RefPtr<SkGrPixelRef> pixel_ref = 641 skia::RefPtr<SkGrPixelRef> pixel_ref =
613 skia::AdoptRef(new SkGrPixelRef(info, texture.get())); 642 skia::AdoptRef(new SkGrPixelRef(info, texture.get()));
614 source.setPixelRef(pixel_ref.get()); 643 source.setPixelRef(pixel_ref.get());
615 644
616 // Create a scratch texture for backing store. 645 // Create a scratch texture for backing store.
617 GrTextureDesc desc; 646 GrTextureDesc desc;
618 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; 647 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit;
619 desc.fSampleCnt = 0; 648 desc.fSampleCnt = 0;
620 desc.fWidth = source.width(); 649 desc.fWidth = source.width();
621 desc.fHeight = source.height(); 650 desc.fHeight = source.height();
622 desc.fConfig = kSkia8888_GrPixelConfig; 651 desc.fConfig = kSkia8888_GrPixelConfig;
623 desc.fOrigin = kBottomLeft_GrSurfaceOrigin; 652 desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
624 GrAutoScratchTexture scratch_texture( 653 GrAutoScratchTexture scratch_texture(
625 offscreen_contexts->GrContext(), desc, GrContext::kExact_ScratchTexMatch); 654 use_gr_context->context(), desc, GrContext::kExact_ScratchTexMatch);
626 skia::RefPtr<GrTexture> backing_store = 655 skia::RefPtr<GrTexture> backing_store =
627 skia::AdoptRef(scratch_texture.detach()); 656 skia::AdoptRef(scratch_texture.detach());
628 657
629 // Create a device and canvas using that backing store. 658 // Create a device and canvas using that backing store.
630 SkGpuDevice device(offscreen_contexts->GrContext(), backing_store.get()); 659 SkGpuDevice device(use_gr_context->context(), backing_store.get());
631 SkCanvas canvas(&device); 660 SkCanvas canvas(&device);
632 661
633 // Draw the source bitmap through the filter to the canvas. 662 // Draw the source bitmap through the filter to the canvas.
634 SkPaint paint; 663 SkPaint paint;
635 paint.setImageFilter(filter); 664 paint.setImageFilter(filter);
636 canvas.clear(SK_ColorTRANSPARENT); 665 canvas.clear(SK_ColorTRANSPARENT);
637 666
638 // TODO(senorblanco): in addition to the origin translation here, the canvas 667 // 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 668 // should also be scaled to accomodate device pixel ratio and pinch zoom. See
640 // crbug.com/281516 and crbug.com/281518. 669 // crbug.com/281516 and crbug.com/281518.
641 canvas.translate(SkIntToScalar(-origin.x()), SkIntToScalar(-origin.y())); 670 canvas.translate(SkIntToScalar(-origin.x()), SkIntToScalar(-origin.y()));
642 canvas.drawSprite(source, 0, 0, &paint); 671 canvas.drawSprite(source, 0, 0, &paint);
643 672
644 // Flush skia context so that all the rendered stuff appears on the
645 // texture.
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
652 return device.accessBitmap(false); 673 return device.accessBitmap(false);
653 } 674 }
654 675
655 static SkBitmap ApplyBlendModeWithBackdrop( 676 static SkBitmap ApplyBlendModeWithBackdrop(
656 GLRenderer* renderer, 677 scoped_ptr<GLRenderer::UseGrContext> use_gr_context,
657 ContextProvider* offscreen_contexts, 678 ResourceProvider* resource_provider,
658 SkBitmap source_bitmap_with_filters, 679 SkBitmap source_bitmap_with_filters,
659 ScopedResource* source_texture_resource, 680 ScopedResource* source_texture_resource,
660 ScopedResource* background_texture_resource, 681 ScopedResource* background_texture_resource,
661 SkXfermode::Mode blend_mode) { 682 SkXfermode::Mode blend_mode) {
662 if (!offscreen_contexts || !offscreen_contexts->GrContext()) 683 if (!use_gr_context)
663 return source_bitmap_with_filters; 684 return source_bitmap_with_filters;
664 685
665 DCHECK(background_texture_resource); 686 DCHECK(background_texture_resource);
666 DCHECK(source_texture_resource); 687 DCHECK(source_texture_resource);
667 688
668 gfx::Size source_size = source_texture_resource->size(); 689 gfx::Size source_size = source_texture_resource->size();
669 gfx::Size background_size = background_texture_resource->size(); 690 gfx::Size background_size = background_texture_resource->size();
670 691
671 DCHECK_LE(background_size.width(), source_size.width()); 692 DCHECK_LE(background_size.width(), source_size.width());
672 DCHECK_LE(background_size.height(), source_size.height()); 693 DCHECK_LE(background_size.height(), source_size.height());
673 694
674 int source_texture_with_filters_id; 695 int source_texture_with_filters_id;
675 scoped_ptr<ResourceProvider::ScopedReadLockGL> lock; 696 scoped_ptr<ResourceProvider::ScopedReadLockGL> lock;
676 if (source_bitmap_with_filters.getTexture()) { 697 if (source_bitmap_with_filters.getTexture()) {
677 DCHECK_EQ(source_size.width(), source_bitmap_with_filters.width()); 698 DCHECK_EQ(source_size.width(), source_bitmap_with_filters.width());
678 DCHECK_EQ(source_size.height(), source_bitmap_with_filters.height()); 699 DCHECK_EQ(source_size.height(), source_bitmap_with_filters.height());
679 GrTexture* texture = 700 GrTexture* texture =
680 reinterpret_cast<GrTexture*>(source_bitmap_with_filters.getTexture()); 701 reinterpret_cast<GrTexture*>(source_bitmap_with_filters.getTexture());
681 source_texture_with_filters_id = texture->getTextureHandle(); 702 source_texture_with_filters_id = texture->getTextureHandle();
682 } else { 703 } else {
683 lock.reset(new ResourceProvider::ScopedReadLockGL( 704 lock.reset(new ResourceProvider::ScopedReadLockGL(
684 renderer->resource_provider(), source_texture_resource->id())); 705 resource_provider, source_texture_resource->id()));
685 source_texture_with_filters_id = lock->texture_id(); 706 source_texture_with_filters_id = lock->texture_id();
686 } 707 }
687 708
688 ResourceProvider::ScopedReadLockGL lock_background( 709 ResourceProvider::ScopedReadLockGL lock_background(
689 renderer->resource_provider(), background_texture_resource->id()); 710 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 711
696 // Wrap the source texture in a Ganesh platform texture. 712 // Wrap the source texture in a Ganesh platform texture.
697 GrBackendTextureDesc backend_texture_description; 713 GrBackendTextureDesc backend_texture_description;
698 backend_texture_description.fConfig = kSkia8888_GrPixelConfig; 714 backend_texture_description.fConfig = kSkia8888_GrPixelConfig;
699 backend_texture_description.fOrigin = kBottomLeft_GrSurfaceOrigin; 715 backend_texture_description.fOrigin = kBottomLeft_GrSurfaceOrigin;
700 716
701 backend_texture_description.fWidth = source_size.width(); 717 backend_texture_description.fWidth = source_size.width();
702 backend_texture_description.fHeight = source_size.height(); 718 backend_texture_description.fHeight = source_size.height();
703 backend_texture_description.fTextureHandle = source_texture_with_filters_id; 719 backend_texture_description.fTextureHandle = source_texture_with_filters_id;
704 skia::RefPtr<GrTexture> source_texture = 720 skia::RefPtr<GrTexture> source_texture =
705 skia::AdoptRef(offscreen_contexts->GrContext()->wrapBackendTexture( 721 skia::AdoptRef(use_gr_context->context()->wrapBackendTexture(
706 backend_texture_description)); 722 backend_texture_description));
707 723
708 backend_texture_description.fWidth = background_size.width(); 724 backend_texture_description.fWidth = background_size.width();
709 backend_texture_description.fHeight = background_size.height(); 725 backend_texture_description.fHeight = background_size.height();
710 backend_texture_description.fTextureHandle = lock_background.texture_id(); 726 backend_texture_description.fTextureHandle = lock_background.texture_id();
711 skia::RefPtr<GrTexture> background_texture = 727 skia::RefPtr<GrTexture> background_texture =
712 skia::AdoptRef(offscreen_contexts->GrContext()->wrapBackendTexture( 728 skia::AdoptRef(use_gr_context->context()->wrapBackendTexture(
713 backend_texture_description)); 729 backend_texture_description));
714 730
715 SkImageInfo source_info = { 731 SkImageInfo source_info = {
716 source_size.width(), 732 source_size.width(),
717 source_size.height(), 733 source_size.height(),
718 kPMColor_SkColorType, 734 kPMColor_SkColorType,
719 kPremul_SkAlphaType 735 kPremul_SkAlphaType
720 }; 736 };
721 // Place the platform texture inside an SkBitmap. 737 // Place the platform texture inside an SkBitmap.
722 SkBitmap source; 738 SkBitmap source;
(...skipping 18 matching lines...) Expand all
741 757
742 // Create a scratch texture for backing store. 758 // Create a scratch texture for backing store.
743 GrTextureDesc desc; 759 GrTextureDesc desc;
744 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; 760 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit;
745 desc.fSampleCnt = 0; 761 desc.fSampleCnt = 0;
746 desc.fWidth = source.width(); 762 desc.fWidth = source.width();
747 desc.fHeight = source.height(); 763 desc.fHeight = source.height();
748 desc.fConfig = kSkia8888_GrPixelConfig; 764 desc.fConfig = kSkia8888_GrPixelConfig;
749 desc.fOrigin = kBottomLeft_GrSurfaceOrigin; 765 desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
750 GrAutoScratchTexture scratch_texture( 766 GrAutoScratchTexture scratch_texture(
751 offscreen_contexts->GrContext(), desc, GrContext::kExact_ScratchTexMatch); 767 use_gr_context->context(), desc, GrContext::kExact_ScratchTexMatch);
752 skia::RefPtr<GrTexture> backing_store = 768 skia::RefPtr<GrTexture> backing_store =
753 skia::AdoptRef(scratch_texture.detach()); 769 skia::AdoptRef(scratch_texture.detach());
754 770
755 // Create a device and canvas using that backing store. 771 // Create a device and canvas using that backing store.
756 SkGpuDevice device(offscreen_contexts->GrContext(), backing_store.get()); 772 SkGpuDevice device(use_gr_context->context(), backing_store.get());
757 SkCanvas canvas(&device); 773 SkCanvas canvas(&device);
758 774
759 // Draw the source bitmap through the filter to the canvas. 775 // Draw the source bitmap through the filter to the canvas.
760 canvas.clear(SK_ColorTRANSPARENT); 776 canvas.clear(SK_ColorTRANSPARENT);
761 canvas.drawSprite(background, 0, 0); 777 canvas.drawSprite(background, 0, 0);
762 SkPaint paint; 778 SkPaint paint;
763 paint.setXfermodeMode(blend_mode); 779 paint.setXfermodeMode(blend_mode);
764 canvas.drawSprite(source, 0, 0, &paint); 780 canvas.drawSprite(source, 0, 0, &paint);
765 781
766 // Flush skia context so that all the rendered stuff appears on the
767 // texture.
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
774 return device.accessBitmap(false); 782 return device.accessBitmap(false);
775 } 783 }
776 784
777 scoped_ptr<ScopedResource> GLRenderer::GetBackgroundWithFilters( 785 scoped_ptr<ScopedResource> GLRenderer::GetBackgroundWithFilters(
778 DrawingFrame* frame, 786 DrawingFrame* frame,
779 const RenderPassDrawQuad* quad, 787 const RenderPassDrawQuad* quad,
780 const gfx::Transform& contents_device_transform, 788 const gfx::Transform& contents_device_transform,
781 const gfx::Transform& contents_device_transform_inverse, 789 const gfx::Transform& contents_device_transform_inverse,
782 bool* background_changed) { 790 bool* background_changed) {
783 // This method draws a background filter, which applies a filter to any pixels 791 // This method draws a background filter, which applies a filter to any pixels
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 GetFramebufferTexture( 848 GetFramebufferTexture(
841 lock.texture_id(), device_background_texture->format(), window_rect); 849 lock.texture_id(), device_background_texture->format(), window_rect);
842 } 850 }
843 851
844 skia::RefPtr<SkImageFilter> filter = RenderSurfaceFilters::BuildImageFilter( 852 skia::RefPtr<SkImageFilter> filter = RenderSurfaceFilters::BuildImageFilter(
845 quad->background_filters, device_background_texture->size()); 853 quad->background_filters, device_background_texture->size());
846 854
847 SkBitmap filtered_device_background; 855 SkBitmap filtered_device_background;
848 if (apply_background_filters) { 856 if (apply_background_filters) {
849 filtered_device_background = 857 filtered_device_background =
850 ApplyImageFilter(this, 858 ApplyImageFilter(UseGrContext::Create(this, frame),
851 frame->offscreen_context_provider, 859 resource_provider_,
852 quad->rect.origin(), 860 quad->rect.origin(),
853 filter.get(), 861 filter.get(),
854 device_background_texture.get()); 862 device_background_texture.get());
855 } 863 }
856 *background_changed = (filtered_device_background.getTexture() != NULL); 864 *background_changed = (filtered_device_background.getTexture() != NULL);
857 865
858 int filtered_device_background_texture_id = 0; 866 int filtered_device_background_texture_id = 0;
859 scoped_ptr<ResourceProvider::ScopedReadLockGL> lock; 867 scoped_ptr<ResourceProvider::ScopedReadLockGL> lock;
860 if (filtered_device_background.getTexture()) { 868 if (filtered_device_background.getTexture()) {
861 GrTexture* texture = 869 GrTexture* texture =
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
952 960
953 if (disable_blending) 961 if (disable_blending)
954 SetBlendEnabled(true); 962 SetBlendEnabled(true);
955 } 963 }
956 964
957 // TODO(senorblanco): Cache this value so that we don't have to do it for both 965 // 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. 966 // the surface and its replica. Apply filters to the contents texture.
959 SkBitmap filter_bitmap; 967 SkBitmap filter_bitmap;
960 SkScalar color_matrix[20]; 968 SkScalar color_matrix[20];
961 bool use_color_matrix = false; 969 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()) { 970 if (!quad->filters.IsEmpty()) {
965 skia::RefPtr<SkImageFilter> filter = RenderSurfaceFilters::BuildImageFilter( 971 skia::RefPtr<SkImageFilter> filter = RenderSurfaceFilters::BuildImageFilter(
966 quad->filters, contents_texture->size()); 972 quad->filters, contents_texture->size());
967 if (filter) { 973 if (filter) {
968 skia::RefPtr<SkColorFilter> cf; 974 skia::RefPtr<SkColorFilter> cf;
969 975
970 { 976 {
971 SkColorFilter* colorfilter_rawptr = NULL; 977 SkColorFilter* colorfilter_rawptr = NULL;
972 filter->asColorFilter(&colorfilter_rawptr); 978 filter->asColorFilter(&colorfilter_rawptr);
973 cf = skia::AdoptRef(colorfilter_rawptr); 979 cf = skia::AdoptRef(colorfilter_rawptr);
974 } 980 }
975 981
976 if (cf && cf->asColorMatrix(color_matrix) && !filter->getInput(0)) { 982 if (cf && cf->asColorMatrix(color_matrix) && !filter->getInput(0)) {
977 // We have a single color matrix as a filter; apply it locally 983 // We have a single color matrix as a filter; apply it locally
978 // in the compositor. 984 // in the compositor.
979 use_color_matrix = true; 985 use_color_matrix = true;
980 } else { 986 } else {
981 filter_bitmap = ApplyImageFilter(this, 987 filter_bitmap = ApplyImageFilter(UseGrContext::Create(this, frame),
982 frame->offscreen_context_provider, 988 resource_provider_,
983 quad->rect.origin(), 989 quad->rect.origin(),
984 filter.get(), 990 filter.get(),
985 contents_texture); 991 contents_texture);
986 } 992 }
987 } 993 }
988 } 994 }
989 995
990 if (quad->shared_quad_state->blend_mode != SkXfermode::kSrcOver_Mode && 996 if (quad->shared_quad_state->blend_mode != SkXfermode::kSrcOver_Mode &&
991 background_texture) { 997 background_texture) {
992 filter_bitmap = 998 filter_bitmap =
993 ApplyBlendModeWithBackdrop(this, 999 ApplyBlendModeWithBackdrop(UseGrContext::Create(this, frame),
994 frame->offscreen_context_provider, 1000 resource_provider_,
995 filter_bitmap, 1001 filter_bitmap,
996 contents_texture, 1002 contents_texture,
997 background_texture.get(), 1003 background_texture.get(),
998 quad->shared_quad_state->blend_mode); 1004 quad->shared_quad_state->blend_mode);
999 } 1005 }
1000 1006
1001 // Draw the background texture if it has some filters applied. 1007 // Draw the background texture if it has some filters applied.
1002 if (background_texture && background_changed) { 1008 if (background_texture && background_changed) {
1003 DCHECK(background_texture->size() == quad->rect.size()); 1009 DCHECK(background_texture->size() == quad->rect.size());
1004 ResourceProvider::ScopedReadLockGL lock(resource_provider_, 1010 ResourceProvider::ScopedReadLockGL lock(resource_provider_,
(...skipping 2119 matching lines...) Expand 10 before | Expand all | Expand 10 after
3124 GLC(gl_, gl_->BlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); 3130 GLC(gl_, gl_->BlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA));
3125 GLC(gl_, gl_->ActiveTexture(GL_TEXTURE0)); 3131 GLC(gl_, gl_->ActiveTexture(GL_TEXTURE0));
3126 program_shadow_ = 0; 3132 program_shadow_ = 0;
3127 3133
3128 // Make sure scissoring starts as disabled. 3134 // Make sure scissoring starts as disabled.
3129 is_scissor_enabled_ = false; 3135 is_scissor_enabled_ = false;
3130 GLC(gl_, gl_->Disable(GL_SCISSOR_TEST)); 3136 GLC(gl_, gl_->Disable(GL_SCISSOR_TEST));
3131 scissor_rect_needs_reset_ = true; 3137 scissor_rect_needs_reset_ = true;
3132 } 3138 }
3133 3139
3140 void GLRenderer::RestoreGLState(DrawingFrame* frame) {
enne (OOO) 2014/04/23 19:53:41 How does this function compare to ReinitializeGLSt
danakj 2014/04/23 19:56:05 It's similar but 1. It doesn't change any state o
enne (OOO) 2014/04/23 20:01:10 I think you should combine these if possible. I t
danakj 2014/04/23 20:11:10 I can give merging them a try again.
3141 shared_geometry_->PrepareForDraw();
3142
3143 GLC(gl_, gl_->Disable(GL_DEPTH_TEST));
3144 GLC(gl_, gl_->Disable(GL_CULL_FACE));
3145 GLC(gl_, gl_->ColorMask(true, true, true, true));
3146 GLC(gl_, gl_->BlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA));
3147 GLC(gl_, gl_->ActiveTexture(GL_TEXTURE0));
3148
3149 if (stencil_shadow_)
Stephen White 2014/04/23 19:57:20 I'm a little nervous that this state-setting code
3150 GLC(gl_, gl_->Enable(GL_STENCIL_TEST));
3151 else
3152 GLC(gl_, gl_->Disable(GL_STENCIL_TEST));
3153
3154 if (blend_shadow_)
3155 GLC(gl_, gl_->Enable(GL_BLEND));
3156 else
3157 GLC(gl_, gl_->Disable(GL_BLEND));
3158
3159 if (is_scissor_enabled_) {
3160 GLC(gl_, gl_->Enable(GL_SCISSOR_TEST));
3161 GLC(gl_,
3162 gl_->Scissor(scissor_rect_.x(),
3163 scissor_rect_.y(),
3164 scissor_rect_.width(),
3165 scissor_rect_.height()));
3166 } else {
3167 GLC(gl_, gl_->Disable(GL_SCISSOR_TEST));
3168 }
3169
3170 SetUseProgram(0);
3171
3172 UseRenderPass(frame, frame->current_render_pass);
3173 }
3174
3134 bool GLRenderer::IsContextLost() { 3175 bool GLRenderer::IsContextLost() {
3135 return output_surface_->context_provider()->IsContextLost(); 3176 return output_surface_->context_provider()->IsContextLost();
3136 } 3177 }
3137 3178
3138 void GLRenderer::ScheduleOverlays(DrawingFrame* frame) { 3179 void GLRenderer::ScheduleOverlays(DrawingFrame* frame) {
3139 if (!frame->overlay_list.size()) 3180 if (!frame->overlay_list.size())
3140 return; 3181 return;
3141 3182
3142 ResourceProvider::ResourceIdArray resources; 3183 ResourceProvider::ResourceIdArray resources;
3143 OverlayCandidateList& overlays = frame->overlay_list; 3184 OverlayCandidateList& overlays = frame->overlay_list;
(...skipping 11 matching lines...) Expand all
3155 context_support_->ScheduleOverlayPlane( 3196 context_support_->ScheduleOverlayPlane(
3156 overlay.plane_z_order, 3197 overlay.plane_z_order,
3157 overlay.transform, 3198 overlay.transform,
3158 pending_overlay_resources_.back()->texture_id(), 3199 pending_overlay_resources_.back()->texture_id(),
3159 overlay.display_rect, 3200 overlay.display_rect,
3160 overlay.uv_rect); 3201 overlay.uv_rect);
3161 } 3202 }
3162 } 3203 }
3163 3204
3164 } // namespace cc 3205 } // namespace cc
OLDNEW
« cc/output/gl_renderer.h ('K') | « cc/output/gl_renderer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698