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 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
654 source.setPixelRef(pixel_ref.get()); | 654 source.setPixelRef(pixel_ref.get()); |
655 | 655 |
656 // Create a scratch texture for backing store. | 656 // Create a scratch texture for backing store. |
657 GrTextureDesc desc; | 657 GrTextureDesc desc; |
658 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; | 658 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; |
659 desc.fSampleCnt = 0; | 659 desc.fSampleCnt = 0; |
660 desc.fWidth = source.width(); | 660 desc.fWidth = source.width(); |
661 desc.fHeight = source.height(); | 661 desc.fHeight = source.height(); |
662 desc.fConfig = kSkia8888_GrPixelConfig; | 662 desc.fConfig = kSkia8888_GrPixelConfig; |
663 desc.fOrigin = kBottomLeft_GrSurfaceOrigin; | 663 desc.fOrigin = kBottomLeft_GrSurfaceOrigin; |
664 GrAutoScratchTexture scratch_texture( | |
665 use_gr_context->context(), desc, GrContext::kExact_ScratchTexMatch); | |
666 skia::RefPtr<GrTexture> backing_store = | 664 skia::RefPtr<GrTexture> backing_store = |
667 skia::AdoptRef(scratch_texture.detach()); | 665 skia::AdoptRef(use_gr_context->context()->refScratchTexture( |
| 666 desc, GrContext::kExact_ScratchTexMatch)); |
668 if (!backing_store) { | 667 if (!backing_store) { |
669 TRACE_EVENT_INSTANT0("cc", | 668 TRACE_EVENT_INSTANT0("cc", |
670 "ApplyImageFilter scratch texture allocation failed", | 669 "ApplyImageFilter scratch texture allocation failed", |
671 TRACE_EVENT_SCOPE_THREAD); | 670 TRACE_EVENT_SCOPE_THREAD); |
672 return skia::RefPtr<SkImage>(); | 671 return skia::RefPtr<SkImage>(); |
673 } | 672 } |
674 | 673 |
675 // Create surface to draw into. | 674 // Create surface to draw into. |
676 skia::RefPtr<SkSurface> surface = skia::AdoptRef( | 675 skia::RefPtr<SkSurface> surface = skia::AdoptRef( |
677 SkSurface::NewRenderTargetDirect(backing_store->asRenderTarget())); | 676 SkSurface::NewRenderTargetDirect(backing_store->asRenderTarget())); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
816 background.setPixelRef(background_pixel_ref.get()); | 815 background.setPixelRef(background_pixel_ref.get()); |
817 | 816 |
818 // Create a scratch texture for backing store. | 817 // Create a scratch texture for backing store. |
819 GrTextureDesc desc; | 818 GrTextureDesc desc; |
820 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; | 819 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; |
821 desc.fSampleCnt = 0; | 820 desc.fSampleCnt = 0; |
822 desc.fWidth = source.width(); | 821 desc.fWidth = source.width(); |
823 desc.fHeight = source.height(); | 822 desc.fHeight = source.height(); |
824 desc.fConfig = kSkia8888_GrPixelConfig; | 823 desc.fConfig = kSkia8888_GrPixelConfig; |
825 desc.fOrigin = kBottomLeft_GrSurfaceOrigin; | 824 desc.fOrigin = kBottomLeft_GrSurfaceOrigin; |
826 GrAutoScratchTexture scratch_texture( | |
827 use_gr_context->context(), desc, GrContext::kExact_ScratchTexMatch); | |
828 skia::RefPtr<GrTexture> backing_store = | 825 skia::RefPtr<GrTexture> backing_store = |
829 skia::AdoptRef(scratch_texture.detach()); | 826 skia::AdoptRef(use_gr_context->context()->refScratchTexture( |
| 827 desc, GrContext::kExact_ScratchTexMatch)); |
830 if (!backing_store) { | 828 if (!backing_store) { |
831 TRACE_EVENT_INSTANT0( | 829 TRACE_EVENT_INSTANT0( |
832 "cc", | 830 "cc", |
833 "ApplyBlendModeWithBackdrop scratch texture allocation failed", | 831 "ApplyBlendModeWithBackdrop scratch texture allocation failed", |
834 TRACE_EVENT_SCOPE_THREAD); | 832 TRACE_EVENT_SCOPE_THREAD); |
835 return source_bitmap_with_filters; | 833 return source_bitmap_with_filters; |
836 } | 834 } |
837 | 835 |
838 // Create a device and canvas using that backing store. | 836 // Create a device and canvas using that backing store. |
839 skia::RefPtr<SkSurface> surface = skia::AdoptRef( | 837 skia::RefPtr<SkSurface> surface = skia::AdoptRef( |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1084 scoped_background_texture.get(), | 1082 scoped_background_texture.get(), |
1085 background_with_filters, | 1083 background_with_filters, |
1086 backdrop_rect); | 1084 backdrop_rect); |
1087 | 1085 |
1088 if (disable_blending) | 1086 if (disable_blending) |
1089 SetBlendEnabled(true); | 1087 SetBlendEnabled(true); |
1090 } | 1088 } |
1091 | 1089 |
1092 // TODO(senorblanco): Cache this value so that we don't have to do it for both | 1090 // TODO(senorblanco): Cache this value so that we don't have to do it for both |
1093 // the surface and its replica. Apply filters to the contents texture. | 1091 // the surface and its replica. Apply filters to the contents texture. |
1094 skia::RefPtr<SkImage> filter_bitmap; | 1092 skia::RefPtr<SkImage> filter_image; |
1095 SkScalar color_matrix[20]; | 1093 SkScalar color_matrix[20]; |
1096 bool use_color_matrix = false; | 1094 bool use_color_matrix = false; |
1097 if (!quad->filters.IsEmpty()) { | 1095 if (!quad->filters.IsEmpty()) { |
1098 skia::RefPtr<SkImageFilter> filter = RenderSurfaceFilters::BuildImageFilter( | 1096 skia::RefPtr<SkImageFilter> filter = RenderSurfaceFilters::BuildImageFilter( |
1099 quad->filters, contents_texture->size()); | 1097 quad->filters, contents_texture->size()); |
1100 if (filter) { | 1098 if (filter) { |
1101 skia::RefPtr<SkColorFilter> cf; | 1099 skia::RefPtr<SkColorFilter> cf; |
1102 | 1100 |
1103 { | 1101 { |
1104 SkColorFilter* colorfilter_rawptr = NULL; | 1102 SkColorFilter* colorfilter_rawptr = NULL; |
1105 filter->asColorFilter(&colorfilter_rawptr); | 1103 filter->asColorFilter(&colorfilter_rawptr); |
1106 cf = skia::AdoptRef(colorfilter_rawptr); | 1104 cf = skia::AdoptRef(colorfilter_rawptr); |
1107 } | 1105 } |
1108 | 1106 |
1109 if (cf && cf->asColorMatrix(color_matrix) && !filter->getInput(0)) { | 1107 if (cf && cf->asColorMatrix(color_matrix) && !filter->getInput(0)) { |
1110 // We have a single color matrix as a filter; apply it locally | 1108 // We have a single color matrix as a filter; apply it locally |
1111 // in the compositor. | 1109 // in the compositor. |
1112 use_color_matrix = true; | 1110 use_color_matrix = true; |
1113 } else { | 1111 } else { |
1114 filter_bitmap = | 1112 filter_image = ApplyImageFilter(ScopedUseGrContext::Create(this, frame), |
1115 ApplyImageFilter(ScopedUseGrContext::Create(this, frame), | 1113 resource_provider_, |
1116 resource_provider_, | 1114 quad->rect.origin(), |
1117 quad->rect.origin(), | 1115 quad->filters_scale, |
1118 quad->filters_scale, | 1116 filter.get(), |
1119 filter.get(), | 1117 contents_texture); |
1120 contents_texture); | |
1121 } | 1118 } |
1122 } | 1119 } |
1123 } | 1120 } |
1124 | 1121 |
1125 if (background_texture) { | 1122 if (background_texture) { |
1126 if (CanApplyBlendModeUsingBlendFunc(blend_mode)) { | 1123 if (CanApplyBlendModeUsingBlendFunc(blend_mode)) { |
1127 // Draw the background texture if it has some filters applied. | 1124 // Draw the background texture if it has some filters applied. |
1128 DCHECK(ShouldApplyBackgroundFilters(frame, quad)); | 1125 DCHECK(ShouldApplyBackgroundFilters(frame, quad)); |
1129 DCHECK(background_texture->size() == quad->rect.size()); | 1126 DCHECK(background_texture->size() == quad->rect.size()); |
1130 ResourceProvider::ScopedReadLockGL lock(resource_provider_, | 1127 ResourceProvider::ScopedReadLockGL lock(resource_provider_, |
1131 background_texture->id()); | 1128 background_texture->id()); |
1132 | 1129 |
1133 // The background_texture is oriented the same as the frame buffer. The | 1130 // The background_texture is oriented the same as the frame buffer. The |
1134 // transform we are copying with has a vertical flip, so flip the contents | 1131 // transform we are copying with has a vertical flip, so flip the contents |
1135 // in the shader to maintain orientation | 1132 // in the shader to maintain orientation |
1136 bool flip_vertically = true; | 1133 bool flip_vertically = true; |
1137 | 1134 |
1138 CopyTextureToFramebuffer(frame, | 1135 CopyTextureToFramebuffer(frame, |
1139 lock.texture_id(), | 1136 lock.texture_id(), |
1140 quad->rect, | 1137 quad->rect, |
1141 quad->quadTransform(), | 1138 quad->quadTransform(), |
1142 flip_vertically); | 1139 flip_vertically); |
1143 } else { | 1140 } else { |
1144 // If blending is applied using shaders, the background texture with | 1141 // If blending is applied using shaders, the background texture with |
1145 // filters will be used as backdrop for blending operation, so we don't | 1142 // filters will be used as backdrop for blending operation, so we don't |
1146 // need to copy it to the frame buffer. | 1143 // need to copy it to the frame buffer. |
1147 filter_bitmap = | 1144 filter_image = |
1148 ApplyBlendModeWithBackdrop(ScopedUseGrContext::Create(this, frame), | 1145 ApplyBlendModeWithBackdrop(ScopedUseGrContext::Create(this, frame), |
1149 resource_provider_, | 1146 resource_provider_, |
1150 filter_bitmap, | 1147 filter_image, |
1151 contents_texture, | 1148 contents_texture, |
1152 background_texture.get(), | 1149 background_texture.get(), |
1153 quad->shared_quad_state->blend_mode); | 1150 quad->shared_quad_state->blend_mode); |
1154 } | 1151 } |
1155 } | 1152 } |
1156 | 1153 |
1157 bool clipped = false; | 1154 bool clipped = false; |
1158 gfx::QuadF device_quad = MathUtil::MapQuad( | 1155 gfx::QuadF device_quad = MathUtil::MapQuad( |
1159 contents_device_transform, SharedGeometryQuad(), &clipped); | 1156 contents_device_transform, SharedGeometryQuad(), &clipped); |
1160 LayerQuad device_layer_bounds(gfx::QuadF(device_quad.BoundingBox())); | 1157 LayerQuad device_layer_bounds(gfx::QuadF(device_quad.BoundingBox())); |
(...skipping 14 matching lines...) Expand all Loading... |
1175 if (quad->mask_resource_id) { | 1172 if (quad->mask_resource_id) { |
1176 mask_resource_lock.reset(new ResourceProvider::ScopedReadLockGL( | 1173 mask_resource_lock.reset(new ResourceProvider::ScopedReadLockGL( |
1177 resource_provider_, quad->mask_resource_id)); | 1174 resource_provider_, quad->mask_resource_id)); |
1178 mask_texture_id = mask_resource_lock->texture_id(); | 1175 mask_texture_id = mask_resource_lock->texture_id(); |
1179 } | 1176 } |
1180 | 1177 |
1181 // TODO(danakj): use the background_texture and blend the background in with | 1178 // TODO(danakj): use the background_texture and blend the background in with |
1182 // this draw instead of having a separate copy of the background texture. | 1179 // this draw instead of having a separate copy of the background texture. |
1183 | 1180 |
1184 scoped_ptr<ResourceProvider::ScopedSamplerGL> contents_resource_lock; | 1181 scoped_ptr<ResourceProvider::ScopedSamplerGL> contents_resource_lock; |
1185 if (filter_bitmap) { | 1182 if (filter_image) { |
1186 GrTexture* texture = filter_bitmap->getTexture(); | 1183 GrTexture* texture = filter_image->getTexture(); |
1187 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_)); | 1184 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_)); |
1188 gl_->BindTexture(GL_TEXTURE_2D, texture->getTextureHandle()); | 1185 gl_->BindTexture(GL_TEXTURE_2D, texture->getTextureHandle()); |
1189 } else { | 1186 } else { |
1190 contents_resource_lock = | 1187 contents_resource_lock = |
1191 make_scoped_ptr(new ResourceProvider::ScopedSamplerGL( | 1188 make_scoped_ptr(new ResourceProvider::ScopedSamplerGL( |
1192 resource_provider_, contents_texture->id(), GL_LINEAR)); | 1189 resource_provider_, contents_texture->id(), GL_LINEAR)); |
1193 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), | 1190 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), |
1194 contents_resource_lock->target()); | 1191 contents_resource_lock->target()); |
1195 } | 1192 } |
1196 | 1193 |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1434 device_layer_edges.ToQuadF(), | 1431 device_layer_edges.ToQuadF(), |
1435 &clipped); | 1432 &clipped); |
1436 | 1433 |
1437 SetShaderOpacity(quad->opacity(), shader_alpha_location); | 1434 SetShaderOpacity(quad->opacity(), shader_alpha_location); |
1438 SetShaderQuadF(surface_quad, shader_quad_location); | 1435 SetShaderQuadF(surface_quad, shader_quad_location); |
1439 DrawQuadGeometry( | 1436 DrawQuadGeometry( |
1440 frame, quad->quadTransform(), quad->rect, shader_matrix_location); | 1437 frame, quad->quadTransform(), quad->rect, shader_matrix_location); |
1441 | 1438 |
1442 // Flush the compositor context before the filter bitmap goes out of | 1439 // Flush the compositor context before the filter bitmap goes out of |
1443 // scope, so the draw gets processed before the filter texture gets deleted. | 1440 // scope, so the draw gets processed before the filter texture gets deleted. |
1444 if (filter_bitmap) | 1441 if (filter_image) |
1445 GLC(gl_, gl_->Flush()); | 1442 GLC(gl_, gl_->Flush()); |
1446 | 1443 |
1447 if (CanApplyBlendModeUsingBlendFunc(blend_mode)) | 1444 if (CanApplyBlendModeUsingBlendFunc(blend_mode)) |
1448 RestoreBlendFuncToDefault(blend_mode); | 1445 RestoreBlendFuncToDefault(blend_mode); |
1449 } | 1446 } |
1450 | 1447 |
1451 struct SolidColorProgramUniforms { | 1448 struct SolidColorProgramUniforms { |
1452 unsigned program; | 1449 unsigned program; |
1453 unsigned matrix_location; | 1450 unsigned matrix_location; |
1454 unsigned viewport_location; | 1451 unsigned viewport_location; |
(...skipping 1828 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3283 context_support_->ScheduleOverlayPlane( | 3280 context_support_->ScheduleOverlayPlane( |
3284 overlay.plane_z_order, | 3281 overlay.plane_z_order, |
3285 overlay.transform, | 3282 overlay.transform, |
3286 pending_overlay_resources_.back()->texture_id(), | 3283 pending_overlay_resources_.back()->texture_id(), |
3287 overlay.display_rect, | 3284 overlay.display_rect, |
3288 overlay.uv_rect); | 3285 overlay.uv_rect); |
3289 } | 3286 } |
3290 } | 3287 } |
3291 | 3288 |
3292 } // namespace cc | 3289 } // namespace cc |
OLD | NEW |