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