| 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 case GL_TEXTURE_RECTANGLE_ARB: | 117 case GL_TEXTURE_RECTANGLE_ARB: |
| 118 return SamplerType2DRect; | 118 return SamplerType2DRect; |
| 119 case GL_TEXTURE_EXTERNAL_OES: | 119 case GL_TEXTURE_EXTERNAL_OES: |
| 120 return SamplerTypeExternalOES; | 120 return SamplerTypeExternalOES; |
| 121 default: | 121 default: |
| 122 NOTREACHED(); | 122 NOTREACHED(); |
| 123 return SamplerType2D; | 123 return SamplerType2D; |
| 124 } | 124 } |
| 125 } | 125 } |
| 126 | 126 |
| 127 BlendMode BlendModeFromSkXfermode(SkXfermode::Mode mode) { |
| 128 switch (mode) { |
| 129 case SkXfermode::kSrcOver_Mode: |
| 130 return BlendModeNormal; |
| 131 case SkXfermode::kOverlay_Mode: |
| 132 return BlendModeOverlay; |
| 133 case SkXfermode::kDarken_Mode: |
| 134 return BlendModeDarken; |
| 135 case SkXfermode::kLighten_Mode: |
| 136 return BlendModeLighten; |
| 137 case SkXfermode::kColorDodge_Mode: |
| 138 return BlendModeColorDodge; |
| 139 case SkXfermode::kColorBurn_Mode: |
| 140 return BlendModeColorBurn; |
| 141 case SkXfermode::kHardLight_Mode: |
| 142 return BlendModeHardLight; |
| 143 case SkXfermode::kSoftLight_Mode: |
| 144 return BlendModeSoftLight; |
| 145 case SkXfermode::kDifference_Mode: |
| 146 return BlendModeDifference; |
| 147 case SkXfermode::kExclusion_Mode: |
| 148 return BlendModeExclusion; |
| 149 case SkXfermode::kMultiply_Mode: |
| 150 return BlendModeMultiply; |
| 151 case SkXfermode::kHue_Mode: |
| 152 return BlendModeHue; |
| 153 case SkXfermode::kSaturation_Mode: |
| 154 return BlendModeSaturation; |
| 155 case SkXfermode::kColor_Mode: |
| 156 return BlendModeColor; |
| 157 case SkXfermode::kLuminosity_Mode: |
| 158 return BlendModeLuminosity; |
| 159 default: |
| 160 NOTREACHED(); |
| 161 return BlendModeNormal; |
| 162 } |
| 163 } |
| 164 |
| 127 // Smallest unit that impact anti-aliasing output. We use this to | 165 // Smallest unit that impact anti-aliasing output. We use this to |
| 128 // determine when anti-aliasing is unnecessary. | 166 // determine when anti-aliasing is unnecessary. |
| 129 const float kAntiAliasingEpsilon = 1.0f / 1024.0f; | 167 const float kAntiAliasingEpsilon = 1.0f / 1024.0f; |
| 130 | 168 |
| 131 // Block or crash if the number of pending sync queries reach this high as | 169 // Block or crash if the number of pending sync queries reach this high as |
| 132 // something is seriously wrong on the service side if this happens. | 170 // something is seriously wrong on the service side if this happens. |
| 133 const size_t kMaxPendingSyncQueries = 16; | 171 const size_t kMaxPendingSyncQueries = 16; |
| 134 | 172 |
| 135 } // anonymous namespace | 173 } // anonymous namespace |
| 136 | 174 |
| (...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 719 void GLRenderer::RestoreBlendFuncToDefault(SkXfermode::Mode blend_mode) { | 757 void GLRenderer::RestoreBlendFuncToDefault(SkXfermode::Mode blend_mode) { |
| 720 if (blend_mode == SkXfermode::kSrcOver_Mode) | 758 if (blend_mode == SkXfermode::kSrcOver_Mode) |
| 721 return; | 759 return; |
| 722 | 760 |
| 723 GLC(gl_, gl_->BlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); | 761 GLC(gl_, gl_->BlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); |
| 724 | 762 |
| 725 if (blend_mode == SkXfermode::kLighten_Mode) | 763 if (blend_mode == SkXfermode::kLighten_Mode) |
| 726 GLC(gl_, gl_->BlendEquation(GL_FUNC_ADD)); | 764 GLC(gl_, gl_->BlendEquation(GL_FUNC_ADD)); |
| 727 } | 765 } |
| 728 | 766 |
| 729 static skia::RefPtr<SkImage> ApplyBlendModeWithBackdrop( | |
| 730 scoped_ptr<GLRenderer::ScopedUseGrContext> use_gr_context, | |
| 731 ResourceProvider* resource_provider, | |
| 732 skia::RefPtr<SkImage> source_bitmap_with_filters, | |
| 733 ScopedResource* source_texture_resource, | |
| 734 ScopedResource* background_texture_resource, | |
| 735 SkXfermode::Mode blend_mode) { | |
| 736 if (!use_gr_context) | |
| 737 return source_bitmap_with_filters; | |
| 738 | |
| 739 DCHECK(background_texture_resource); | |
| 740 DCHECK(source_texture_resource); | |
| 741 | |
| 742 gfx::Size source_size = source_texture_resource->size(); | |
| 743 gfx::Size background_size = background_texture_resource->size(); | |
| 744 | |
| 745 DCHECK_LE(background_size.width(), source_size.width()); | |
| 746 DCHECK_LE(background_size.height(), source_size.height()); | |
| 747 | |
| 748 int source_texture_with_filters_id; | |
| 749 scoped_ptr<ResourceProvider::ScopedReadLockGL> lock; | |
| 750 if (source_bitmap_with_filters) { | |
| 751 DCHECK_EQ(source_size.width(), source_bitmap_with_filters->width()); | |
| 752 DCHECK_EQ(source_size.height(), source_bitmap_with_filters->height()); | |
| 753 GrTexture* texture = | |
| 754 reinterpret_cast<GrTexture*>(source_bitmap_with_filters->getTexture()); | |
| 755 source_texture_with_filters_id = texture->getTextureHandle(); | |
| 756 } else { | |
| 757 lock.reset(new ResourceProvider::ScopedReadLockGL( | |
| 758 resource_provider, source_texture_resource->id())); | |
| 759 source_texture_with_filters_id = lock->texture_id(); | |
| 760 } | |
| 761 | |
| 762 ResourceProvider::ScopedReadLockGL lock_background( | |
| 763 resource_provider, background_texture_resource->id()); | |
| 764 | |
| 765 // Wrap the source texture in a Ganesh platform texture. | |
| 766 GrBackendTextureDesc backend_texture_description; | |
| 767 backend_texture_description.fConfig = kSkia8888_GrPixelConfig; | |
| 768 backend_texture_description.fOrigin = kBottomLeft_GrSurfaceOrigin; | |
| 769 | |
| 770 backend_texture_description.fWidth = source_size.width(); | |
| 771 backend_texture_description.fHeight = source_size.height(); | |
| 772 backend_texture_description.fTextureHandle = source_texture_with_filters_id; | |
| 773 skia::RefPtr<GrTexture> source_texture = | |
| 774 skia::AdoptRef(use_gr_context->context()->wrapBackendTexture( | |
| 775 backend_texture_description)); | |
| 776 if (!source_texture) { | |
| 777 TRACE_EVENT_INSTANT0( | |
| 778 "cc", | |
| 779 "ApplyBlendModeWithBackdrop wrap source texture failed", | |
| 780 TRACE_EVENT_SCOPE_THREAD); | |
| 781 return skia::RefPtr<SkImage>(); | |
| 782 } | |
| 783 | |
| 784 backend_texture_description.fWidth = background_size.width(); | |
| 785 backend_texture_description.fHeight = background_size.height(); | |
| 786 backend_texture_description.fTextureHandle = lock_background.texture_id(); | |
| 787 skia::RefPtr<GrTexture> background_texture = | |
| 788 skia::AdoptRef(use_gr_context->context()->wrapBackendTexture( | |
| 789 backend_texture_description)); | |
| 790 if (!background_texture) { | |
| 791 TRACE_EVENT_INSTANT0( | |
| 792 "cc", | |
| 793 "ApplyBlendModeWithBackdrop wrap background texture failed", | |
| 794 TRACE_EVENT_SCOPE_THREAD); | |
| 795 return skia::RefPtr<SkImage>(); | |
| 796 } | |
| 797 | |
| 798 SkImageInfo source_info = | |
| 799 SkImageInfo::MakeN32Premul(source_size.width(), source_size.height()); | |
| 800 // Place the platform texture inside an SkBitmap. | |
| 801 SkBitmap source; | |
| 802 source.setInfo(source_info); | |
| 803 skia::RefPtr<SkGrPixelRef> source_pixel_ref = | |
| 804 skia::AdoptRef(new SkGrPixelRef(source_info, source_texture.get())); | |
| 805 source.setPixelRef(source_pixel_ref.get()); | |
| 806 | |
| 807 SkImageInfo background_info = SkImageInfo::MakeN32Premul( | |
| 808 background_size.width(), background_size.height()); | |
| 809 | |
| 810 SkBitmap background; | |
| 811 background.setInfo(background_info); | |
| 812 skia::RefPtr<SkGrPixelRef> background_pixel_ref = | |
| 813 skia::AdoptRef(new SkGrPixelRef( | |
| 814 background_info, background_texture.get())); | |
| 815 background.setPixelRef(background_pixel_ref.get()); | |
| 816 | |
| 817 // Create a scratch texture for backing store. | |
| 818 GrTextureDesc desc; | |
| 819 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; | |
| 820 desc.fSampleCnt = 0; | |
| 821 desc.fWidth = source.width(); | |
| 822 desc.fHeight = source.height(); | |
| 823 desc.fConfig = kSkia8888_GrPixelConfig; | |
| 824 desc.fOrigin = kBottomLeft_GrSurfaceOrigin; | |
| 825 skia::RefPtr<GrTexture> backing_store = | |
| 826 skia::AdoptRef(use_gr_context->context()->refScratchTexture( | |
| 827 desc, GrContext::kExact_ScratchTexMatch)); | |
| 828 if (!backing_store) { | |
| 829 TRACE_EVENT_INSTANT0( | |
| 830 "cc", | |
| 831 "ApplyBlendModeWithBackdrop scratch texture allocation failed", | |
| 832 TRACE_EVENT_SCOPE_THREAD); | |
| 833 return source_bitmap_with_filters; | |
| 834 } | |
| 835 | |
| 836 // Create a device and canvas using that backing store. | |
| 837 skia::RefPtr<SkSurface> surface = skia::AdoptRef( | |
| 838 SkSurface::NewRenderTargetDirect(backing_store->asRenderTarget())); | |
| 839 if (!surface) | |
| 840 return skia::RefPtr<SkImage>(); | |
| 841 skia::RefPtr<SkCanvas> canvas = skia::SharePtr(surface->getCanvas()); | |
| 842 | |
| 843 // Draw the source bitmap through the filter to the canvas. | |
| 844 canvas->clear(SK_ColorTRANSPARENT); | |
| 845 canvas->drawSprite(background, 0, 0); | |
| 846 SkPaint paint; | |
| 847 paint.setXfermodeMode(blend_mode); | |
| 848 canvas->drawSprite(source, 0, 0, &paint); | |
| 849 | |
| 850 skia::RefPtr<SkImage> image = skia::AdoptRef(surface->newImageSnapshot()); | |
| 851 if (!image || !image->getTexture()) { | |
| 852 return skia::RefPtr<SkImage>(); | |
| 853 } | |
| 854 | |
| 855 // Flush the GrContext to ensure all buffered GL calls are drawn to the | |
| 856 // backing store before we access and return it, and have cc begin using the | |
| 857 // GL context again. | |
| 858 canvas->flush(); | |
| 859 | |
| 860 return image; | |
| 861 } | |
| 862 | |
| 863 bool GLRenderer::ShouldApplyBackgroundFilters(DrawingFrame* frame, | 767 bool GLRenderer::ShouldApplyBackgroundFilters(DrawingFrame* frame, |
| 864 const RenderPassDrawQuad* quad) { | 768 const RenderPassDrawQuad* quad) { |
| 865 if (quad->background_filters.IsEmpty()) | 769 if (quad->background_filters.IsEmpty()) |
| 866 return false; | 770 return false; |
| 867 | 771 |
| 868 // TODO(danakj): We only allow background filters on an opaque render surface | 772 // TODO(danakj): We only allow background filters on an opaque render surface |
| 869 // because other surfaces may contain translucent pixels, and the contents | 773 // because other surfaces may contain translucent pixels, and the contents |
| 870 // behind those translucent pixels wouldn't have the filter applied. | 774 // behind those translucent pixels wouldn't have the filter applied. |
| 871 if (frame->current_render_pass->has_transparent_background) | 775 if (frame->current_render_pass->has_transparent_background) |
| 872 return false; | 776 return false; |
| 873 | 777 |
| 874 // TODO(ajuma): Add support for reference filters once | 778 // TODO(ajuma): Add support for reference filters once |
| 875 // FilterOperations::GetOutsets supports reference filters. | 779 // FilterOperations::GetOutsets supports reference filters. |
| 876 if (quad->background_filters.HasReferenceFilter()) | 780 if (quad->background_filters.HasReferenceFilter()) |
| 877 return false; | 781 return false; |
| 878 return true; | 782 return true; |
| 879 } | 783 } |
| 880 | 784 |
| 881 gfx::Rect GLRenderer::GetBackdropBoundingBoxForRenderPassQuad( | 785 gfx::Rect GLRenderer::GetBackdropBoundingBoxForRenderPassQuad( |
| 882 DrawingFrame* frame, | 786 DrawingFrame* frame, |
| 883 const RenderPassDrawQuad* quad, | 787 const RenderPassDrawQuad* quad, |
| 884 const gfx::Transform& contents_device_transform) { | 788 const gfx::Transform& contents_device_transform, |
| 789 bool use_aa) { |
| 885 gfx::Rect backdrop_rect = gfx::ToEnclosingRect(MathUtil::MapClippedRect( | 790 gfx::Rect backdrop_rect = gfx::ToEnclosingRect(MathUtil::MapClippedRect( |
| 886 contents_device_transform, SharedGeometryQuad().BoundingBox())); | 791 contents_device_transform, SharedGeometryQuad().BoundingBox())); |
| 887 | 792 |
| 888 if (ShouldApplyBackgroundFilters(frame, quad)) { | 793 if (ShouldApplyBackgroundFilters(frame, quad)) { |
| 889 int top, right, bottom, left; | 794 int top, right, bottom, left; |
| 890 quad->background_filters.GetOutsets(&top, &right, &bottom, &left); | 795 quad->background_filters.GetOutsets(&top, &right, &bottom, &left); |
| 891 backdrop_rect.Inset(-left, -top, -right, -bottom); | 796 backdrop_rect.Inset(-left, -top, -right, -bottom); |
| 892 } | 797 } |
| 893 | 798 |
| 799 if (!backdrop_rect.IsEmpty() && use_aa) { |
| 800 const int kOutsetForAntialiasing = 1; |
| 801 backdrop_rect.Inset(-kOutsetForAntialiasing, -kOutsetForAntialiasing); |
| 802 } |
| 803 |
| 894 backdrop_rect.Intersect( | 804 backdrop_rect.Intersect( |
| 895 MoveFromDrawToWindowSpace(frame->current_render_pass->output_rect)); | 805 MoveFromDrawToWindowSpace(frame->current_render_pass->output_rect)); |
| 896 return backdrop_rect; | 806 return backdrop_rect; |
| 897 } | 807 } |
| 898 | 808 |
| 899 scoped_ptr<ScopedResource> GLRenderer::GetBackdropTexture( | 809 scoped_ptr<ScopedResource> GLRenderer::GetBackdropTexture( |
| 900 const gfx::Rect& bounding_rect) { | 810 const gfx::Rect& bounding_rect) { |
| 901 scoped_ptr<ScopedResource> device_background_texture = | 811 scoped_ptr<ScopedResource> device_background_texture = |
| 902 ScopedResource::Create(resource_provider_); | 812 ScopedResource::Create(resource_provider_); |
| 903 // CopyTexImage2D fails when called on a texture having immutable storage. | 813 // CopyTexImage2D fails when called on a texture having immutable storage. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 928 filter.get(), | 838 filter.get(), |
| 929 background_texture); | 839 background_texture); |
| 930 return background_with_filters; | 840 return background_with_filters; |
| 931 } | 841 } |
| 932 | 842 |
| 933 scoped_ptr<ScopedResource> | 843 scoped_ptr<ScopedResource> |
| 934 GLRenderer::ApplyInverseTransformForBackgroundFilters( | 844 GLRenderer::ApplyInverseTransformForBackgroundFilters( |
| 935 DrawingFrame* frame, | 845 DrawingFrame* frame, |
| 936 const RenderPassDrawQuad* quad, | 846 const RenderPassDrawQuad* quad, |
| 937 const gfx::Transform& contents_device_transform_inverse, | 847 const gfx::Transform& contents_device_transform_inverse, |
| 938 ScopedResource* device_background_texture, | |
| 939 skia::RefPtr<SkImage> filtered_device_background, | 848 skia::RefPtr<SkImage> filtered_device_background, |
| 940 const gfx::Rect& backdrop_bounding_rect) { | 849 const gfx::Rect& backdrop_bounding_rect) { |
| 941 // This method draws a background filter, which applies a filter to any pixels | 850 // This method draws a background filter, which applies a filter to any pixels |
| 942 // behind the quad and seen through its background. The algorithm works as | 851 // behind the quad and seen through its background. The algorithm works as |
| 943 // follows: | 852 // follows: |
| 944 // 1. Read the pixels in the bounding box into a buffer. | 853 // 1. Read the pixels in the bounding box into a buffer. |
| 945 // Moved to GLRenderer::GetBackdropBoundingBoxForRenderPassQuad(). | 854 // Moved to GLRenderer::GetBackdropBoundingBoxForRenderPassQuad(). |
| 946 // 2. Read the pixels in the bounding box into a buffer R. | 855 // 2. Read the pixels in the bounding box into a buffer R. |
| 947 // Moved to GLRenderer::GetBackdropTexture(). | 856 // Moved to GLRenderer::GetBackdropTexture(). |
| 948 // 3. Apply the background filter to R, so that it is applied in the pixels' | 857 // 3. Apply the background filter to R, so that it is applied in the pixels' |
| 949 // coordinate space. Moved to GLRenderer::ApplyBackgroundFilters(). | 858 // coordinate space. Moved to GLRenderer::ApplyBackgroundFilters(). |
| 950 // 4. Apply the quad's inverse transform to map the pixels in R into the | 859 // 4. Apply the quad's inverse transform to map the pixels in R into the |
| 951 // quad's content space. This implicitly clips R by the content bounds of the | 860 // quad's content space. This implicitly clips R by the content bounds of the |
| 952 // quad since the destination texture has bounds matching the quad's content. | 861 // quad since the destination texture has bounds matching the quad's content. |
| 953 // 5. Draw the background texture for the contents using the same transform as | 862 // 5. Draw the background texture for the contents using the same transform as |
| 954 // used to draw the contents itself. This is done without blending to replace | 863 // used to draw the contents itself. This is done without blending to replace |
| 955 // the current background pixels with the new filtered background. | 864 // the current background pixels with the new filtered background. |
| 956 // 6. Draw the contents of the quad over drop of the new background with | 865 // 6. Draw the contents of the quad over drop of the new background with |
| 957 // blending, as per usual. The filtered background pixels will show through | 866 // blending, as per usual. The filtered background pixels will show through |
| 958 // any non-opaque pixels in this draws. | 867 // any non-opaque pixels in this draws. |
| 959 // | 868 // |
| 960 // Pixel copies in this algorithm occur at steps 2, 3, 4, and 5. | 869 // Pixel copies in this algorithm occur at steps 2, 3, 4, and 5. |
| 961 | 870 |
| 962 // TODO(danakj): When this algorithm changes, update | 871 // TODO(danakj): When this algorithm changes, update |
| 963 // LayerTreeHost::PrioritizeTextures() accordingly. | 872 // LayerTreeHost::PrioritizeTextures() accordingly. |
| 964 | 873 |
| 965 DCHECK(device_background_texture); | 874 DCHECK(filtered_device_background); |
| 966 | 875 |
| 967 int filtered_device_background_texture_id = 0; | 876 GrTexture* texture = filtered_device_background->getTexture(); |
| 968 scoped_ptr<ResourceProvider::ScopedReadLockGL> lock; | |
| 969 if (filtered_device_background) { | |
| 970 GrTexture* texture = filtered_device_background->getTexture(); | |
| 971 filtered_device_background_texture_id = texture->getTextureHandle(); | |
| 972 } else { | |
| 973 lock.reset(new ResourceProvider::ScopedReadLockGL( | |
| 974 resource_provider_, device_background_texture->id())); | |
| 975 filtered_device_background_texture_id = lock->texture_id(); | |
| 976 } | |
| 977 | 877 |
| 978 scoped_ptr<ScopedResource> background_texture = | 878 scoped_ptr<ScopedResource> background_texture = |
| 979 ScopedResource::Create(resource_provider_); | 879 ScopedResource::Create(resource_provider_); |
| 980 background_texture->Allocate( | 880 background_texture->Allocate( |
| 981 quad->rect.size(), | 881 quad->rect.size(), |
| 982 ResourceProvider::TextureHintImmutableFramebuffer, | 882 ResourceProvider::TextureHintImmutableFramebuffer, |
| 983 RGBA_8888); | 883 RGBA_8888); |
| 984 | 884 |
| 985 const RenderPass* target_render_pass = frame->current_render_pass; | 885 const RenderPass* target_render_pass = frame->current_render_pass; |
| 986 bool using_background_texture = | 886 bool using_background_texture = |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1000 gl_->Clear(GL_COLOR_BUFFER_BIT); | 900 gl_->Clear(GL_COLOR_BUFFER_BIT); |
| 1001 #endif | 901 #endif |
| 1002 | 902 |
| 1003 // The background_texture is oriented the same as the frame buffer. | 903 // The background_texture is oriented the same as the frame buffer. |
| 1004 // The transform we are copying with has a vertical flip, as well as | 904 // The transform we are copying with has a vertical flip, as well as |
| 1005 // the |device_to_framebuffer_transform|, which cancel each other out. So do | 905 // the |device_to_framebuffer_transform|, which cancel each other out. So do |
| 1006 // not flip the contents in the shader to maintain orientation. | 906 // not flip the contents in the shader to maintain orientation. |
| 1007 bool flip_vertically = false; | 907 bool flip_vertically = false; |
| 1008 | 908 |
| 1009 CopyTextureToFramebuffer(frame, | 909 CopyTextureToFramebuffer(frame, |
| 1010 filtered_device_background_texture_id, | 910 texture->getTextureHandle(), |
| 1011 backdrop_bounding_rect, | 911 backdrop_bounding_rect, |
| 1012 device_to_framebuffer_transform, | 912 device_to_framebuffer_transform, |
| 1013 flip_vertically); | 913 flip_vertically); |
| 1014 } | 914 } |
| 1015 | 915 |
| 1016 UseRenderPass(frame, target_render_pass); | 916 UseRenderPass(frame, target_render_pass); |
| 1017 | 917 |
| 1018 if (!using_background_texture) | 918 if (!using_background_texture) |
| 1019 return nullptr; | 919 return nullptr; |
| 1020 return background_texture.Pass(); | 920 return background_texture.Pass(); |
| 1021 } | 921 } |
| 1022 | 922 |
| 1023 void GLRenderer::DrawRenderPassQuad(DrawingFrame* frame, | 923 void GLRenderer::DrawRenderPassQuad(DrawingFrame* frame, |
| 1024 const RenderPassDrawQuad* quad) { | 924 const RenderPassDrawQuad* quad) { |
| 1025 SkXfermode::Mode blend_mode = quad->shared_quad_state->blend_mode; | 925 SkXfermode::Mode blend_mode = quad->shared_quad_state->blend_mode; |
| 1026 SetBlendEnabled(quad->ShouldDrawWithBlending() || | 926 SetBlendEnabled( |
| 1027 (!IsDefaultBlendMode(blend_mode) && | 927 CanApplyBlendModeUsingBlendFunc(blend_mode) && |
| 1028 CanApplyBlendModeUsingBlendFunc(blend_mode))); | 928 (quad->ShouldDrawWithBlending() || !IsDefaultBlendMode(blend_mode))); |
| 1029 | 929 |
| 1030 ScopedResource* contents_texture = | 930 ScopedResource* contents_texture = |
| 1031 render_pass_textures_.get(quad->render_pass_id); | 931 render_pass_textures_.get(quad->render_pass_id); |
| 1032 if (!contents_texture || !contents_texture->id()) | 932 if (!contents_texture || !contents_texture->id()) |
| 1033 return; | 933 return; |
| 1034 | 934 |
| 1035 gfx::Transform quad_rect_matrix; | 935 gfx::Transform quad_rect_matrix; |
| 1036 QuadRectTransform(&quad_rect_matrix, quad->quadTransform(), quad->rect); | 936 QuadRectTransform(&quad_rect_matrix, quad->quadTransform(), quad->rect); |
| 1037 gfx::Transform contents_device_transform = | 937 gfx::Transform contents_device_transform = |
| 1038 frame->window_matrix * frame->projection_matrix * quad_rect_matrix; | 938 frame->window_matrix * frame->projection_matrix * quad_rect_matrix; |
| 1039 contents_device_transform.FlattenTo2d(); | 939 contents_device_transform.FlattenTo2d(); |
| 1040 | 940 |
| 1041 // Can only draw surface if device matrix is invertible. | 941 // Can only draw surface if device matrix is invertible. |
| 1042 gfx::Transform contents_device_transform_inverse( | 942 gfx::Transform contents_device_transform_inverse( |
| 1043 gfx::Transform::kSkipInitialization); | 943 gfx::Transform::kSkipInitialization); |
| 1044 if (!contents_device_transform.GetInverse(&contents_device_transform_inverse)) | 944 if (!contents_device_transform.GetInverse(&contents_device_transform_inverse)) |
| 1045 return; | 945 return; |
| 1046 | 946 |
| 947 bool clipped = false; |
| 948 gfx::QuadF device_quad = MathUtil::MapQuad( |
| 949 contents_device_transform, SharedGeometryQuad(), &clipped); |
| 950 // Use anti-aliasing programs only when necessary. |
| 951 bool use_aa = |
| 952 !clipped && |
| 953 (settings_->force_antialiasing || !device_quad.IsRectilinear() || |
| 954 !gfx::IsNearestRectWithinDistance(device_quad.BoundingBox(), |
| 955 kAntiAliasingEpsilon)); |
| 956 |
| 1047 bool need_background_texture = !CanApplyBlendModeUsingBlendFunc(blend_mode) || | 957 bool need_background_texture = !CanApplyBlendModeUsingBlendFunc(blend_mode) || |
| 1048 ShouldApplyBackgroundFilters(frame, quad); | 958 ShouldApplyBackgroundFilters(frame, quad); |
| 1049 | 959 |
| 1050 scoped_ptr<ScopedResource> background_texture; | 960 scoped_ptr<ScopedResource> background_texture; |
| 961 skia::RefPtr<SkImage> background_image; |
| 962 gfx::Rect background_rect; |
| 1051 if (need_background_texture) { | 963 if (need_background_texture) { |
| 964 // Compute a bounding box around the pixels that will be visible through |
| 965 // the quad. |
| 966 background_rect = GetBackdropBoundingBoxForRenderPassQuad( |
| 967 frame, quad, contents_device_transform, use_aa); |
| 968 } |
| 969 |
| 970 if (!background_rect.IsEmpty()) { |
| 1052 // The pixels from the filtered background should completely replace the | 971 // The pixels from the filtered background should completely replace the |
| 1053 // current pixel values. | 972 // current pixel values. |
| 1054 bool disable_blending = blend_enabled(); | 973 bool disable_blending = blend_enabled(); |
| 1055 if (disable_blending) | 974 if (disable_blending) |
| 1056 SetBlendEnabled(false); | 975 SetBlendEnabled(false); |
| 1057 | 976 |
| 1058 // Compute a bounding box around the pixels that will be visible through | |
| 1059 // the quad. | |
| 1060 gfx::Rect backdrop_rect = GetBackdropBoundingBoxForRenderPassQuad( | |
| 1061 frame, quad, contents_device_transform); | |
| 1062 | |
| 1063 // Read the pixels in the bounding box into a buffer R. | 977 // Read the pixels in the bounding box into a buffer R. |
| 1064 scoped_ptr<ScopedResource> scoped_background_texture = | 978 scoped_ptr<ScopedResource> scoped_background_texture = |
| 1065 GetBackdropTexture(backdrop_rect); | 979 GetBackdropTexture(background_rect); |
| 1066 | 980 |
| 1067 skia::RefPtr<SkImage> background_with_filters; | 981 skia::RefPtr<SkImage> background_with_filters; |
| 1068 if (ShouldApplyBackgroundFilters(frame, quad)) { | 982 if (ShouldApplyBackgroundFilters(frame, quad) && |
| 983 scoped_background_texture) { |
| 1069 // Apply the background filters to R, so that it is applied in the pixels' | 984 // Apply the background filters to R, so that it is applied in the pixels' |
| 1070 // coordinate space. | 985 // coordinate space. |
| 1071 background_with_filters = | 986 background_with_filters = |
| 1072 ApplyBackgroundFilters(frame, quad, scoped_background_texture.get()); | 987 ApplyBackgroundFilters(frame, quad, scoped_background_texture.get()); |
| 1073 } | 988 } |
| 1074 // Apply the quad's inverse transform to map the pixels in R into the | 989 |
| 1075 // quad's content space. This implicitly clips R by the content bounds of | 990 if (CanApplyBlendModeUsingBlendFunc(blend_mode) && |
| 1076 // the quad since the destination texture has bounds matching the quad's | 991 background_with_filters) { |
| 1077 // content. | 992 // The background with filters will be copied to the frame buffer. |
| 1078 background_texture = ApplyInverseTransformForBackgroundFilters( | 993 // Apply the quad's inverse transform to map the pixels in R into the |
| 1079 frame, | 994 // quad's content space. This implicitly clips R by the content bounds of |
| 1080 quad, | 995 // the quad since the destination texture has bounds matching the quad's |
| 1081 contents_device_transform_inverse, | 996 // content. |
| 1082 scoped_background_texture.get(), | 997 background_texture = ApplyInverseTransformForBackgroundFilters( |
| 1083 background_with_filters, | 998 frame, |
| 1084 backdrop_rect); | 999 quad, |
| 1000 contents_device_transform_inverse, |
| 1001 background_with_filters, |
| 1002 background_rect); |
| 1003 } else if (!CanApplyBlendModeUsingBlendFunc(blend_mode)) { |
| 1004 if (background_with_filters) { |
| 1005 // The background with filters will be used as backdrop for blending. |
| 1006 background_image = background_with_filters; |
| 1007 } else { |
| 1008 background_texture = scoped_background_texture.Pass(); |
| 1009 } |
| 1010 } |
| 1085 | 1011 |
| 1086 if (disable_blending) | 1012 if (disable_blending) |
| 1087 SetBlendEnabled(true); | 1013 SetBlendEnabled(true); |
| 1088 } | 1014 } |
| 1089 | 1015 |
| 1090 // TODO(senorblanco): Cache this value so that we don't have to do it for both | 1016 // TODO(senorblanco): Cache this value so that we don't have to do it for both |
| 1091 // the surface and its replica. Apply filters to the contents texture. | 1017 // the surface and its replica. Apply filters to the contents texture. |
| 1092 skia::RefPtr<SkImage> filter_image; | 1018 skia::RefPtr<SkImage> filter_image; |
| 1093 SkScalar color_matrix[20]; | 1019 SkScalar color_matrix[20]; |
| 1094 bool use_color_matrix = false; | 1020 bool use_color_matrix = false; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1112 filter_image = ApplyImageFilter(ScopedUseGrContext::Create(this, frame), | 1038 filter_image = ApplyImageFilter(ScopedUseGrContext::Create(this, frame), |
| 1113 resource_provider_, | 1039 resource_provider_, |
| 1114 quad->rect.origin(), | 1040 quad->rect.origin(), |
| 1115 quad->filters_scale, | 1041 quad->filters_scale, |
| 1116 filter.get(), | 1042 filter.get(), |
| 1117 contents_texture); | 1043 contents_texture); |
| 1118 } | 1044 } |
| 1119 } | 1045 } |
| 1120 } | 1046 } |
| 1121 | 1047 |
| 1122 if (background_texture) { | 1048 if (background_texture && ShouldApplyBackgroundFilters(frame, quad)) { |
| 1123 if (CanApplyBlendModeUsingBlendFunc(blend_mode)) { | 1049 // Draw the background texture if it has some filters applied. |
| 1124 // Draw the background texture if it has some filters applied. | 1050 DCHECK(CanApplyBlendModeUsingBlendFunc(blend_mode)); |
| 1125 DCHECK(ShouldApplyBackgroundFilters(frame, quad)); | 1051 DCHECK(background_texture->size() == quad->rect.size()); |
| 1126 DCHECK(background_texture->size() == quad->rect.size()); | 1052 ResourceProvider::ScopedReadLockGL lock(resource_provider_, |
| 1127 ResourceProvider::ScopedReadLockGL lock(resource_provider_, | 1053 background_texture->id()); |
| 1128 background_texture->id()); | |
| 1129 | 1054 |
| 1130 // The background_texture is oriented the same as the frame buffer. The | 1055 // The background_texture is oriented the same as the frame buffer. The |
| 1131 // transform we are copying with has a vertical flip, so flip the contents | 1056 // transform we are copying with has a vertical flip, so flip the contents |
| 1132 // in the shader to maintain orientation | 1057 // in the shader to maintain orientation |
| 1133 bool flip_vertically = true; | 1058 bool flip_vertically = true; |
| 1134 | 1059 |
| 1135 CopyTextureToFramebuffer(frame, | 1060 CopyTextureToFramebuffer(frame, |
| 1136 lock.texture_id(), | 1061 lock.texture_id(), |
| 1137 quad->rect, | 1062 quad->rect, |
| 1138 quad->quadTransform(), | 1063 quad->quadTransform(), |
| 1139 flip_vertically); | 1064 flip_vertically); |
| 1140 } else { | |
| 1141 // If blending is applied using shaders, the background texture with | |
| 1142 // filters will be used as backdrop for blending operation, so we don't | |
| 1143 // need to copy it to the frame buffer. | |
| 1144 filter_image = | |
| 1145 ApplyBlendModeWithBackdrop(ScopedUseGrContext::Create(this, frame), | |
| 1146 resource_provider_, | |
| 1147 filter_image, | |
| 1148 contents_texture, | |
| 1149 background_texture.get(), | |
| 1150 quad->shared_quad_state->blend_mode); | |
| 1151 } | |
| 1152 } | 1065 } |
| 1153 | 1066 |
| 1154 bool clipped = false; | |
| 1155 gfx::QuadF device_quad = MathUtil::MapQuad( | |
| 1156 contents_device_transform, SharedGeometryQuad(), &clipped); | |
| 1157 LayerQuad device_layer_bounds(gfx::QuadF(device_quad.BoundingBox())); | 1067 LayerQuad device_layer_bounds(gfx::QuadF(device_quad.BoundingBox())); |
| 1158 LayerQuad device_layer_edges(device_quad); | 1068 LayerQuad device_layer_edges(device_quad); |
| 1159 | |
| 1160 // Use anti-aliasing programs only when necessary. | |
| 1161 bool use_aa = | |
| 1162 !clipped && (!device_quad.IsRectilinear() || | |
| 1163 !gfx::IsNearestRectWithinDistance(device_quad.BoundingBox(), | |
| 1164 kAntiAliasingEpsilon)); | |
| 1165 if (use_aa) { | 1069 if (use_aa) { |
| 1166 device_layer_bounds.InflateAntiAliasingDistance(); | 1070 device_layer_bounds.InflateAntiAliasingDistance(); |
| 1167 device_layer_edges.InflateAntiAliasingDistance(); | 1071 device_layer_edges.InflateAntiAliasingDistance(); |
| 1168 } | 1072 } |
| 1169 | 1073 |
| 1170 scoped_ptr<ResourceProvider::ScopedSamplerGL> mask_resource_lock; | 1074 scoped_ptr<ResourceProvider::ScopedSamplerGL> mask_resource_lock; |
| 1171 unsigned mask_texture_id = 0; | 1075 unsigned mask_texture_id = 0; |
| 1172 SamplerType mask_sampler = SamplerTypeNA; | 1076 SamplerType mask_sampler = SamplerTypeNA; |
| 1173 if (quad->mask_resource_id) { | 1077 if (quad->mask_resource_id) { |
| 1174 mask_resource_lock.reset(new ResourceProvider::ScopedSamplerGL( | 1078 mask_resource_lock.reset(new ResourceProvider::ScopedSamplerGL( |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1206 int shader_edge_location = -1; | 1110 int shader_edge_location = -1; |
| 1207 int shader_viewport_location = -1; | 1111 int shader_viewport_location = -1; |
| 1208 int shader_mask_sampler_location = -1; | 1112 int shader_mask_sampler_location = -1; |
| 1209 int shader_mask_tex_coord_scale_location = -1; | 1113 int shader_mask_tex_coord_scale_location = -1; |
| 1210 int shader_mask_tex_coord_offset_location = -1; | 1114 int shader_mask_tex_coord_offset_location = -1; |
| 1211 int shader_matrix_location = -1; | 1115 int shader_matrix_location = -1; |
| 1212 int shader_alpha_location = -1; | 1116 int shader_alpha_location = -1; |
| 1213 int shader_color_matrix_location = -1; | 1117 int shader_color_matrix_location = -1; |
| 1214 int shader_color_offset_location = -1; | 1118 int shader_color_offset_location = -1; |
| 1215 int shader_tex_transform_location = -1; | 1119 int shader_tex_transform_location = -1; |
| 1120 int shader_backdrop_location = -1; |
| 1121 int shader_backdrop_rect_location = -1; |
| 1122 |
| 1123 BlendMode shader_blend_mode = ((background_texture || background_image) && |
| 1124 !CanApplyBlendModeUsingBlendFunc(blend_mode)) |
| 1125 ? BlendModeFromSkXfermode(blend_mode) |
| 1126 : BlendModeNormal; |
| 1216 | 1127 |
| 1217 if (use_aa && mask_texture_id && !use_color_matrix) { | 1128 if (use_aa && mask_texture_id && !use_color_matrix) { |
| 1218 const RenderPassMaskProgramAA* program = | 1129 const RenderPassMaskProgramAA* program = |
| 1219 GetRenderPassMaskProgramAA(tex_coord_precision); | 1130 GetRenderPassMaskProgramAA(tex_coord_precision, shader_blend_mode); |
| 1220 SetUseProgram(program->program()); | 1131 SetUseProgram(program->program()); |
| 1221 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0)); | 1132 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0)); |
| 1222 | 1133 |
| 1223 shader_quad_location = program->vertex_shader().quad_location(); | 1134 shader_quad_location = program->vertex_shader().quad_location(); |
| 1224 shader_edge_location = program->vertex_shader().edge_location(); | 1135 shader_edge_location = program->vertex_shader().edge_location(); |
| 1225 shader_viewport_location = program->vertex_shader().viewport_location(); | 1136 shader_viewport_location = program->vertex_shader().viewport_location(); |
| 1226 shader_mask_sampler_location = | 1137 shader_mask_sampler_location = |
| 1227 program->fragment_shader().mask_sampler_location(); | 1138 program->fragment_shader().mask_sampler_location(); |
| 1228 shader_mask_tex_coord_scale_location = | 1139 shader_mask_tex_coord_scale_location = |
| 1229 program->fragment_shader().mask_tex_coord_scale_location(); | 1140 program->fragment_shader().mask_tex_coord_scale_location(); |
| 1230 shader_mask_tex_coord_offset_location = | 1141 shader_mask_tex_coord_offset_location = |
| 1231 program->fragment_shader().mask_tex_coord_offset_location(); | 1142 program->fragment_shader().mask_tex_coord_offset_location(); |
| 1232 shader_matrix_location = program->vertex_shader().matrix_location(); | 1143 shader_matrix_location = program->vertex_shader().matrix_location(); |
| 1233 shader_alpha_location = program->fragment_shader().alpha_location(); | 1144 shader_alpha_location = program->fragment_shader().alpha_location(); |
| 1234 shader_tex_transform_location = | 1145 shader_tex_transform_location = |
| 1235 program->vertex_shader().tex_transform_location(); | 1146 program->vertex_shader().tex_transform_location(); |
| 1147 shader_backdrop_location = program->fragment_shader().backdrop_location(); |
| 1148 shader_backdrop_rect_location = |
| 1149 program->fragment_shader().backdrop_rect_location(); |
| 1236 } else if (!use_aa && mask_texture_id && !use_color_matrix) { | 1150 } else if (!use_aa && mask_texture_id && !use_color_matrix) { |
| 1237 const RenderPassMaskProgram* program = | 1151 const RenderPassMaskProgram* program = |
| 1238 GetRenderPassMaskProgram(tex_coord_precision); | 1152 GetRenderPassMaskProgram(tex_coord_precision, shader_blend_mode); |
| 1239 SetUseProgram(program->program()); | 1153 SetUseProgram(program->program()); |
| 1240 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0)); | 1154 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0)); |
| 1241 | 1155 |
| 1242 shader_mask_sampler_location = | 1156 shader_mask_sampler_location = |
| 1243 program->fragment_shader().mask_sampler_location(); | 1157 program->fragment_shader().mask_sampler_location(); |
| 1244 shader_mask_tex_coord_scale_location = | 1158 shader_mask_tex_coord_scale_location = |
| 1245 program->fragment_shader().mask_tex_coord_scale_location(); | 1159 program->fragment_shader().mask_tex_coord_scale_location(); |
| 1246 shader_mask_tex_coord_offset_location = | 1160 shader_mask_tex_coord_offset_location = |
| 1247 program->fragment_shader().mask_tex_coord_offset_location(); | 1161 program->fragment_shader().mask_tex_coord_offset_location(); |
| 1248 shader_matrix_location = program->vertex_shader().matrix_location(); | 1162 shader_matrix_location = program->vertex_shader().matrix_location(); |
| 1249 shader_alpha_location = program->fragment_shader().alpha_location(); | 1163 shader_alpha_location = program->fragment_shader().alpha_location(); |
| 1250 shader_tex_transform_location = | 1164 shader_tex_transform_location = |
| 1251 program->vertex_shader().tex_transform_location(); | 1165 program->vertex_shader().tex_transform_location(); |
| 1166 shader_backdrop_location = program->fragment_shader().backdrop_location(); |
| 1167 shader_backdrop_rect_location = |
| 1168 program->fragment_shader().backdrop_rect_location(); |
| 1252 } else if (use_aa && !mask_texture_id && !use_color_matrix) { | 1169 } else if (use_aa && !mask_texture_id && !use_color_matrix) { |
| 1253 const RenderPassProgramAA* program = | 1170 const RenderPassProgramAA* program = |
| 1254 GetRenderPassProgramAA(tex_coord_precision); | 1171 GetRenderPassProgramAA(tex_coord_precision, shader_blend_mode); |
| 1255 SetUseProgram(program->program()); | 1172 SetUseProgram(program->program()); |
| 1256 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0)); | 1173 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0)); |
| 1257 | 1174 |
| 1258 shader_quad_location = program->vertex_shader().quad_location(); | 1175 shader_quad_location = program->vertex_shader().quad_location(); |
| 1259 shader_edge_location = program->vertex_shader().edge_location(); | 1176 shader_edge_location = program->vertex_shader().edge_location(); |
| 1260 shader_viewport_location = program->vertex_shader().viewport_location(); | 1177 shader_viewport_location = program->vertex_shader().viewport_location(); |
| 1261 shader_matrix_location = program->vertex_shader().matrix_location(); | 1178 shader_matrix_location = program->vertex_shader().matrix_location(); |
| 1262 shader_alpha_location = program->fragment_shader().alpha_location(); | 1179 shader_alpha_location = program->fragment_shader().alpha_location(); |
| 1263 shader_tex_transform_location = | 1180 shader_tex_transform_location = |
| 1264 program->vertex_shader().tex_transform_location(); | 1181 program->vertex_shader().tex_transform_location(); |
| 1182 shader_backdrop_location = program->fragment_shader().backdrop_location(); |
| 1183 shader_backdrop_rect_location = |
| 1184 program->fragment_shader().backdrop_rect_location(); |
| 1265 } else if (use_aa && mask_texture_id && use_color_matrix) { | 1185 } else if (use_aa && mask_texture_id && use_color_matrix) { |
| 1266 const RenderPassMaskColorMatrixProgramAA* program = | 1186 const RenderPassMaskColorMatrixProgramAA* program = |
| 1267 GetRenderPassMaskColorMatrixProgramAA(tex_coord_precision); | 1187 GetRenderPassMaskColorMatrixProgramAA(tex_coord_precision, |
| 1188 shader_blend_mode); |
| 1268 SetUseProgram(program->program()); | 1189 SetUseProgram(program->program()); |
| 1269 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0)); | 1190 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0)); |
| 1270 | 1191 |
| 1271 shader_matrix_location = program->vertex_shader().matrix_location(); | 1192 shader_matrix_location = program->vertex_shader().matrix_location(); |
| 1272 shader_quad_location = program->vertex_shader().quad_location(); | 1193 shader_quad_location = program->vertex_shader().quad_location(); |
| 1273 shader_tex_transform_location = | 1194 shader_tex_transform_location = |
| 1274 program->vertex_shader().tex_transform_location(); | 1195 program->vertex_shader().tex_transform_location(); |
| 1275 shader_edge_location = program->vertex_shader().edge_location(); | 1196 shader_edge_location = program->vertex_shader().edge_location(); |
| 1276 shader_viewport_location = program->vertex_shader().viewport_location(); | 1197 shader_viewport_location = program->vertex_shader().viewport_location(); |
| 1277 shader_alpha_location = program->fragment_shader().alpha_location(); | 1198 shader_alpha_location = program->fragment_shader().alpha_location(); |
| 1278 shader_mask_sampler_location = | 1199 shader_mask_sampler_location = |
| 1279 program->fragment_shader().mask_sampler_location(); | 1200 program->fragment_shader().mask_sampler_location(); |
| 1280 shader_mask_tex_coord_scale_location = | 1201 shader_mask_tex_coord_scale_location = |
| 1281 program->fragment_shader().mask_tex_coord_scale_location(); | 1202 program->fragment_shader().mask_tex_coord_scale_location(); |
| 1282 shader_mask_tex_coord_offset_location = | 1203 shader_mask_tex_coord_offset_location = |
| 1283 program->fragment_shader().mask_tex_coord_offset_location(); | 1204 program->fragment_shader().mask_tex_coord_offset_location(); |
| 1284 shader_color_matrix_location = | 1205 shader_color_matrix_location = |
| 1285 program->fragment_shader().color_matrix_location(); | 1206 program->fragment_shader().color_matrix_location(); |
| 1286 shader_color_offset_location = | 1207 shader_color_offset_location = |
| 1287 program->fragment_shader().color_offset_location(); | 1208 program->fragment_shader().color_offset_location(); |
| 1209 shader_backdrop_location = program->fragment_shader().backdrop_location(); |
| 1210 shader_backdrop_rect_location = |
| 1211 program->fragment_shader().backdrop_rect_location(); |
| 1288 } else if (use_aa && !mask_texture_id && use_color_matrix) { | 1212 } else if (use_aa && !mask_texture_id && use_color_matrix) { |
| 1289 const RenderPassColorMatrixProgramAA* program = | 1213 const RenderPassColorMatrixProgramAA* program = |
| 1290 GetRenderPassColorMatrixProgramAA(tex_coord_precision); | 1214 GetRenderPassColorMatrixProgramAA(tex_coord_precision, |
| 1215 shader_blend_mode); |
| 1291 SetUseProgram(program->program()); | 1216 SetUseProgram(program->program()); |
| 1292 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0)); | 1217 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0)); |
| 1293 | 1218 |
| 1294 shader_matrix_location = program->vertex_shader().matrix_location(); | 1219 shader_matrix_location = program->vertex_shader().matrix_location(); |
| 1295 shader_quad_location = program->vertex_shader().quad_location(); | 1220 shader_quad_location = program->vertex_shader().quad_location(); |
| 1296 shader_tex_transform_location = | 1221 shader_tex_transform_location = |
| 1297 program->vertex_shader().tex_transform_location(); | 1222 program->vertex_shader().tex_transform_location(); |
| 1298 shader_edge_location = program->vertex_shader().edge_location(); | 1223 shader_edge_location = program->vertex_shader().edge_location(); |
| 1299 shader_viewport_location = program->vertex_shader().viewport_location(); | 1224 shader_viewport_location = program->vertex_shader().viewport_location(); |
| 1300 shader_alpha_location = program->fragment_shader().alpha_location(); | 1225 shader_alpha_location = program->fragment_shader().alpha_location(); |
| 1301 shader_color_matrix_location = | 1226 shader_color_matrix_location = |
| 1302 program->fragment_shader().color_matrix_location(); | 1227 program->fragment_shader().color_matrix_location(); |
| 1303 shader_color_offset_location = | 1228 shader_color_offset_location = |
| 1304 program->fragment_shader().color_offset_location(); | 1229 program->fragment_shader().color_offset_location(); |
| 1230 shader_backdrop_location = program->fragment_shader().backdrop_location(); |
| 1231 shader_backdrop_rect_location = |
| 1232 program->fragment_shader().backdrop_rect_location(); |
| 1305 } else if (!use_aa && mask_texture_id && use_color_matrix) { | 1233 } else if (!use_aa && mask_texture_id && use_color_matrix) { |
| 1306 const RenderPassMaskColorMatrixProgram* program = | 1234 const RenderPassMaskColorMatrixProgram* program = |
| 1307 GetRenderPassMaskColorMatrixProgram(tex_coord_precision); | 1235 GetRenderPassMaskColorMatrixProgram(tex_coord_precision, |
| 1236 shader_blend_mode); |
| 1308 SetUseProgram(program->program()); | 1237 SetUseProgram(program->program()); |
| 1309 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0)); | 1238 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0)); |
| 1310 | 1239 |
| 1311 shader_matrix_location = program->vertex_shader().matrix_location(); | 1240 shader_matrix_location = program->vertex_shader().matrix_location(); |
| 1312 shader_tex_transform_location = | 1241 shader_tex_transform_location = |
| 1313 program->vertex_shader().tex_transform_location(); | 1242 program->vertex_shader().tex_transform_location(); |
| 1314 shader_mask_sampler_location = | 1243 shader_mask_sampler_location = |
| 1315 program->fragment_shader().mask_sampler_location(); | 1244 program->fragment_shader().mask_sampler_location(); |
| 1316 shader_mask_tex_coord_scale_location = | 1245 shader_mask_tex_coord_scale_location = |
| 1317 program->fragment_shader().mask_tex_coord_scale_location(); | 1246 program->fragment_shader().mask_tex_coord_scale_location(); |
| 1318 shader_mask_tex_coord_offset_location = | 1247 shader_mask_tex_coord_offset_location = |
| 1319 program->fragment_shader().mask_tex_coord_offset_location(); | 1248 program->fragment_shader().mask_tex_coord_offset_location(); |
| 1320 shader_alpha_location = program->fragment_shader().alpha_location(); | 1249 shader_alpha_location = program->fragment_shader().alpha_location(); |
| 1321 shader_color_matrix_location = | 1250 shader_color_matrix_location = |
| 1322 program->fragment_shader().color_matrix_location(); | 1251 program->fragment_shader().color_matrix_location(); |
| 1323 shader_color_offset_location = | 1252 shader_color_offset_location = |
| 1324 program->fragment_shader().color_offset_location(); | 1253 program->fragment_shader().color_offset_location(); |
| 1254 shader_backdrop_location = program->fragment_shader().backdrop_location(); |
| 1255 shader_backdrop_rect_location = |
| 1256 program->fragment_shader().backdrop_rect_location(); |
| 1325 } else if (!use_aa && !mask_texture_id && use_color_matrix) { | 1257 } else if (!use_aa && !mask_texture_id && use_color_matrix) { |
| 1326 const RenderPassColorMatrixProgram* program = | 1258 const RenderPassColorMatrixProgram* program = |
| 1327 GetRenderPassColorMatrixProgram(tex_coord_precision); | 1259 GetRenderPassColorMatrixProgram(tex_coord_precision, shader_blend_mode); |
| 1328 SetUseProgram(program->program()); | 1260 SetUseProgram(program->program()); |
| 1329 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0)); | 1261 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0)); |
| 1330 | 1262 |
| 1331 shader_matrix_location = program->vertex_shader().matrix_location(); | 1263 shader_matrix_location = program->vertex_shader().matrix_location(); |
| 1332 shader_tex_transform_location = | 1264 shader_tex_transform_location = |
| 1333 program->vertex_shader().tex_transform_location(); | 1265 program->vertex_shader().tex_transform_location(); |
| 1334 shader_alpha_location = program->fragment_shader().alpha_location(); | 1266 shader_alpha_location = program->fragment_shader().alpha_location(); |
| 1335 shader_color_matrix_location = | 1267 shader_color_matrix_location = |
| 1336 program->fragment_shader().color_matrix_location(); | 1268 program->fragment_shader().color_matrix_location(); |
| 1337 shader_color_offset_location = | 1269 shader_color_offset_location = |
| 1338 program->fragment_shader().color_offset_location(); | 1270 program->fragment_shader().color_offset_location(); |
| 1271 shader_backdrop_location = program->fragment_shader().backdrop_location(); |
| 1272 shader_backdrop_rect_location = |
| 1273 program->fragment_shader().backdrop_rect_location(); |
| 1339 } else { | 1274 } else { |
| 1340 const RenderPassProgram* program = | 1275 const RenderPassProgram* program = |
| 1341 GetRenderPassProgram(tex_coord_precision); | 1276 GetRenderPassProgram(tex_coord_precision, shader_blend_mode); |
| 1342 SetUseProgram(program->program()); | 1277 SetUseProgram(program->program()); |
| 1343 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0)); | 1278 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0)); |
| 1344 | 1279 |
| 1345 shader_matrix_location = program->vertex_shader().matrix_location(); | 1280 shader_matrix_location = program->vertex_shader().matrix_location(); |
| 1346 shader_alpha_location = program->fragment_shader().alpha_location(); | 1281 shader_alpha_location = program->fragment_shader().alpha_location(); |
| 1347 shader_tex_transform_location = | 1282 shader_tex_transform_location = |
| 1348 program->vertex_shader().tex_transform_location(); | 1283 program->vertex_shader().tex_transform_location(); |
| 1284 shader_backdrop_location = program->fragment_shader().backdrop_location(); |
| 1285 shader_backdrop_rect_location = |
| 1286 program->fragment_shader().backdrop_rect_location(); |
| 1349 } | 1287 } |
| 1350 float tex_scale_x = | 1288 float tex_scale_x = |
| 1351 quad->rect.width() / static_cast<float>(contents_texture->size().width()); | 1289 quad->rect.width() / static_cast<float>(contents_texture->size().width()); |
| 1352 float tex_scale_y = quad->rect.height() / | 1290 float tex_scale_y = quad->rect.height() / |
| 1353 static_cast<float>(contents_texture->size().height()); | 1291 static_cast<float>(contents_texture->size().height()); |
| 1354 DCHECK_LE(tex_scale_x, 1.0f); | 1292 DCHECK_LE(tex_scale_x, 1.0f); |
| 1355 DCHECK_LE(tex_scale_y, 1.0f); | 1293 DCHECK_LE(tex_scale_y, 1.0f); |
| 1356 | 1294 |
| 1357 DCHECK(shader_tex_transform_location != -1 || IsContextLost()); | 1295 DCHECK(shader_tex_transform_location != -1 || IsContextLost()); |
| 1358 // Flip the content vertically in the shader, as the RenderPass input | 1296 // Flip the content vertically in the shader, as the RenderPass input |
| 1359 // texture is already oriented the same way as the framebuffer, but the | 1297 // texture is already oriented the same way as the framebuffer, but the |
| 1360 // projection transform does a flip. | 1298 // projection transform does a flip. |
| 1361 GLC(gl_, | 1299 GLC(gl_, |
| 1362 gl_->Uniform4f(shader_tex_transform_location, | 1300 gl_->Uniform4f(shader_tex_transform_location, |
| 1363 0.0f, | 1301 0.0f, |
| 1364 tex_scale_y, | 1302 tex_scale_y, |
| 1365 tex_scale_x, | 1303 tex_scale_x, |
| 1366 -tex_scale_y)); | 1304 -tex_scale_y)); |
| 1367 | 1305 |
| 1306 GLint last_texture_unit = 0; |
| 1368 scoped_ptr<ResourceProvider::ScopedSamplerGL> shader_mask_sampler_lock; | 1307 scoped_ptr<ResourceProvider::ScopedSamplerGL> shader_mask_sampler_lock; |
| 1369 if (shader_mask_sampler_location != -1) { | 1308 if (shader_mask_sampler_location != -1) { |
| 1370 DCHECK_NE(shader_mask_tex_coord_scale_location, 1); | 1309 DCHECK_NE(shader_mask_tex_coord_scale_location, 1); |
| 1371 DCHECK_NE(shader_mask_tex_coord_offset_location, 1); | 1310 DCHECK_NE(shader_mask_tex_coord_offset_location, 1); |
| 1372 DCHECK_EQ(SamplerType2D, mask_sampler); | 1311 DCHECK_EQ(SamplerType2D, mask_sampler); |
| 1373 GLC(gl_, gl_->Uniform1i(shader_mask_sampler_location, 1)); | 1312 GLC(gl_, gl_->Uniform1i(shader_mask_sampler_location, 1)); |
| 1374 | 1313 |
| 1375 gfx::RectF mask_uv_rect = quad->MaskUVRect(); | 1314 gfx::RectF mask_uv_rect = quad->MaskUVRect(); |
| 1376 | 1315 |
| 1377 // Mask textures are oriented vertically flipped relative to the framebuffer | 1316 // Mask textures are oriented vertically flipped relative to the framebuffer |
| 1378 // and the RenderPass contents texture, so we flip the tex coords from the | 1317 // and the RenderPass contents texture, so we flip the tex coords from the |
| 1379 // RenderPass texture to find the mask texture coords. | 1318 // RenderPass texture to find the mask texture coords. |
| 1380 GLC(gl_, | 1319 GLC(gl_, |
| 1381 gl_->Uniform2f(shader_mask_tex_coord_offset_location, | 1320 gl_->Uniform2f(shader_mask_tex_coord_offset_location, |
| 1382 mask_uv_rect.x(), | 1321 mask_uv_rect.x(), |
| 1383 mask_uv_rect.bottom())); | 1322 mask_uv_rect.bottom())); |
| 1384 GLC(gl_, | 1323 GLC(gl_, |
| 1385 gl_->Uniform2f(shader_mask_tex_coord_scale_location, | 1324 gl_->Uniform2f(shader_mask_tex_coord_scale_location, |
| 1386 mask_uv_rect.width() / tex_scale_x, | 1325 mask_uv_rect.width() / tex_scale_x, |
| 1387 -mask_uv_rect.height() / tex_scale_y)); | 1326 -mask_uv_rect.height() / tex_scale_y)); |
| 1327 |
| 1328 last_texture_unit = 1; |
| 1388 } | 1329 } |
| 1389 | 1330 |
| 1390 if (shader_edge_location != -1) { | 1331 if (shader_edge_location != -1) { |
| 1391 float edge[24]; | 1332 float edge[24]; |
| 1392 device_layer_edges.ToFloatArray(edge); | 1333 device_layer_edges.ToFloatArray(edge); |
| 1393 device_layer_bounds.ToFloatArray(&edge[12]); | 1334 device_layer_bounds.ToFloatArray(&edge[12]); |
| 1394 GLC(gl_, gl_->Uniform3fv(shader_edge_location, 8, edge)); | 1335 GLC(gl_, gl_->Uniform3fv(shader_edge_location, 8, edge)); |
| 1395 } | 1336 } |
| 1396 | 1337 |
| 1397 if (shader_viewport_location != -1) { | 1338 if (shader_viewport_location != -1) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1413 } | 1354 } |
| 1414 static const float kScale = 1.0f / 255.0f; | 1355 static const float kScale = 1.0f / 255.0f; |
| 1415 if (shader_color_offset_location != -1) { | 1356 if (shader_color_offset_location != -1) { |
| 1416 float offset[4]; | 1357 float offset[4]; |
| 1417 for (int i = 0; i < 4; ++i) | 1358 for (int i = 0; i < 4; ++i) |
| 1418 offset[i] = SkScalarToFloat(color_matrix[i * 5 + 4]) * kScale; | 1359 offset[i] = SkScalarToFloat(color_matrix[i * 5 + 4]) * kScale; |
| 1419 | 1360 |
| 1420 GLC(gl_, gl_->Uniform4fv(shader_color_offset_location, 1, offset)); | 1361 GLC(gl_, gl_->Uniform4fv(shader_color_offset_location, 1, offset)); |
| 1421 } | 1362 } |
| 1422 | 1363 |
| 1364 scoped_ptr<ResourceProvider::ScopedSamplerGL> shader_background_sampler_lock; |
| 1365 if (shader_backdrop_location != -1) { |
| 1366 DCHECK(background_texture || background_image); |
| 1367 DCHECK_NE(shader_backdrop_location, 0); |
| 1368 DCHECK_NE(shader_backdrop_rect_location, 0); |
| 1369 |
| 1370 GLC(gl_, gl_->Uniform1i(shader_backdrop_location, ++last_texture_unit)); |
| 1371 |
| 1372 GLC(gl_, |
| 1373 gl_->Uniform4f(shader_backdrop_rect_location, |
| 1374 background_rect.x(), |
| 1375 background_rect.y(), |
| 1376 background_rect.width(), |
| 1377 background_rect.height())); |
| 1378 |
| 1379 if (background_image) { |
| 1380 GrTexture* texture = background_image->getTexture(); |
| 1381 GLC(gl_, gl_->ActiveTexture(GL_TEXTURE0 + last_texture_unit)); |
| 1382 gl_->BindTexture(GL_TEXTURE_2D, texture->getTextureHandle()); |
| 1383 GLC(gl_, gl_->ActiveTexture(GL_TEXTURE0)); |
| 1384 } else { |
| 1385 shader_background_sampler_lock = make_scoped_ptr( |
| 1386 new ResourceProvider::ScopedSamplerGL(resource_provider_, |
| 1387 background_texture->id(), |
| 1388 GL_TEXTURE0 + last_texture_unit, |
| 1389 GL_LINEAR)); |
| 1390 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), |
| 1391 shader_background_sampler_lock->target()); |
| 1392 } |
| 1393 } |
| 1394 |
| 1423 // Map device space quad to surface space. contents_device_transform has no 3d | 1395 // Map device space quad to surface space. contents_device_transform has no 3d |
| 1424 // component since it was flattened, so we don't need to project. | 1396 // component since it was flattened, so we don't need to project. |
| 1425 gfx::QuadF surface_quad = MathUtil::MapQuad(contents_device_transform_inverse, | 1397 gfx::QuadF surface_quad = MathUtil::MapQuad(contents_device_transform_inverse, |
| 1426 device_layer_edges.ToQuadF(), | 1398 device_layer_edges.ToQuadF(), |
| 1427 &clipped); | 1399 &clipped); |
| 1428 | 1400 |
| 1429 SetShaderOpacity(quad->opacity(), shader_alpha_location); | 1401 SetShaderOpacity(quad->opacity(), shader_alpha_location); |
| 1430 SetShaderQuadF(surface_quad, shader_quad_location); | 1402 SetShaderQuadF(surface_quad, shader_quad_location); |
| 1431 DrawQuadGeometry( | 1403 DrawQuadGeometry( |
| 1432 frame, quad->quadTransform(), quad->rect, shader_matrix_location); | 1404 frame, quad->quadTransform(), quad->rect, shader_matrix_location); |
| (...skipping 915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2348 } | 2320 } |
| 2349 | 2321 |
| 2350 void GLRenderer::CopyTextureToFramebuffer(const DrawingFrame* frame, | 2322 void GLRenderer::CopyTextureToFramebuffer(const DrawingFrame* frame, |
| 2351 int texture_id, | 2323 int texture_id, |
| 2352 const gfx::Rect& rect, | 2324 const gfx::Rect& rect, |
| 2353 const gfx::Transform& draw_matrix, | 2325 const gfx::Transform& draw_matrix, |
| 2354 bool flip_vertically) { | 2326 bool flip_vertically) { |
| 2355 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( | 2327 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( |
| 2356 gl_, &highp_threshold_cache_, highp_threshold_min_, rect.bottom_right()); | 2328 gl_, &highp_threshold_cache_, highp_threshold_min_, rect.bottom_right()); |
| 2357 | 2329 |
| 2358 const RenderPassProgram* program = GetRenderPassProgram(tex_coord_precision); | 2330 const RenderPassProgram* program = |
| 2331 GetRenderPassProgram(tex_coord_precision, BlendModeNormal); |
| 2359 SetUseProgram(program->program()); | 2332 SetUseProgram(program->program()); |
| 2360 | 2333 |
| 2361 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0)); | 2334 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0)); |
| 2362 | 2335 |
| 2363 if (flip_vertically) { | 2336 if (flip_vertically) { |
| 2364 GLC(gl_, | 2337 GLC(gl_, |
| 2365 gl_->Uniform4f(program->vertex_shader().tex_transform_location(), | 2338 gl_->Uniform4f(program->vertex_shader().tex_transform_location(), |
| 2366 0.f, | 2339 0.f, |
| 2367 1.f, | 2340 1.f, |
| 2368 1.f, | 2341 1.f, |
| (...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2827 if (!solid_color_program_aa_.initialized()) { | 2800 if (!solid_color_program_aa_.initialized()) { |
| 2828 TRACE_EVENT0("cc", "GLRenderer::solidColorProgramAA::initialize"); | 2801 TRACE_EVENT0("cc", "GLRenderer::solidColorProgramAA::initialize"); |
| 2829 solid_color_program_aa_.Initialize(output_surface_->context_provider(), | 2802 solid_color_program_aa_.Initialize(output_surface_->context_provider(), |
| 2830 TexCoordPrecisionNA, | 2803 TexCoordPrecisionNA, |
| 2831 SamplerTypeNA); | 2804 SamplerTypeNA); |
| 2832 } | 2805 } |
| 2833 return &solid_color_program_aa_; | 2806 return &solid_color_program_aa_; |
| 2834 } | 2807 } |
| 2835 | 2808 |
| 2836 const GLRenderer::RenderPassProgram* GLRenderer::GetRenderPassProgram( | 2809 const GLRenderer::RenderPassProgram* GLRenderer::GetRenderPassProgram( |
| 2837 TexCoordPrecision precision) { | 2810 TexCoordPrecision precision, |
| 2811 BlendMode blend_mode) { |
| 2838 DCHECK_GE(precision, 0); | 2812 DCHECK_GE(precision, 0); |
| 2839 DCHECK_LT(precision, NumTexCoordPrecisions); | 2813 DCHECK_LT(precision, NumTexCoordPrecisions); |
| 2840 RenderPassProgram* program = &render_pass_program_[precision]; | 2814 DCHECK_GE(blend_mode, 0); |
| 2815 DCHECK_LT(blend_mode, NumBlendModes); |
| 2816 RenderPassProgram* program = &render_pass_program_[precision][blend_mode]; |
| 2841 if (!program->initialized()) { | 2817 if (!program->initialized()) { |
| 2842 TRACE_EVENT0("cc", "GLRenderer::renderPassProgram::initialize"); | 2818 TRACE_EVENT0("cc", "GLRenderer::renderPassProgram::initialize"); |
| 2843 program->Initialize( | 2819 program->Initialize(output_surface_->context_provider(), |
| 2844 output_surface_->context_provider(), precision, SamplerType2D); | 2820 precision, |
| 2821 SamplerType2D, |
| 2822 blend_mode); |
| 2845 } | 2823 } |
| 2846 return program; | 2824 return program; |
| 2847 } | 2825 } |
| 2848 | 2826 |
| 2849 const GLRenderer::RenderPassProgramAA* GLRenderer::GetRenderPassProgramAA( | 2827 const GLRenderer::RenderPassProgramAA* GLRenderer::GetRenderPassProgramAA( |
| 2850 TexCoordPrecision precision) { | 2828 TexCoordPrecision precision, |
| 2829 BlendMode blend_mode) { |
| 2851 DCHECK_GE(precision, 0); | 2830 DCHECK_GE(precision, 0); |
| 2852 DCHECK_LT(precision, NumTexCoordPrecisions); | 2831 DCHECK_LT(precision, NumTexCoordPrecisions); |
| 2853 RenderPassProgramAA* program = &render_pass_program_aa_[precision]; | 2832 DCHECK_GE(blend_mode, 0); |
| 2833 DCHECK_LT(blend_mode, NumBlendModes); |
| 2834 RenderPassProgramAA* program = |
| 2835 &render_pass_program_aa_[precision][blend_mode]; |
| 2854 if (!program->initialized()) { | 2836 if (!program->initialized()) { |
| 2855 TRACE_EVENT0("cc", "GLRenderer::renderPassProgramAA::initialize"); | 2837 TRACE_EVENT0("cc", "GLRenderer::renderPassProgramAA::initialize"); |
| 2856 program->Initialize( | 2838 program->Initialize(output_surface_->context_provider(), |
| 2857 output_surface_->context_provider(), precision, SamplerType2D); | 2839 precision, |
| 2840 SamplerType2D, |
| 2841 blend_mode); |
| 2858 } | 2842 } |
| 2859 return program; | 2843 return program; |
| 2860 } | 2844 } |
| 2861 | 2845 |
| 2862 const GLRenderer::RenderPassMaskProgram* GLRenderer::GetRenderPassMaskProgram( | 2846 const GLRenderer::RenderPassMaskProgram* GLRenderer::GetRenderPassMaskProgram( |
| 2863 TexCoordPrecision precision) { | 2847 TexCoordPrecision precision, |
| 2848 BlendMode blend_mode) { |
| 2864 DCHECK_GE(precision, 0); | 2849 DCHECK_GE(precision, 0); |
| 2865 DCHECK_LT(precision, NumTexCoordPrecisions); | 2850 DCHECK_LT(precision, NumTexCoordPrecisions); |
| 2866 RenderPassMaskProgram* program = &render_pass_mask_program_[precision]; | 2851 DCHECK_GE(blend_mode, 0); |
| 2852 DCHECK_LT(blend_mode, NumBlendModes); |
| 2853 RenderPassMaskProgram* program = |
| 2854 &render_pass_mask_program_[precision][blend_mode]; |
| 2867 if (!program->initialized()) { | 2855 if (!program->initialized()) { |
| 2868 TRACE_EVENT0("cc", "GLRenderer::renderPassMaskProgram::initialize"); | 2856 TRACE_EVENT0("cc", "GLRenderer::renderPassMaskProgram::initialize"); |
| 2869 program->Initialize( | 2857 program->Initialize(output_surface_->context_provider(), |
| 2870 output_surface_->context_provider(), precision, SamplerType2D); | 2858 precision, |
| 2859 SamplerType2D, |
| 2860 blend_mode); |
| 2871 } | 2861 } |
| 2872 return program; | 2862 return program; |
| 2873 } | 2863 } |
| 2874 | 2864 |
| 2875 const GLRenderer::RenderPassMaskProgramAA* | 2865 const GLRenderer::RenderPassMaskProgramAA* |
| 2876 GLRenderer::GetRenderPassMaskProgramAA(TexCoordPrecision precision) { | 2866 GLRenderer::GetRenderPassMaskProgramAA(TexCoordPrecision precision, |
| 2867 BlendMode blend_mode) { |
| 2877 DCHECK_GE(precision, 0); | 2868 DCHECK_GE(precision, 0); |
| 2878 DCHECK_LT(precision, NumTexCoordPrecisions); | 2869 DCHECK_LT(precision, NumTexCoordPrecisions); |
| 2879 RenderPassMaskProgramAA* program = &render_pass_mask_program_aa_[precision]; | 2870 DCHECK_GE(blend_mode, 0); |
| 2871 DCHECK_LT(blend_mode, NumBlendModes); |
| 2872 RenderPassMaskProgramAA* program = |
| 2873 &render_pass_mask_program_aa_[precision][blend_mode]; |
| 2880 if (!program->initialized()) { | 2874 if (!program->initialized()) { |
| 2881 TRACE_EVENT0("cc", "GLRenderer::renderPassMaskProgramAA::initialize"); | 2875 TRACE_EVENT0("cc", "GLRenderer::renderPassMaskProgramAA::initialize"); |
| 2882 program->Initialize( | 2876 program->Initialize(output_surface_->context_provider(), |
| 2883 output_surface_->context_provider(), precision, SamplerType2D); | 2877 precision, |
| 2878 SamplerType2D, |
| 2879 blend_mode); |
| 2884 } | 2880 } |
| 2885 return program; | 2881 return program; |
| 2886 } | 2882 } |
| 2887 | 2883 |
| 2888 const GLRenderer::RenderPassColorMatrixProgram* | 2884 const GLRenderer::RenderPassColorMatrixProgram* |
| 2889 GLRenderer::GetRenderPassColorMatrixProgram(TexCoordPrecision precision) { | 2885 GLRenderer::GetRenderPassColorMatrixProgram(TexCoordPrecision precision, |
| 2886 BlendMode blend_mode) { |
| 2890 DCHECK_GE(precision, 0); | 2887 DCHECK_GE(precision, 0); |
| 2891 DCHECK_LT(precision, NumTexCoordPrecisions); | 2888 DCHECK_LT(precision, NumTexCoordPrecisions); |
| 2889 DCHECK_GE(blend_mode, 0); |
| 2890 DCHECK_LT(blend_mode, NumBlendModes); |
| 2892 RenderPassColorMatrixProgram* program = | 2891 RenderPassColorMatrixProgram* program = |
| 2893 &render_pass_color_matrix_program_[precision]; | 2892 &render_pass_color_matrix_program_[precision][blend_mode]; |
| 2894 if (!program->initialized()) { | 2893 if (!program->initialized()) { |
| 2895 TRACE_EVENT0("cc", "GLRenderer::renderPassColorMatrixProgram::initialize"); | 2894 TRACE_EVENT0("cc", "GLRenderer::renderPassColorMatrixProgram::initialize"); |
| 2896 program->Initialize( | 2895 program->Initialize(output_surface_->context_provider(), |
| 2897 output_surface_->context_provider(), precision, SamplerType2D); | 2896 precision, |
| 2897 SamplerType2D, |
| 2898 blend_mode); |
| 2898 } | 2899 } |
| 2899 return program; | 2900 return program; |
| 2900 } | 2901 } |
| 2901 | 2902 |
| 2902 const GLRenderer::RenderPassColorMatrixProgramAA* | 2903 const GLRenderer::RenderPassColorMatrixProgramAA* |
| 2903 GLRenderer::GetRenderPassColorMatrixProgramAA(TexCoordPrecision precision) { | 2904 GLRenderer::GetRenderPassColorMatrixProgramAA(TexCoordPrecision precision, |
| 2905 BlendMode blend_mode) { |
| 2904 DCHECK_GE(precision, 0); | 2906 DCHECK_GE(precision, 0); |
| 2905 DCHECK_LT(precision, NumTexCoordPrecisions); | 2907 DCHECK_LT(precision, NumTexCoordPrecisions); |
| 2908 DCHECK_GE(blend_mode, 0); |
| 2909 DCHECK_LT(blend_mode, NumBlendModes); |
| 2906 RenderPassColorMatrixProgramAA* program = | 2910 RenderPassColorMatrixProgramAA* program = |
| 2907 &render_pass_color_matrix_program_aa_[precision]; | 2911 &render_pass_color_matrix_program_aa_[precision][blend_mode]; |
| 2908 if (!program->initialized()) { | 2912 if (!program->initialized()) { |
| 2909 TRACE_EVENT0("cc", | 2913 TRACE_EVENT0("cc", |
| 2910 "GLRenderer::renderPassColorMatrixProgramAA::initialize"); | 2914 "GLRenderer::renderPassColorMatrixProgramAA::initialize"); |
| 2911 program->Initialize( | 2915 program->Initialize(output_surface_->context_provider(), |
| 2912 output_surface_->context_provider(), precision, SamplerType2D); | 2916 precision, |
| 2917 SamplerType2D, |
| 2918 blend_mode); |
| 2913 } | 2919 } |
| 2914 return program; | 2920 return program; |
| 2915 } | 2921 } |
| 2916 | 2922 |
| 2917 const GLRenderer::RenderPassMaskColorMatrixProgram* | 2923 const GLRenderer::RenderPassMaskColorMatrixProgram* |
| 2918 GLRenderer::GetRenderPassMaskColorMatrixProgram(TexCoordPrecision precision) { | 2924 GLRenderer::GetRenderPassMaskColorMatrixProgram(TexCoordPrecision precision, |
| 2925 BlendMode blend_mode) { |
| 2919 DCHECK_GE(precision, 0); | 2926 DCHECK_GE(precision, 0); |
| 2920 DCHECK_LT(precision, NumTexCoordPrecisions); | 2927 DCHECK_LT(precision, NumTexCoordPrecisions); |
| 2928 DCHECK_GE(blend_mode, 0); |
| 2929 DCHECK_LT(blend_mode, NumBlendModes); |
| 2921 RenderPassMaskColorMatrixProgram* program = | 2930 RenderPassMaskColorMatrixProgram* program = |
| 2922 &render_pass_mask_color_matrix_program_[precision]; | 2931 &render_pass_mask_color_matrix_program_[precision][blend_mode]; |
| 2923 if (!program->initialized()) { | 2932 if (!program->initialized()) { |
| 2924 TRACE_EVENT0("cc", | 2933 TRACE_EVENT0("cc", |
| 2925 "GLRenderer::renderPassMaskColorMatrixProgram::initialize"); | 2934 "GLRenderer::renderPassMaskColorMatrixProgram::initialize"); |
| 2926 program->Initialize( | 2935 program->Initialize(output_surface_->context_provider(), |
| 2927 output_surface_->context_provider(), precision, SamplerType2D); | 2936 precision, |
| 2937 SamplerType2D, |
| 2938 blend_mode); |
| 2928 } | 2939 } |
| 2929 return program; | 2940 return program; |
| 2930 } | 2941 } |
| 2931 | 2942 |
| 2932 const GLRenderer::RenderPassMaskColorMatrixProgramAA* | 2943 const GLRenderer::RenderPassMaskColorMatrixProgramAA* |
| 2933 GLRenderer::GetRenderPassMaskColorMatrixProgramAA(TexCoordPrecision precision) { | 2944 GLRenderer::GetRenderPassMaskColorMatrixProgramAA(TexCoordPrecision precision, |
| 2945 BlendMode blend_mode) { |
| 2934 DCHECK_GE(precision, 0); | 2946 DCHECK_GE(precision, 0); |
| 2935 DCHECK_LT(precision, NumTexCoordPrecisions); | 2947 DCHECK_LT(precision, NumTexCoordPrecisions); |
| 2948 DCHECK_GE(blend_mode, 0); |
| 2949 DCHECK_LT(blend_mode, NumBlendModes); |
| 2936 RenderPassMaskColorMatrixProgramAA* program = | 2950 RenderPassMaskColorMatrixProgramAA* program = |
| 2937 &render_pass_mask_color_matrix_program_aa_[precision]; | 2951 &render_pass_mask_color_matrix_program_aa_[precision][blend_mode]; |
| 2938 if (!program->initialized()) { | 2952 if (!program->initialized()) { |
| 2939 TRACE_EVENT0("cc", | 2953 TRACE_EVENT0("cc", |
| 2940 "GLRenderer::renderPassMaskColorMatrixProgramAA::initialize"); | 2954 "GLRenderer::renderPassMaskColorMatrixProgramAA::initialize"); |
| 2941 program->Initialize( | 2955 program->Initialize(output_surface_->context_provider(), |
| 2942 output_surface_->context_provider(), precision, SamplerType2D); | 2956 precision, |
| 2957 SamplerType2D, |
| 2958 blend_mode); |
| 2943 } | 2959 } |
| 2944 return program; | 2960 return program; |
| 2945 } | 2961 } |
| 2946 | 2962 |
| 2947 const GLRenderer::TileProgram* GLRenderer::GetTileProgram( | 2963 const GLRenderer::TileProgram* GLRenderer::GetTileProgram( |
| 2948 TexCoordPrecision precision, | 2964 TexCoordPrecision precision, |
| 2949 SamplerType sampler) { | 2965 SamplerType sampler) { |
| 2950 DCHECK_GE(precision, 0); | 2966 DCHECK_GE(precision, 0); |
| 2951 DCHECK_LT(precision, NumTexCoordPrecisions); | 2967 DCHECK_LT(precision, NumTexCoordPrecisions); |
| 2952 DCHECK_GE(sampler, 0); | 2968 DCHECK_GE(sampler, 0); |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3158 | 3174 |
| 3159 for (int i = 0; i < NumTexCoordPrecisions; ++i) { | 3175 for (int i = 0; i < NumTexCoordPrecisions; ++i) { |
| 3160 for (int j = 0; j < NumSamplerTypes; ++j) { | 3176 for (int j = 0; j < NumSamplerTypes; ++j) { |
| 3161 tile_program_[i][j].Cleanup(gl_); | 3177 tile_program_[i][j].Cleanup(gl_); |
| 3162 tile_program_opaque_[i][j].Cleanup(gl_); | 3178 tile_program_opaque_[i][j].Cleanup(gl_); |
| 3163 tile_program_swizzle_[i][j].Cleanup(gl_); | 3179 tile_program_swizzle_[i][j].Cleanup(gl_); |
| 3164 tile_program_swizzle_opaque_[i][j].Cleanup(gl_); | 3180 tile_program_swizzle_opaque_[i][j].Cleanup(gl_); |
| 3165 tile_program_aa_[i][j].Cleanup(gl_); | 3181 tile_program_aa_[i][j].Cleanup(gl_); |
| 3166 tile_program_swizzle_aa_[i][j].Cleanup(gl_); | 3182 tile_program_swizzle_aa_[i][j].Cleanup(gl_); |
| 3167 } | 3183 } |
| 3168 | 3184 for (int j = 0; j < NumBlendModes; j++) { |
| 3169 render_pass_mask_program_[i].Cleanup(gl_); | 3185 render_pass_mask_program_[i][j].Cleanup(gl_); |
| 3170 render_pass_program_[i].Cleanup(gl_); | 3186 render_pass_program_[i][j].Cleanup(gl_); |
| 3171 render_pass_mask_program_aa_[i].Cleanup(gl_); | 3187 render_pass_mask_program_aa_[i][j].Cleanup(gl_); |
| 3172 render_pass_program_aa_[i].Cleanup(gl_); | 3188 render_pass_program_aa_[i][j].Cleanup(gl_); |
| 3173 render_pass_color_matrix_program_[i].Cleanup(gl_); | 3189 render_pass_color_matrix_program_[i][j].Cleanup(gl_); |
| 3174 render_pass_mask_color_matrix_program_aa_[i].Cleanup(gl_); | 3190 render_pass_mask_color_matrix_program_aa_[i][j].Cleanup(gl_); |
| 3175 render_pass_color_matrix_program_aa_[i].Cleanup(gl_); | 3191 render_pass_color_matrix_program_aa_[i][j].Cleanup(gl_); |
| 3176 render_pass_mask_color_matrix_program_[i].Cleanup(gl_); | 3192 render_pass_mask_color_matrix_program_[i][j].Cleanup(gl_); |
| 3193 } |
| 3177 | 3194 |
| 3178 texture_program_[i].Cleanup(gl_); | 3195 texture_program_[i].Cleanup(gl_); |
| 3179 nonpremultiplied_texture_program_[i].Cleanup(gl_); | 3196 nonpremultiplied_texture_program_[i].Cleanup(gl_); |
| 3180 texture_background_program_[i].Cleanup(gl_); | 3197 texture_background_program_[i].Cleanup(gl_); |
| 3181 nonpremultiplied_texture_background_program_[i].Cleanup(gl_); | 3198 nonpremultiplied_texture_background_program_[i].Cleanup(gl_); |
| 3182 texture_io_surface_program_[i].Cleanup(gl_); | 3199 texture_io_surface_program_[i].Cleanup(gl_); |
| 3183 | 3200 |
| 3184 video_yuv_program_[i].Cleanup(gl_); | 3201 video_yuv_program_[i].Cleanup(gl_); |
| 3185 video_yuva_program_[i].Cleanup(gl_); | 3202 video_yuva_program_[i].Cleanup(gl_); |
| 3186 video_stream_texture_program_[i].Cleanup(gl_); | 3203 video_stream_texture_program_[i].Cleanup(gl_); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3275 context_support_->ScheduleOverlayPlane( | 3292 context_support_->ScheduleOverlayPlane( |
| 3276 overlay.plane_z_order, | 3293 overlay.plane_z_order, |
| 3277 overlay.transform, | 3294 overlay.transform, |
| 3278 pending_overlay_resources_.back()->texture_id(), | 3295 pending_overlay_resources_.back()->texture_id(), |
| 3279 overlay.display_rect, | 3296 overlay.display_rect, |
| 3280 overlay.uv_rect); | 3297 overlay.uv_rect); |
| 3281 } | 3298 } |
| 3282 } | 3299 } |
| 3283 | 3300 |
| 3284 } // namespace cc | 3301 } // namespace cc |
| OLD | NEW |