| 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 606 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 617   GLC(gl_, gl_->LineWidth(quad->width)); | 617   GLC(gl_, gl_->LineWidth(quad->width)); | 
| 618 | 618 | 
| 619   // The indices for the line are stored in the same array as the triangle | 619   // The indices for the line are stored in the same array as the triangle | 
| 620   // indices. | 620   // indices. | 
| 621   GLC(gl_, gl_->DrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_SHORT, 0)); | 621   GLC(gl_, gl_->DrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_SHORT, 0)); | 
| 622 } | 622 } | 
| 623 | 623 | 
| 624 static skia::RefPtr<SkImage> ApplyImageFilter( | 624 static skia::RefPtr<SkImage> ApplyImageFilter( | 
| 625     scoped_ptr<GLRenderer::ScopedUseGrContext> use_gr_context, | 625     scoped_ptr<GLRenderer::ScopedUseGrContext> use_gr_context, | 
| 626     ResourceProvider* resource_provider, | 626     ResourceProvider* resource_provider, | 
| 627     const gfx::Point& origin, | 627     const gfx::Rect& rect, | 
| 628     const gfx::Vector2dF& scale, | 628     const gfx::Vector2dF& scale, | 
| 629     SkImageFilter* filter, | 629     SkImageFilter* filter, | 
| 630     ScopedResource* source_texture_resource) { | 630     ScopedResource* source_texture_resource) { | 
| 631   if (!filter) | 631   if (!filter) | 
| 632     return skia::RefPtr<SkImage>(); | 632     return skia::RefPtr<SkImage>(); | 
| 633 | 633 | 
| 634   if (!use_gr_context) | 634   if (!use_gr_context) | 
| 635     return skia::RefPtr<SkImage>(); | 635     return skia::RefPtr<SkImage>(); | 
| 636 | 636 | 
| 637   ResourceProvider::ScopedReadLockGL lock(resource_provider, | 637   ResourceProvider::ScopedReadLockGL lock(resource_provider, | 
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 686   // Create surface to draw into. | 686   // Create surface to draw into. | 
| 687   skia::RefPtr<SkSurface> surface = skia::AdoptRef( | 687   skia::RefPtr<SkSurface> surface = skia::AdoptRef( | 
| 688       SkSurface::NewRenderTargetDirect(backing_store->asRenderTarget())); | 688       SkSurface::NewRenderTargetDirect(backing_store->asRenderTarget())); | 
| 689   skia::RefPtr<SkCanvas> canvas = skia::SharePtr(surface->getCanvas()); | 689   skia::RefPtr<SkCanvas> canvas = skia::SharePtr(surface->getCanvas()); | 
| 690 | 690 | 
| 691   // Draw the source bitmap through the filter to the canvas. | 691   // Draw the source bitmap through the filter to the canvas. | 
| 692   SkPaint paint; | 692   SkPaint paint; | 
| 693   paint.setImageFilter(filter); | 693   paint.setImageFilter(filter); | 
| 694   canvas->clear(SK_ColorTRANSPARENT); | 694   canvas->clear(SK_ColorTRANSPARENT); | 
| 695 | 695 | 
| 696   canvas->translate(SkIntToScalar(-origin.x()), SkIntToScalar(-origin.y())); | 696   // The origin of the filter is top-left and the origin of the source is | 
|  | 697   // bottom-left, but the orientation is the same, so we must translate the | 
|  | 698   // filter so that it renders at the bottom of the texture to avoid | 
|  | 699   // misregistration. | 
|  | 700   int y_translate = source.height() - rect.height() - rect.origin().y(); | 
|  | 701   canvas->translate(-rect.origin().x(), y_translate); | 
| 697   canvas->scale(scale.x(), scale.y()); | 702   canvas->scale(scale.x(), scale.y()); | 
| 698   canvas->drawSprite(source, 0, 0, &paint); | 703   canvas->drawSprite(source, 0, 0, &paint); | 
| 699 | 704 | 
| 700   skia::RefPtr<SkImage> image = skia::AdoptRef(surface->newImageSnapshot()); | 705   skia::RefPtr<SkImage> image = skia::AdoptRef(surface->newImageSnapshot()); | 
| 701   if (!image || !image->getTexture()) { | 706   if (!image || !image->getTexture()) { | 
| 702     return skia::RefPtr<SkImage>(); | 707     return skia::RefPtr<SkImage>(); | 
| 703   } | 708   } | 
| 704 | 709 | 
| 705   // Flush the GrContext to ensure all buffered GL calls are drawn to the | 710   // Flush the GrContext to ensure all buffered GL calls are drawn to the | 
| 706   // backing store before we access and return it, and have cc begin using the | 711   // backing store before we access and return it, and have cc begin using the | 
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 851 } | 856 } | 
| 852 | 857 | 
| 853 skia::RefPtr<SkImage> GLRenderer::ApplyBackgroundFilters( | 858 skia::RefPtr<SkImage> GLRenderer::ApplyBackgroundFilters( | 
| 854     DrawingFrame* frame, | 859     DrawingFrame* frame, | 
| 855     const RenderPassDrawQuad* quad, | 860     const RenderPassDrawQuad* quad, | 
| 856     ScopedResource* background_texture) { | 861     ScopedResource* background_texture) { | 
| 857   DCHECK(ShouldApplyBackgroundFilters(frame, quad)); | 862   DCHECK(ShouldApplyBackgroundFilters(frame, quad)); | 
| 858   skia::RefPtr<SkImageFilter> filter = RenderSurfaceFilters::BuildImageFilter( | 863   skia::RefPtr<SkImageFilter> filter = RenderSurfaceFilters::BuildImageFilter( | 
| 859       quad->background_filters, background_texture->size()); | 864       quad->background_filters, background_texture->size()); | 
| 860 | 865 | 
| 861   skia::RefPtr<SkImage> background_with_filters = | 866   skia::RefPtr<SkImage> background_with_filters = ApplyImageFilter( | 
| 862       ApplyImageFilter(ScopedUseGrContext::Create(this, frame), | 867       ScopedUseGrContext::Create(this, frame), resource_provider_, quad->rect, | 
| 863                        resource_provider_, | 868       quad->filters_scale, filter.get(), background_texture); | 
| 864                        quad->rect.origin(), |  | 
| 865                        quad->filters_scale, |  | 
| 866                        filter.get(), |  | 
| 867                        background_texture); |  | 
| 868   return background_with_filters; | 869   return background_with_filters; | 
| 869 } | 870 } | 
| 870 | 871 | 
| 871 void GLRenderer::DrawRenderPassQuad(DrawingFrame* frame, | 872 void GLRenderer::DrawRenderPassQuad(DrawingFrame* frame, | 
| 872                                     const RenderPassDrawQuad* quad) { | 873                                     const RenderPassDrawQuad* quad) { | 
| 873   ScopedResource* contents_texture = | 874   ScopedResource* contents_texture = | 
| 874       render_pass_textures_.get(quad->render_pass_id); | 875       render_pass_textures_.get(quad->render_pass_id); | 
| 875   if (!contents_texture || !contents_texture->id()) | 876   if (!contents_texture || !contents_texture->id()) | 
| 876     return; | 877     return; | 
| 877 | 878 | 
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 963         SkColorFilter* colorfilter_rawptr = NULL; | 964         SkColorFilter* colorfilter_rawptr = NULL; | 
| 964         filter->asColorFilter(&colorfilter_rawptr); | 965         filter->asColorFilter(&colorfilter_rawptr); | 
| 965         cf = skia::AdoptRef(colorfilter_rawptr); | 966         cf = skia::AdoptRef(colorfilter_rawptr); | 
| 966       } | 967       } | 
| 967 | 968 | 
| 968       if (cf && cf->asColorMatrix(color_matrix) && !filter->getInput(0)) { | 969       if (cf && cf->asColorMatrix(color_matrix) && !filter->getInput(0)) { | 
| 969         // We have a single color matrix as a filter; apply it locally | 970         // We have a single color matrix as a filter; apply it locally | 
| 970         // in the compositor. | 971         // in the compositor. | 
| 971         use_color_matrix = true; | 972         use_color_matrix = true; | 
| 972       } else { | 973       } else { | 
| 973         filter_image = ApplyImageFilter(ScopedUseGrContext::Create(this, frame), | 974         filter_image = ApplyImageFilter( | 
| 974                                         resource_provider_, | 975             ScopedUseGrContext::Create(this, frame), resource_provider_, | 
| 975                                         quad->rect.origin(), | 976             quad->rect, quad->filters_scale, filter.get(), contents_texture); | 
| 976                                         quad->filters_scale, |  | 
| 977                                         filter.get(), |  | 
| 978                                         contents_texture); |  | 
| 979       } | 977       } | 
| 980     } | 978     } | 
| 981   } | 979   } | 
| 982 | 980 | 
| 983   scoped_ptr<ResourceProvider::ScopedSamplerGL> mask_resource_lock; | 981   scoped_ptr<ResourceProvider::ScopedSamplerGL> mask_resource_lock; | 
| 984   unsigned mask_texture_id = 0; | 982   unsigned mask_texture_id = 0; | 
| 985   SamplerType mask_sampler = SamplerTypeNA; | 983   SamplerType mask_sampler = SamplerTypeNA; | 
| 986   if (quad->mask_resource_id) { | 984   if (quad->mask_resource_id) { | 
| 987     mask_resource_lock.reset(new ResourceProvider::ScopedSamplerGL( | 985     mask_resource_lock.reset(new ResourceProvider::ScopedSamplerGL( | 
| 988         resource_provider_, quad->mask_resource_id, GL_TEXTURE1, GL_LINEAR)); | 986         resource_provider_, quad->mask_resource_id, GL_TEXTURE1, GL_LINEAR)); | 
| (...skipping 1715 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2704   } else { | 2702   } else { | 
| 2705     SetStencilEnabled(false); | 2703     SetStencilEnabled(false); | 
| 2706   } | 2704   } | 
| 2707 } | 2705 } | 
| 2708 | 2706 | 
| 2709 bool GLRenderer::BindFramebufferToTexture(DrawingFrame* frame, | 2707 bool GLRenderer::BindFramebufferToTexture(DrawingFrame* frame, | 
| 2710                                           const ScopedResource* texture, | 2708                                           const ScopedResource* texture, | 
| 2711                                           const gfx::Rect& target_rect) { | 2709                                           const gfx::Rect& target_rect) { | 
| 2712   DCHECK(texture->id()); | 2710   DCHECK(texture->id()); | 
| 2713 | 2711 | 
|  | 2712   // Explicitly release lock, otherwise we can crash when try to lock | 
|  | 2713   // same texture again. | 
| 2714   current_framebuffer_lock_ = nullptr; | 2714   current_framebuffer_lock_ = nullptr; | 
| 2715 | 2715 | 
| 2716   SetStencilEnabled(false); | 2716   SetStencilEnabled(false); | 
| 2717   GLC(gl_, gl_->BindFramebuffer(GL_FRAMEBUFFER, offscreen_framebuffer_id_)); | 2717   GLC(gl_, gl_->BindFramebuffer(GL_FRAMEBUFFER, offscreen_framebuffer_id_)); | 
| 2718   current_framebuffer_lock_ = | 2718   current_framebuffer_lock_ = | 
| 2719       make_scoped_ptr(new ResourceProvider::ScopedWriteLockGL( | 2719       make_scoped_ptr(new ResourceProvider::ScopedWriteLockGL( | 
| 2720           resource_provider_, texture->id())); | 2720           resource_provider_, texture->id())); | 
| 2721   unsigned texture_id = current_framebuffer_lock_->texture_id(); | 2721   unsigned texture_id = current_framebuffer_lock_->texture_id(); | 
| 2722   GLC(gl_, | 2722   GLC(gl_, | 
| 2723       gl_->FramebufferTexture2D( | 2723       gl_->FramebufferTexture2D( | 
| (...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 3305     context_support_->ScheduleOverlayPlane( | 3305     context_support_->ScheduleOverlayPlane( | 
| 3306         overlay.plane_z_order, | 3306         overlay.plane_z_order, | 
| 3307         overlay.transform, | 3307         overlay.transform, | 
| 3308         pending_overlay_resources_.back()->texture_id(), | 3308         pending_overlay_resources_.back()->texture_id(), | 
| 3309         overlay.display_rect, | 3309         overlay.display_rect, | 
| 3310         overlay.uv_rect); | 3310         overlay.uv_rect); | 
| 3311   } | 3311   } | 
| 3312 } | 3312 } | 
| 3313 | 3313 | 
| 3314 }  // namespace cc | 3314 }  // namespace cc | 
| OLD | NEW | 
|---|