Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2010 The Chromium Authors. All rights reserved. | 1 // Copyright 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/output/gl_renderer.h" | 5 #include "cc/output/gl_renderer.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 332 | 332 |
| 333 capabilities_.using_image = context_caps.gpu.image; | 333 capabilities_.using_image = context_caps.gpu.image; |
| 334 | 334 |
| 335 capabilities_.using_discard_framebuffer = | 335 capabilities_.using_discard_framebuffer = |
| 336 context_caps.gpu.discard_framebuffer; | 336 context_caps.gpu.discard_framebuffer; |
| 337 | 337 |
| 338 capabilities_.allow_rasterize_on_demand = true; | 338 capabilities_.allow_rasterize_on_demand = true; |
| 339 | 339 |
| 340 use_sync_query_ = context_caps.gpu.sync_query; | 340 use_sync_query_ = context_caps.gpu.sync_query; |
| 341 use_blend_minmax_ = context_caps.gpu.blend_minmax; | 341 use_blend_minmax_ = context_caps.gpu.blend_minmax; |
| 342 use_blend_equation_advanced_ = context_caps.gpu.blend_equation_advanced; | |
| 342 | 343 |
| 343 InitializeSharedObjects(); | 344 InitializeSharedObjects(); |
| 344 } | 345 } |
| 345 | 346 |
| 346 GLRenderer::~GLRenderer() { | 347 GLRenderer::~GLRenderer() { |
| 347 while (!pending_async_read_pixels_.empty()) { | 348 while (!pending_async_read_pixels_.empty()) { |
| 348 PendingAsyncReadPixels* pending_read = pending_async_read_pixels_.back(); | 349 PendingAsyncReadPixels* pending_read = pending_async_read_pixels_.back(); |
| 349 pending_read->finished_read_pixels_callback.Cancel(); | 350 pending_read->finished_read_pixels_callback.Cancel(); |
| 350 pending_async_read_pixels_.pop_back(); | 351 pending_async_read_pixels_.pop_back(); |
| 351 } | 352 } |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 693 | 694 |
| 694 // Flush the GrContext to ensure all buffered GL calls are drawn to the | 695 // Flush the GrContext to ensure all buffered GL calls are drawn to the |
| 695 // backing store before we access and return it, and have cc begin using the | 696 // backing store before we access and return it, and have cc begin using the |
| 696 // GL context again. | 697 // GL context again. |
| 697 canvas->flush(); | 698 canvas->flush(); |
| 698 | 699 |
| 699 return image; | 700 return image; |
| 700 } | 701 } |
| 701 | 702 |
| 702 bool GLRenderer::CanApplyBlendModeUsingBlendFunc(SkXfermode::Mode blend_mode) { | 703 bool GLRenderer::CanApplyBlendModeUsingBlendFunc(SkXfermode::Mode blend_mode) { |
| 703 return (use_blend_minmax_ && blend_mode == SkXfermode::kLighten_Mode) || | 704 return use_blend_equation_advanced_ || |
| 704 blend_mode == SkXfermode::kScreen_Mode || | 705 (use_blend_minmax_ && blend_mode == SkXfermode::kLighten_Mode) || |
| 705 blend_mode == SkXfermode::kSrcOver_Mode; | 706 blend_mode == SkXfermode::kScreen_Mode || |
| 707 blend_mode == SkXfermode::kSrcOver_Mode; | |
| 706 } | 708 } |
| 707 | 709 |
| 708 void GLRenderer::ApplyBlendModeUsingBlendFunc(SkXfermode::Mode blend_mode) { | 710 void GLRenderer::ApplyBlendModeUsingBlendFunc(SkXfermode::Mode blend_mode) { |
| 709 DCHECK(CanApplyBlendModeUsingBlendFunc(blend_mode)); | 711 DCHECK(CanApplyBlendModeUsingBlendFunc(blend_mode)); |
| 710 | 712 |
| 711 // Any modes set here must be reset in RestoreBlendFuncToDefault | 713 // Any modes set here must be reset in RestoreBlendFuncToDefault |
| 712 if (blend_mode == SkXfermode::kScreen_Mode) { | 714 if (use_blend_equation_advanced_) { |
| 713 GLC(gl_, gl_->BlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ONE)); | 715 GLenum equation = GL_SRC_OVER_NV; |
| 714 } else if (blend_mode == SkXfermode::kLighten_Mode) { | 716 |
| 715 GLC(gl_, gl_->BlendFunc(GL_ONE, GL_ONE)); | 717 switch (blend_mode) { |
| 716 GLC(gl_, gl_->BlendEquation(GL_MAX_EXT)); | 718 case SkXfermode::kScreen_Mode: |
|
piman
2014/10/16 20:13:28
nit: indent style (run git cl format?)
Erik Dahlström (inactive)
2014/10/17 15:33:17
Done.
| |
| 719 equation = GL_SCREEN_NV; | |
| 720 break; | |
| 721 case SkXfermode::kOverlay_Mode: | |
| 722 equation = GL_OVERLAY_NV; | |
| 723 break; | |
| 724 case SkXfermode::kDarken_Mode: | |
| 725 equation = GL_DARKEN_NV; | |
| 726 break; | |
| 727 case SkXfermode::kLighten_Mode: | |
| 728 equation = GL_LIGHTEN_NV; | |
| 729 break; | |
| 730 case SkXfermode::kColorDodge_Mode: | |
| 731 equation = GL_COLORDODGE_NV; | |
| 732 break; | |
| 733 case SkXfermode::kColorBurn_Mode: | |
| 734 equation = GL_COLORBURN_NV; | |
| 735 break; | |
| 736 case SkXfermode::kHardLight_Mode: | |
| 737 equation = GL_HARDLIGHT_NV; | |
| 738 break; | |
| 739 case SkXfermode::kSoftLight_Mode: | |
| 740 equation = GL_SOFTLIGHT_NV; | |
| 741 break; | |
| 742 case SkXfermode::kDifference_Mode: | |
| 743 equation = GL_DIFFERENCE_NV; | |
| 744 break; | |
| 745 case SkXfermode::kExclusion_Mode: | |
| 746 equation = GL_EXCLUSION_NV; | |
| 747 break; | |
| 748 case SkXfermode::kMultiply_Mode: | |
| 749 equation = GL_MULTIPLY_NV; | |
| 750 break; | |
| 751 case SkXfermode::kHue_Mode: | |
| 752 equation = GL_HSL_HUE_NV; | |
| 753 break; | |
| 754 case SkXfermode::kSaturation_Mode: | |
| 755 equation = GL_HSL_SATURATION_NV; | |
| 756 break; | |
| 757 case SkXfermode::kColor_Mode: | |
| 758 equation = GL_HSL_COLOR_NV; | |
| 759 break; | |
| 760 case SkXfermode::kLuminosity_Mode: | |
| 761 equation = GL_HSL_LUMINOSITY_NV; | |
| 762 break; | |
| 763 default: | |
| 764 return; | |
| 765 } | |
| 766 | |
| 767 GLC(gl_, gl_->BlendEquation(equation)); | |
| 768 } else { | |
| 769 if (blend_mode == SkXfermode::kScreen_Mode) { | |
| 770 GLC(gl_, gl_->BlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ONE)); | |
| 771 } else if (blend_mode == SkXfermode::kLighten_Mode) { | |
| 772 GLC(gl_, gl_->BlendFunc(GL_ONE, GL_ONE)); | |
| 773 GLC(gl_, gl_->BlendEquation(GL_MAX_EXT)); | |
| 774 } | |
| 717 } | 775 } |
| 718 } | 776 } |
| 719 | 777 |
| 720 void GLRenderer::RestoreBlendFuncToDefault(SkXfermode::Mode blend_mode) { | 778 void GLRenderer::RestoreBlendFuncToDefault(SkXfermode::Mode blend_mode) { |
| 721 if (blend_mode == SkXfermode::kSrcOver_Mode) | 779 if (blend_mode == SkXfermode::kSrcOver_Mode) |
| 722 return; | 780 return; |
| 723 | 781 |
| 724 GLC(gl_, gl_->BlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); | 782 if (use_blend_equation_advanced_) { |
| 783 GLC(gl_, gl_->BlendEquation(GL_FUNC_ADD)); | |
| 784 } else { | |
| 785 GLC(gl_, gl_->BlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); | |
| 725 | 786 |
| 726 if (blend_mode == SkXfermode::kLighten_Mode) | 787 if (blend_mode == SkXfermode::kLighten_Mode) |
| 727 GLC(gl_, gl_->BlendEquation(GL_FUNC_ADD)); | 788 GLC(gl_, gl_->BlendEquation(GL_FUNC_ADD)); |
| 789 } | |
| 728 } | 790 } |
| 729 | 791 |
| 730 static skia::RefPtr<SkImage> ApplyBlendModeWithBackdrop( | 792 static skia::RefPtr<SkImage> ApplyBlendModeWithBackdrop( |
| 731 scoped_ptr<GLRenderer::ScopedUseGrContext> use_gr_context, | 793 scoped_ptr<GLRenderer::ScopedUseGrContext> use_gr_context, |
| 732 ResourceProvider* resource_provider, | 794 ResourceProvider* resource_provider, |
| 733 skia::RefPtr<SkImage> source_bitmap_with_filters, | 795 skia::RefPtr<SkImage> source_bitmap_with_filters, |
| 734 ScopedResource* source_texture_resource, | 796 ScopedResource* source_texture_resource, |
| 735 ScopedResource* background_texture_resource, | 797 ScopedResource* background_texture_resource, |
| 736 SkXfermode::Mode blend_mode) { | 798 SkXfermode::Mode blend_mode) { |
| 737 if (!use_gr_context) | 799 if (!use_gr_context) |
| (...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1187 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_)); | 1249 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_)); |
| 1188 gl_->BindTexture(GL_TEXTURE_2D, texture->getTextureHandle()); | 1250 gl_->BindTexture(GL_TEXTURE_2D, texture->getTextureHandle()); |
| 1189 } else { | 1251 } else { |
| 1190 contents_resource_lock = | 1252 contents_resource_lock = |
| 1191 make_scoped_ptr(new ResourceProvider::ScopedSamplerGL( | 1253 make_scoped_ptr(new ResourceProvider::ScopedSamplerGL( |
| 1192 resource_provider_, contents_texture->id(), GL_LINEAR)); | 1254 resource_provider_, contents_texture->id(), GL_LINEAR)); |
| 1193 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), | 1255 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), |
| 1194 contents_resource_lock->target()); | 1256 contents_resource_lock->target()); |
| 1195 } | 1257 } |
| 1196 | 1258 |
| 1197 if (CanApplyBlendModeUsingBlendFunc(blend_mode)) | 1259 if (CanApplyBlendModeUsingBlendFunc(blend_mode)) { |
| 1198 ApplyBlendModeUsingBlendFunc(blend_mode); | 1260 if (use_blend_equation_advanced_) |
| 1261 GLC(gl_, gl_->BlendBarrierNV()); | |
|
piman
2014/10/16 20:13:29
Is it worth skipping this if we have GL_*_blend_eq
Erik Dahlström (inactive)
2014/10/17 15:33:17
Perhaps, my current card/driver setup doesn't supp
| |
| 1262 | |
| 1263 ApplyBlendModeUsingBlendFunc(blend_mode); | |
| 1264 } | |
| 1199 | 1265 |
| 1200 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( | 1266 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( |
| 1201 gl_, | 1267 gl_, |
| 1202 &highp_threshold_cache_, | 1268 &highp_threshold_cache_, |
| 1203 highp_threshold_min_, | 1269 highp_threshold_min_, |
| 1204 quad->shared_quad_state->visible_content_rect.bottom_right()); | 1270 quad->shared_quad_state->visible_content_rect.bottom_right()); |
| 1205 | 1271 |
| 1206 int shader_quad_location = -1; | 1272 int shader_quad_location = -1; |
| 1207 int shader_edge_location = -1; | 1273 int shader_edge_location = -1; |
| 1208 int shader_viewport_location = -1; | 1274 int shader_viewport_location = -1; |
| (...skipping 2074 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3283 context_support_->ScheduleOverlayPlane( | 3349 context_support_->ScheduleOverlayPlane( |
| 3284 overlay.plane_z_order, | 3350 overlay.plane_z_order, |
| 3285 overlay.transform, | 3351 overlay.transform, |
| 3286 pending_overlay_resources_.back()->texture_id(), | 3352 pending_overlay_resources_.back()->texture_id(), |
| 3287 overlay.display_rect, | 3353 overlay.display_rect, |
| 3288 overlay.uv_rect); | 3354 overlay.uv_rect); |
| 3289 } | 3355 } |
| 3290 } | 3356 } |
| 3291 | 3357 |
| 3292 } // namespace cc | 3358 } // namespace cc |
| OLD | NEW |