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 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 | 368 |
369 capabilities_.using_image = context_caps.gpu.image; | 369 capabilities_.using_image = context_caps.gpu.image; |
370 | 370 |
371 capabilities_.using_discard_framebuffer = | 371 capabilities_.using_discard_framebuffer = |
372 context_caps.gpu.discard_framebuffer; | 372 context_caps.gpu.discard_framebuffer; |
373 | 373 |
374 capabilities_.allow_rasterize_on_demand = true; | 374 capabilities_.allow_rasterize_on_demand = true; |
375 | 375 |
376 use_sync_query_ = context_caps.gpu.sync_query; | 376 use_sync_query_ = context_caps.gpu.sync_query; |
377 use_blend_minmax_ = context_caps.gpu.blend_minmax; | 377 use_blend_minmax_ = context_caps.gpu.blend_minmax; |
| 378 use_blend_equation_advanced_ = context_caps.gpu.blend_equation_advanced; |
| 379 use_blend_equation_advanced_coherent_ = |
| 380 context_caps.gpu.blend_equation_advanced_coherent; |
378 | 381 |
379 InitializeSharedObjects(); | 382 InitializeSharedObjects(); |
380 } | 383 } |
381 | 384 |
382 GLRenderer::~GLRenderer() { | 385 GLRenderer::~GLRenderer() { |
383 while (!pending_async_read_pixels_.empty()) { | 386 while (!pending_async_read_pixels_.empty()) { |
384 PendingAsyncReadPixels* pending_read = pending_async_read_pixels_.back(); | 387 PendingAsyncReadPixels* pending_read = pending_async_read_pixels_.back(); |
385 pending_read->finished_read_pixels_callback.Cancel(); | 388 pending_read->finished_read_pixels_callback.Cancel(); |
386 pending_async_read_pixels_.pop_back(); | 389 pending_async_read_pixels_.pop_back(); |
387 } | 390 } |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
728 | 731 |
729 // Flush the GrContext to ensure all buffered GL calls are drawn to the | 732 // Flush the GrContext to ensure all buffered GL calls are drawn to the |
730 // backing store before we access and return it, and have cc begin using the | 733 // backing store before we access and return it, and have cc begin using the |
731 // GL context again. | 734 // GL context again. |
732 canvas->flush(); | 735 canvas->flush(); |
733 | 736 |
734 return image; | 737 return image; |
735 } | 738 } |
736 | 739 |
737 bool GLRenderer::CanApplyBlendModeUsingBlendFunc(SkXfermode::Mode blend_mode) { | 740 bool GLRenderer::CanApplyBlendModeUsingBlendFunc(SkXfermode::Mode blend_mode) { |
738 return (use_blend_minmax_ && blend_mode == SkXfermode::kLighten_Mode) || | 741 return use_blend_equation_advanced_ || |
| 742 (use_blend_minmax_ && blend_mode == SkXfermode::kLighten_Mode) || |
739 blend_mode == SkXfermode::kScreen_Mode || | 743 blend_mode == SkXfermode::kScreen_Mode || |
740 blend_mode == SkXfermode::kSrcOver_Mode; | 744 blend_mode == SkXfermode::kSrcOver_Mode; |
741 } | 745 } |
742 | 746 |
743 void GLRenderer::ApplyBlendModeUsingBlendFunc(SkXfermode::Mode blend_mode) { | 747 void GLRenderer::ApplyBlendModeUsingBlendFunc(SkXfermode::Mode blend_mode) { |
744 DCHECK(CanApplyBlendModeUsingBlendFunc(blend_mode)); | 748 DCHECK(CanApplyBlendModeUsingBlendFunc(blend_mode)); |
745 | 749 |
746 // Any modes set here must be reset in RestoreBlendFuncToDefault | 750 // Any modes set here must be reset in RestoreBlendFuncToDefault |
747 if (blend_mode == SkXfermode::kScreen_Mode) { | 751 if (use_blend_equation_advanced_) { |
748 GLC(gl_, gl_->BlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ONE)); | 752 GLenum equation = GL_FUNC_ADD; |
749 } else if (blend_mode == SkXfermode::kLighten_Mode) { | 753 |
750 GLC(gl_, gl_->BlendFunc(GL_ONE, GL_ONE)); | 754 switch (blend_mode) { |
751 GLC(gl_, gl_->BlendEquation(GL_MAX_EXT)); | 755 case SkXfermode::kScreen_Mode: |
| 756 equation = GL_SCREEN_KHR; |
| 757 break; |
| 758 case SkXfermode::kOverlay_Mode: |
| 759 equation = GL_OVERLAY_KHR; |
| 760 break; |
| 761 case SkXfermode::kDarken_Mode: |
| 762 equation = GL_DARKEN_KHR; |
| 763 break; |
| 764 case SkXfermode::kLighten_Mode: |
| 765 equation = GL_LIGHTEN_KHR; |
| 766 break; |
| 767 case SkXfermode::kColorDodge_Mode: |
| 768 equation = GL_COLORDODGE_KHR; |
| 769 break; |
| 770 case SkXfermode::kColorBurn_Mode: |
| 771 equation = GL_COLORBURN_KHR; |
| 772 break; |
| 773 case SkXfermode::kHardLight_Mode: |
| 774 equation = GL_HARDLIGHT_KHR; |
| 775 break; |
| 776 case SkXfermode::kSoftLight_Mode: |
| 777 equation = GL_SOFTLIGHT_KHR; |
| 778 break; |
| 779 case SkXfermode::kDifference_Mode: |
| 780 equation = GL_DIFFERENCE_KHR; |
| 781 break; |
| 782 case SkXfermode::kExclusion_Mode: |
| 783 equation = GL_EXCLUSION_KHR; |
| 784 break; |
| 785 case SkXfermode::kMultiply_Mode: |
| 786 equation = GL_MULTIPLY_KHR; |
| 787 break; |
| 788 case SkXfermode::kHue_Mode: |
| 789 equation = GL_HSL_HUE_KHR; |
| 790 break; |
| 791 case SkXfermode::kSaturation_Mode: |
| 792 equation = GL_HSL_SATURATION_KHR; |
| 793 break; |
| 794 case SkXfermode::kColor_Mode: |
| 795 equation = GL_HSL_COLOR_KHR; |
| 796 break; |
| 797 case SkXfermode::kLuminosity_Mode: |
| 798 equation = GL_HSL_LUMINOSITY_KHR; |
| 799 break; |
| 800 default: |
| 801 return; |
| 802 } |
| 803 |
| 804 GLC(gl_, gl_->BlendEquation(equation)); |
| 805 } else { |
| 806 if (blend_mode == SkXfermode::kScreen_Mode) { |
| 807 GLC(gl_, gl_->BlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ONE)); |
| 808 } else if (blend_mode == SkXfermode::kLighten_Mode) { |
| 809 GLC(gl_, gl_->BlendFunc(GL_ONE, GL_ONE)); |
| 810 GLC(gl_, gl_->BlendEquation(GL_MAX_EXT)); |
| 811 } |
752 } | 812 } |
753 } | 813 } |
754 | 814 |
755 void GLRenderer::RestoreBlendFuncToDefault(SkXfermode::Mode blend_mode) { | 815 void GLRenderer::RestoreBlendFuncToDefault(SkXfermode::Mode blend_mode) { |
756 if (blend_mode == SkXfermode::kSrcOver_Mode) | 816 if (blend_mode == SkXfermode::kSrcOver_Mode) |
757 return; | 817 return; |
758 | 818 |
759 GLC(gl_, gl_->BlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); | 819 if (use_blend_equation_advanced_) { |
| 820 GLC(gl_, gl_->BlendEquation(GL_FUNC_ADD)); |
| 821 } else { |
| 822 GLC(gl_, gl_->BlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); |
760 | 823 |
761 if (blend_mode == SkXfermode::kLighten_Mode) | 824 if (blend_mode == SkXfermode::kLighten_Mode) |
762 GLC(gl_, gl_->BlendEquation(GL_FUNC_ADD)); | 825 GLC(gl_, gl_->BlendEquation(GL_FUNC_ADD)); |
| 826 } |
763 } | 827 } |
764 | 828 |
765 bool GLRenderer::ShouldApplyBackgroundFilters(DrawingFrame* frame, | 829 bool GLRenderer::ShouldApplyBackgroundFilters(DrawingFrame* frame, |
766 const RenderPassDrawQuad* quad) { | 830 const RenderPassDrawQuad* quad) { |
767 if (quad->background_filters.IsEmpty()) | 831 if (quad->background_filters.IsEmpty()) |
768 return false; | 832 return false; |
769 | 833 |
770 // TODO(danakj): We only allow background filters on an opaque render surface | 834 // TODO(danakj): We only allow background filters on an opaque render surface |
771 // because other surfaces may contain translucent pixels, and the contents | 835 // because other surfaces may contain translucent pixels, and the contents |
772 // behind those translucent pixels wouldn't have the filter applied. | 836 // behind those translucent pixels wouldn't have the filter applied. |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1088 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_)); | 1152 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_)); |
1089 gl_->BindTexture(GL_TEXTURE_2D, texture->getTextureHandle()); | 1153 gl_->BindTexture(GL_TEXTURE_2D, texture->getTextureHandle()); |
1090 } else { | 1154 } else { |
1091 contents_resource_lock = | 1155 contents_resource_lock = |
1092 make_scoped_ptr(new ResourceProvider::ScopedSamplerGL( | 1156 make_scoped_ptr(new ResourceProvider::ScopedSamplerGL( |
1093 resource_provider_, contents_texture->id(), GL_LINEAR)); | 1157 resource_provider_, contents_texture->id(), GL_LINEAR)); |
1094 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), | 1158 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), |
1095 contents_resource_lock->target()); | 1159 contents_resource_lock->target()); |
1096 } | 1160 } |
1097 | 1161 |
1098 if (CanApplyBlendModeUsingBlendFunc(blend_mode)) | 1162 if (CanApplyBlendModeUsingBlendFunc(blend_mode)) { |
| 1163 if (!use_blend_equation_advanced_coherent_ && use_blend_equation_advanced_) |
| 1164 GLC(gl_, gl_->BlendBarrierKHR()); |
| 1165 |
1099 ApplyBlendModeUsingBlendFunc(blend_mode); | 1166 ApplyBlendModeUsingBlendFunc(blend_mode); |
| 1167 } |
1100 | 1168 |
1101 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( | 1169 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( |
1102 gl_, | 1170 gl_, |
1103 &highp_threshold_cache_, | 1171 &highp_threshold_cache_, |
1104 highp_threshold_min_, | 1172 highp_threshold_min_, |
1105 quad->shared_quad_state->visible_content_rect.bottom_right()); | 1173 quad->shared_quad_state->visible_content_rect.bottom_right()); |
1106 | 1174 |
1107 int shader_quad_location = -1; | 1175 int shader_quad_location = -1; |
1108 int shader_edge_location = -1; | 1176 int shader_edge_location = -1; |
1109 int shader_viewport_location = -1; | 1177 int shader_viewport_location = -1; |
(...skipping 2180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3290 context_support_->ScheduleOverlayPlane( | 3358 context_support_->ScheduleOverlayPlane( |
3291 overlay.plane_z_order, | 3359 overlay.plane_z_order, |
3292 overlay.transform, | 3360 overlay.transform, |
3293 pending_overlay_resources_.back()->texture_id(), | 3361 pending_overlay_resources_.back()->texture_id(), |
3294 overlay.display_rect, | 3362 overlay.display_rect, |
3295 overlay.uv_rect); | 3363 overlay.uv_rect); |
3296 } | 3364 } |
3297 } | 3365 } |
3298 | 3366 |
3299 } // namespace cc | 3367 } // namespace cc |
OLD | NEW |