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