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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 // Parameters needed to draw a RenderPassDrawQuad. | 154 // Parameters needed to draw a RenderPassDrawQuad. |
155 struct DrawRenderPassDrawQuadParams { | 155 struct DrawRenderPassDrawQuadParams { |
156 DrawRenderPassDrawQuadParams() {} | 156 DrawRenderPassDrawQuadParams() {} |
157 ~DrawRenderPassDrawQuadParams() {} | 157 ~DrawRenderPassDrawQuadParams() {} |
158 | 158 |
159 // Required Inputs. | 159 // Required Inputs. |
160 const RenderPassDrawQuad* quad = nullptr; | 160 const RenderPassDrawQuad* quad = nullptr; |
161 const Resource* contents_texture = nullptr; | 161 const Resource* contents_texture = nullptr; |
162 const gfx::QuadF* clip_region = nullptr; | 162 const gfx::QuadF* clip_region = nullptr; |
163 bool flip_texture = false; | 163 bool flip_texture = false; |
164 | |
165 gfx::Transform window_matrix; | 164 gfx::Transform window_matrix; |
166 gfx::Transform projection_matrix; | 165 gfx::Transform projection_matrix; |
| 166 gfx::Transform quad_to_target_transform; |
167 | 167 |
168 // |frame| is needed for background effects. | 168 // |frame| is only used for background effects. |
169 DirectRenderer::DrawingFrame* frame = nullptr; | 169 DirectRenderer::DrawingFrame* frame = nullptr; |
170 | 170 |
171 // Whether the texture to be sampled from needs to be flipped. | 171 // Whether the texture to be sampled from needs to be flipped. |
172 bool source_needs_flip = false; | 172 bool source_needs_flip = false; |
173 | 173 |
174 float edge[24]; | 174 float edge[24]; |
175 SkScalar color_matrix[20]; | 175 SkScalar color_matrix[20]; |
176 | 176 |
177 // Blending refers to modifications to the backdrop. | 177 // Blending refers to modifications to the backdrop. |
178 bool use_shaders_for_blending = false; | 178 bool use_shaders_for_blending = false; |
(...skipping 30 matching lines...) Expand all Loading... |
209 GLuint background_image_id = 0; | 209 GLuint background_image_id = 0; |
210 | 210 |
211 // Whether the original background texture is needed for the mask. | 211 // Whether the original background texture is needed for the mask. |
212 bool mask_for_background = false; | 212 bool mask_for_background = false; |
213 | 213 |
214 // Whether a color matrix needs to be applied by the shaders when drawing | 214 // Whether a color matrix needs to be applied by the shaders when drawing |
215 // the RPDQ. | 215 // the RPDQ. |
216 bool use_color_matrix = false; | 216 bool use_color_matrix = false; |
217 | 217 |
218 gfx::QuadF surface_quad; | 218 gfx::QuadF surface_quad; |
| 219 |
219 gfx::Transform contents_device_transform; | 220 gfx::Transform contents_device_transform; |
220 }; | 221 }; |
221 | 222 |
222 static GLint GetActiveTextureUnit(GLES2Interface* gl) { | 223 static GLint GetActiveTextureUnit(GLES2Interface* gl) { |
223 GLint active_unit = 0; | 224 GLint active_unit = 0; |
224 gl->GetIntegerv(GL_ACTIVE_TEXTURE, &active_unit); | 225 gl->GetIntegerv(GL_ACTIVE_TEXTURE, &active_unit); |
225 return active_unit; | 226 return active_unit; |
226 } | 227 } |
227 | 228 |
228 class GLRenderer::ScopedUseGrContext { | 229 class GLRenderer::ScopedUseGrContext { |
(...skipping 833 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1062 // See above comments about texture flipping. When the input is a | 1063 // See above comments about texture flipping. When the input is a |
1063 // render pass, it needs to an extra flip to be oriented correctly. | 1064 // render pass, it needs to an extra flip to be oriented correctly. |
1064 params.flip_texture = true; | 1065 params.flip_texture = true; |
1065 params.contents_texture = contents_texture; | 1066 params.contents_texture = contents_texture; |
1066 DrawRenderPassQuadInternal(¶ms); | 1067 DrawRenderPassQuadInternal(¶ms); |
1067 } | 1068 } |
1068 } | 1069 } |
1069 | 1070 |
1070 void GLRenderer::DrawRenderPassQuadInternal( | 1071 void GLRenderer::DrawRenderPassQuadInternal( |
1071 DrawRenderPassDrawQuadParams* params) { | 1072 DrawRenderPassDrawQuadParams* params) { |
| 1073 params->quad_to_target_transform = |
| 1074 params->quad->shared_quad_state->quad_to_target_transform; |
1072 if (!InitializeRPDQParameters(params)) | 1075 if (!InitializeRPDQParameters(params)) |
1073 return; | 1076 return; |
1074 UpdateRPDQShadersForBlending(params); | 1077 UpdateRPDQShadersForBlending(params); |
1075 if (!UpdateRPDQWithSkiaFilters(params)) | 1078 if (!UpdateRPDQWithSkiaFilters(params)) |
1076 return; | 1079 return; |
1077 UseRenderPass(params->frame, params->frame->current_render_pass); | 1080 UseRenderPass(params->frame, params->frame->current_render_pass); |
1078 SetViewport(); | 1081 SetViewport(); |
1079 UpdateRPDQTexturesForSampling(params); | 1082 UpdateRPDQTexturesForSampling(params); |
1080 UpdateRPDQBlendMode(params); | 1083 UpdateRPDQBlendMode(params); |
1081 ChooseRPDQProgram(params); | 1084 ChooseRPDQProgram(params); |
1082 UpdateRPDQUniforms(params); | 1085 UpdateRPDQUniforms(params); |
1083 DrawRPDQ(*params); | 1086 DrawRPDQ(*params); |
1084 } | 1087 } |
1085 | 1088 |
1086 bool GLRenderer::InitializeRPDQParameters( | 1089 bool GLRenderer::InitializeRPDQParameters( |
1087 DrawRenderPassDrawQuadParams* params) { | 1090 DrawRenderPassDrawQuadParams* params) { |
1088 const RenderPassDrawQuad* quad = params->quad; | 1091 const RenderPassDrawQuad* quad = params->quad; |
1089 SkMatrix scale_matrix; | 1092 SkMatrix scale_matrix; |
1090 scale_matrix.setScale(quad->filters_scale.x(), quad->filters_scale.y()); | 1093 scale_matrix.setScale(quad->filters_scale.x(), quad->filters_scale.y()); |
1091 gfx::Rect dst_rect = quad->filters.MapRect(quad->rect, scale_matrix); | 1094 gfx::Rect dst_rect = quad->filters.MapRect(quad->rect, scale_matrix); |
1092 params->dst_rect.SetRect(static_cast<float>(dst_rect.x()), | 1095 params->dst_rect.SetRect(static_cast<float>(dst_rect.x()), |
1093 static_cast<float>(dst_rect.y()), | 1096 static_cast<float>(dst_rect.y()), |
1094 static_cast<float>(dst_rect.width()), | 1097 static_cast<float>(dst_rect.width()), |
1095 static_cast<float>(dst_rect.height())); | 1098 static_cast<float>(dst_rect.height())); |
1096 gfx::Transform quad_rect_matrix; | 1099 gfx::Transform quad_rect_matrix; |
1097 QuadRectTransform(&quad_rect_matrix, | 1100 QuadRectTransform(&quad_rect_matrix, params->quad_to_target_transform, |
1098 quad->shared_quad_state->quad_to_target_transform, | |
1099 params->dst_rect); | 1101 params->dst_rect); |
1100 params->contents_device_transform = | 1102 params->contents_device_transform = |
1101 params->window_matrix * params->projection_matrix * quad_rect_matrix; | 1103 params->window_matrix * params->projection_matrix * quad_rect_matrix; |
1102 params->contents_device_transform.FlattenTo2d(); | 1104 params->contents_device_transform.FlattenTo2d(); |
1103 | 1105 |
1104 // Can only draw surface if device matrix is invertible. | 1106 // Can only draw surface if device matrix is invertible. |
1105 if (!params->contents_device_transform.IsInvertible()) | 1107 if (!params->contents_device_transform.IsInvertible()) |
1106 return false; | 1108 return false; |
1107 | 1109 |
1108 params->surface_quad = SharedGeometryQuad(); | 1110 params->surface_quad = SharedGeometryQuad(); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1211 // locally in the compositor and process the rest of the DAG (if any) | 1213 // locally in the compositor and process the rest of the DAG (if any) |
1212 // in Skia. | 1214 // in Skia. |
1213 params->use_color_matrix = true; | 1215 params->use_color_matrix = true; |
1214 filter = sk_ref_sp(filter->getInput(0)); | 1216 filter = sk_ref_sp(filter->getInput(0)); |
1215 } | 1217 } |
1216 if (filter) { | 1218 if (filter) { |
1217 gfx::Rect clip_rect = quad->shared_quad_state->clip_rect; | 1219 gfx::Rect clip_rect = quad->shared_quad_state->clip_rect; |
1218 if (clip_rect.IsEmpty()) { | 1220 if (clip_rect.IsEmpty()) { |
1219 clip_rect = current_draw_rect_; | 1221 clip_rect = current_draw_rect_; |
1220 } | 1222 } |
1221 gfx::Transform transform = | 1223 gfx::Transform transform = params->quad_to_target_transform; |
1222 quad->shared_quad_state->quad_to_target_transform; | |
1223 gfx::QuadF clip_quad = gfx::QuadF(gfx::RectF(clip_rect)); | 1224 gfx::QuadF clip_quad = gfx::QuadF(gfx::RectF(clip_rect)); |
1224 gfx::QuadF local_clip = MapQuadToLocalSpace(transform, clip_quad); | 1225 gfx::QuadF local_clip = MapQuadToLocalSpace(transform, clip_quad); |
1225 params->dst_rect.Intersect(local_clip.BoundingBox()); | 1226 params->dst_rect.Intersect(local_clip.BoundingBox()); |
1226 // If we've been fully clipped out (by crop rect or clipping), there's | 1227 // If we've been fully clipped out (by crop rect or clipping), there's |
1227 // nothing to draw. | 1228 // nothing to draw. |
1228 if (params->dst_rect.IsEmpty()) { | 1229 if (params->dst_rect.IsEmpty()) { |
1229 return false; | 1230 return false; |
1230 } | 1231 } |
1231 SkIPoint offset; | 1232 SkIPoint offset; |
1232 SkIRect subset; | 1233 SkIRect subset; |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1493 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), | 1494 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), |
1494 params->shader_background_sampler_lock->target()); | 1495 params->shader_background_sampler_lock->target()); |
1495 } | 1496 } |
1496 } | 1497 } |
1497 | 1498 |
1498 SetShaderOpacity(params->quad->shared_quad_state->opacity, locations.alpha); | 1499 SetShaderOpacity(params->quad->shared_quad_state->opacity, locations.alpha); |
1499 SetShaderQuadF(params->surface_quad, locations.quad); | 1500 SetShaderQuadF(params->surface_quad, locations.quad); |
1500 } | 1501 } |
1501 | 1502 |
1502 void GLRenderer::DrawRPDQ(const DrawRenderPassDrawQuadParams& params) { | 1503 void GLRenderer::DrawRPDQ(const DrawRenderPassDrawQuadParams& params) { |
1503 DrawQuadGeometry(params.projection_matrix, | 1504 DrawQuadGeometry(params.projection_matrix, params.quad_to_target_transform, |
1504 params.quad->shared_quad_state->quad_to_target_transform, | |
1505 params.dst_rect, params.locations.matrix); | 1505 params.dst_rect, params.locations.matrix); |
1506 | 1506 |
1507 // Flush the compositor context before the filter bitmap goes out of | 1507 // Flush the compositor context before the filter bitmap goes out of |
1508 // scope, so the draw gets processed before the filter texture gets deleted. | 1508 // scope, so the draw gets processed before the filter texture gets deleted. |
1509 if (params.filter_image) | 1509 if (params.filter_image) |
1510 gl_->Flush(); | 1510 gl_->Flush(); |
1511 | 1511 |
1512 if (!params.use_shaders_for_blending) | 1512 if (!params.use_shaders_for_blending) |
1513 RestoreBlendFuncToDefault(params.quad->shared_quad_state->blend_mode); | 1513 RestoreBlendFuncToDefault(params.quad->shared_quad_state->blend_mode); |
1514 } | 1514 } |
(...skipping 1207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2722 | 2722 |
2723 ScheduleCALayers(frame); | 2723 ScheduleCALayers(frame); |
2724 ScheduleOverlays(frame); | 2724 ScheduleOverlays(frame); |
2725 } | 2725 } |
2726 | 2726 |
2727 void GLRenderer::FinishDrawingQuadList() { | 2727 void GLRenderer::FinishDrawingQuadList() { |
2728 FlushTextureQuadCache(SHARED_BINDING); | 2728 FlushTextureQuadCache(SHARED_BINDING); |
2729 } | 2729 } |
2730 | 2730 |
2731 bool GLRenderer::FlippedFramebuffer(const DrawingFrame* frame) const { | 2731 bool GLRenderer::FlippedFramebuffer(const DrawingFrame* frame) const { |
| 2732 if (force_drawing_frame_framebuffer_unflipped_) |
| 2733 return false; |
2732 if (frame->current_render_pass != frame->root_render_pass) | 2734 if (frame->current_render_pass != frame->root_render_pass) |
2733 return true; | 2735 return true; |
2734 return FlippedRootFramebuffer(); | 2736 return FlippedRootFramebuffer(); |
2735 } | 2737 } |
2736 | 2738 |
2737 bool GLRenderer::FlippedRootFramebuffer() const { | 2739 bool GLRenderer::FlippedRootFramebuffer() const { |
2738 // GL is normally flipped, so a flipped output results in an unflipping. | 2740 // GL is normally flipped, so a flipped output results in an unflipping. |
2739 return !output_surface_->capabilities().flipped_output_surface; | 2741 return !output_surface_->capabilities().flipped_output_surface; |
2740 } | 2742 } |
2741 | 2743 |
(...skipping 1029 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3771 } | 3773 } |
3772 | 3774 |
3773 bool GLRenderer::IsContextLost() { | 3775 bool GLRenderer::IsContextLost() { |
3774 return gl_->GetGraphicsResetStatusKHR() != GL_NO_ERROR; | 3776 return gl_->GetGraphicsResetStatusKHR() != GL_NO_ERROR; |
3775 } | 3777 } |
3776 | 3778 |
3777 void GLRenderer::ScheduleCALayers(DrawingFrame* frame) { | 3779 void GLRenderer::ScheduleCALayers(DrawingFrame* frame) { |
3778 scoped_refptr<CALayerOverlaySharedState> shared_state; | 3780 scoped_refptr<CALayerOverlaySharedState> shared_state; |
3779 size_t copied_render_pass_count = 0; | 3781 size_t copied_render_pass_count = 0; |
3780 for (const CALayerOverlay& ca_layer_overlay : frame->ca_layer_overlay_list) { | 3782 for (const CALayerOverlay& ca_layer_overlay : frame->ca_layer_overlay_list) { |
3781 if (!overlay_resource_pool_) { | 3783 if (ca_layer_overlay.rpdq) { |
3782 overlay_resource_pool_ = ResourcePool::CreateForGpuMemoryBufferResources( | 3784 ScheduleRenderPassDrawQuad(&ca_layer_overlay, frame); |
3783 resource_provider_, base::ThreadTaskRunnerHandle::Get().get(), | 3785 shared_state = nullptr; |
3784 gfx::BufferUsage::SCANOUT); | 3786 ++copied_render_pass_count; |
| 3787 continue; |
3785 } | 3788 } |
3786 | 3789 |
3787 ResourceId contents_resource_id = ca_layer_overlay.contents_resource_id; | 3790 ResourceId contents_resource_id = ca_layer_overlay.contents_resource_id; |
3788 unsigned texture_id = 0; | 3791 unsigned texture_id = 0; |
3789 if (contents_resource_id) { | 3792 if (contents_resource_id) { |
3790 pending_overlay_resources_.push_back( | 3793 pending_overlay_resources_.push_back( |
3791 base::WrapUnique(new ResourceProvider::ScopedReadLockGL( | 3794 base::WrapUnique(new ResourceProvider::ScopedReadLockGL( |
3792 resource_provider_, contents_resource_id))); | 3795 resource_provider_, contents_resource_id))); |
3793 texture_id = pending_overlay_resources_.back()->texture_id(); | 3796 texture_id = pending_overlay_resources_.back()->texture_id(); |
3794 } | 3797 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3848 resource_provider_, overlay.resource_id))); | 3851 resource_provider_, overlay.resource_id))); |
3849 texture_id = pending_overlay_resources_.back()->texture_id(); | 3852 texture_id = pending_overlay_resources_.back()->texture_id(); |
3850 } | 3853 } |
3851 | 3854 |
3852 context_support_->ScheduleOverlayPlane( | 3855 context_support_->ScheduleOverlayPlane( |
3853 overlay.plane_z_order, overlay.transform, texture_id, | 3856 overlay.plane_z_order, overlay.transform, texture_id, |
3854 ToNearestRect(overlay.display_rect), overlay.uv_rect); | 3857 ToNearestRect(overlay.display_rect), overlay.uv_rect); |
3855 } | 3858 } |
3856 } | 3859 } |
3857 | 3860 |
| 3861 // This function draws the RenderPassDrawQuad into a temporary |
| 3862 // texture/framebuffer, and then copies the result into an IOSurface. The |
| 3863 // inefficient (but simple) way to do this would be to: |
| 3864 // 1. Allocate a framebuffer the size of the screen. |
| 3865 // 2. Draw using all the normal RPDQ draw logic. |
| 3866 // |
| 3867 // Instead, this method does the following: |
| 3868 // 1. Configure parameters as if drawing to a framebuffer the size of the |
| 3869 // screen. This reuses most of the RPDQ draw logic. |
| 3870 // 2. Update parameters to draw into a framebuffer only as large as needed. |
| 3871 // 3. Fix shader uniforms that were broken by (2). |
| 3872 // |
| 3873 // Then: |
| 3874 // 4. Allocate an IOSurface as the drawing destination. |
| 3875 // 5. Draw the RPDQ. |
| 3876 void GLRenderer::CopyRenderPassDrawQuadToOverlayResource( |
| 3877 const CALayerOverlay* ca_layer_overlay, |
| 3878 Resource** resource, |
| 3879 DrawingFrame* external_frame, |
| 3880 gfx::RectF* new_bounds) { |
| 3881 ScopedResource* contents_texture = |
| 3882 render_pass_textures_[ca_layer_overlay->rpdq->render_pass_id].get(); |
| 3883 DCHECK(contents_texture); |
| 3884 |
| 3885 // Configure parameters as if drawing to a framebuffer the size of the |
| 3886 // screen. |
| 3887 DrawRenderPassDrawQuadParams params; |
| 3888 params.quad = ca_layer_overlay->rpdq; |
| 3889 params.flip_texture = true; |
| 3890 params.contents_texture = contents_texture; |
| 3891 params.quad_to_target_transform = |
| 3892 params.quad->shared_quad_state->quad_to_target_transform; |
| 3893 |
| 3894 // Calculate projection and window matrices using InitializeViewport(). This |
| 3895 // requires creating a dummy DrawingFrame. |
| 3896 { |
| 3897 DrawingFrame frame; |
| 3898 gfx::Rect frame_rect = external_frame->device_viewport_rect; |
| 3899 force_drawing_frame_framebuffer_unflipped_ = true; |
| 3900 InitializeViewport(&frame, frame_rect, frame_rect, frame_rect.size()); |
| 3901 force_drawing_frame_framebuffer_unflipped_ = false; |
| 3902 params.projection_matrix = frame.projection_matrix; |
| 3903 params.window_matrix = frame.window_matrix; |
| 3904 } |
| 3905 |
| 3906 // Perform basic initialization with the screen-sized viewport. |
| 3907 if (!InitializeRPDQParameters(¶ms)) |
| 3908 return; |
| 3909 |
| 3910 if (!UpdateRPDQWithSkiaFilters(¶ms)) |
| 3911 return; |
| 3912 |
| 3913 // |params.dst_rect| now contain values that reflect a potentially increased |
| 3914 // size quad. |
| 3915 gfx::RectF updated_dst_rect = params.dst_rect; |
| 3916 *new_bounds = updated_dst_rect; |
| 3917 |
| 3918 // Calculate new projection and window matrices for a minimally sized viewport |
| 3919 // using InitializeViewport(). This requires creating a dummy DrawingFrame. |
| 3920 { |
| 3921 DrawingFrame frame; |
| 3922 force_drawing_frame_framebuffer_unflipped_ = true; |
| 3923 gfx::Rect frame_rect = |
| 3924 gfx::Rect(0, 0, updated_dst_rect.width(), updated_dst_rect.height()); |
| 3925 InitializeViewport(&frame, frame_rect, frame_rect, frame_rect.size()); |
| 3926 force_drawing_frame_framebuffer_unflipped_ = false; |
| 3927 params.projection_matrix = frame.projection_matrix; |
| 3928 params.window_matrix = frame.window_matrix; |
| 3929 } |
| 3930 |
| 3931 // Calculate a new quad_to_target_transform. |
| 3932 params.quad_to_target_transform = gfx::Transform(); |
| 3933 params.quad_to_target_transform.Translate(-updated_dst_rect.x(), |
| 3934 -updated_dst_rect.y()); |
| 3935 |
| 3936 // Antialiasing works by fading out content that is close to the edge of the |
| 3937 // viewport. All of these values need to be recalculated. |
| 3938 if (params.use_aa) { |
| 3939 current_window_space_viewport_ = |
| 3940 gfx::Rect(0, 0, updated_dst_rect.width(), updated_dst_rect.height()); |
| 3941 gfx::Transform quad_rect_matrix; |
| 3942 QuadRectTransform(&quad_rect_matrix, params.quad_to_target_transform, |
| 3943 updated_dst_rect); |
| 3944 params.contents_device_transform = |
| 3945 params.window_matrix * params.projection_matrix * quad_rect_matrix; |
| 3946 bool clipped = false; |
| 3947 params.contents_device_transform.FlattenTo2d(); |
| 3948 gfx::QuadF device_layer_quad = MathUtil::MapQuad( |
| 3949 params.contents_device_transform, SharedGeometryQuad(), &clipped); |
| 3950 LayerQuad device_layer_edges(device_layer_quad); |
| 3951 InflateAntiAliasingDistances(device_layer_quad, &device_layer_edges, |
| 3952 params.edge); |
| 3953 } |
| 3954 |
| 3955 // Establish destination texture. |
| 3956 *resource = overlay_resource_pool_->AcquireResource( |
| 3957 gfx::Size(updated_dst_rect.width(), updated_dst_rect.height()), |
| 3958 ResourceFormat::RGBA_8888); |
| 3959 ResourceProvider::ScopedWriteLockGL destination(resource_provider_, |
| 3960 (*resource)->id(), false); |
| 3961 GLuint temp_fbo; |
| 3962 |
| 3963 gl_->GenFramebuffers(1, &temp_fbo); |
| 3964 gl_->BindFramebuffer(GL_FRAMEBUFFER, temp_fbo); |
| 3965 gl_->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, |
| 3966 destination.target(), destination.texture_id(), 0); |
| 3967 DCHECK(gl_->CheckFramebufferStatus(GL_FRAMEBUFFER) == |
| 3968 GL_FRAMEBUFFER_COMPLETE); |
| 3969 |
| 3970 // Clear to 0 to ensure the background is transparent. |
| 3971 gl_->ClearColor(0, 0, 0, 0); |
| 3972 gl_->Clear(GL_COLOR_BUFFER_BIT); |
| 3973 |
| 3974 UpdateRPDQTexturesForSampling(¶ms); |
| 3975 UpdateRPDQBlendMode(¶ms); |
| 3976 ChooseRPDQProgram(¶ms); |
| 3977 UpdateRPDQUniforms(¶ms); |
| 3978 |
| 3979 // Prior to drawing, set up the destination framebuffer and viewport. |
| 3980 gl_->BindFramebuffer(GL_FRAMEBUFFER, temp_fbo); |
| 3981 gl_->Viewport(0, 0, updated_dst_rect.width(), updated_dst_rect.height()); |
| 3982 |
| 3983 DrawRPDQ(params); |
| 3984 gl_->DeleteFramebuffers(1, &temp_fbo); |
| 3985 } |
| 3986 |
| 3987 void GLRenderer::ScheduleRenderPassDrawQuad( |
| 3988 const CALayerOverlay* ca_layer_overlay, |
| 3989 DrawingFrame* external_frame) { |
| 3990 DCHECK(ca_layer_overlay->rpdq); |
| 3991 |
| 3992 if (!overlay_resource_pool_) { |
| 3993 overlay_resource_pool_ = ResourcePool::CreateForGpuMemoryBufferResources( |
| 3994 resource_provider_, base::ThreadTaskRunnerHandle::Get().get(), |
| 3995 gfx::BufferUsage::SCANOUT); |
| 3996 } |
| 3997 |
| 3998 Resource* resource = nullptr; |
| 3999 gfx::RectF new_bounds; |
| 4000 CopyRenderPassDrawQuadToOverlayResource(ca_layer_overlay, &resource, |
| 4001 external_frame, &new_bounds); |
| 4002 if (!resource || !resource->id()) |
| 4003 return; |
| 4004 |
| 4005 pending_overlay_resources_.push_back( |
| 4006 base::WrapUnique(new ResourceProvider::ScopedReadLockGL( |
| 4007 resource_provider_, resource->id()))); |
| 4008 unsigned texture_id = pending_overlay_resources_.back()->texture_id(); |
| 4009 |
| 4010 // Once a resource is released, it is marked as "busy". It will be |
| 4011 // available for reuse after the ScopedReadLockGL is destroyed. |
| 4012 overlay_resource_pool_->ReleaseResource(resource); |
| 4013 |
| 4014 GLfloat contents_rect[4] = { |
| 4015 ca_layer_overlay->contents_rect.x(), ca_layer_overlay->contents_rect.y(), |
| 4016 ca_layer_overlay->contents_rect.width(), |
| 4017 ca_layer_overlay->contents_rect.height(), |
| 4018 }; |
| 4019 GLfloat bounds_rect[4] = { |
| 4020 new_bounds.x(), new_bounds.y(), new_bounds.width(), new_bounds.height(), |
| 4021 }; |
| 4022 GLboolean is_clipped = ca_layer_overlay->shared_state->is_clipped; |
| 4023 GLfloat clip_rect[4] = {ca_layer_overlay->shared_state->clip_rect.x(), |
| 4024 ca_layer_overlay->shared_state->clip_rect.y(), |
| 4025 ca_layer_overlay->shared_state->clip_rect.width(), |
| 4026 ca_layer_overlay->shared_state->clip_rect.height()}; |
| 4027 GLint sorting_context_id = ca_layer_overlay->shared_state->sorting_context_id; |
| 4028 SkMatrix44 transform = ca_layer_overlay->shared_state->transform; |
| 4029 GLfloat gl_transform[16]; |
| 4030 transform.asColMajorf(gl_transform); |
| 4031 unsigned filter = ca_layer_overlay->filter; |
| 4032 |
| 4033 gl_->ScheduleCALayerSharedStateCHROMIUM( |
| 4034 ca_layer_overlay->shared_state->opacity, is_clipped, clip_rect, |
| 4035 sorting_context_id, gl_transform); |
| 4036 gl_->ScheduleCALayerCHROMIUM( |
| 4037 texture_id, contents_rect, ca_layer_overlay->background_color, |
| 4038 ca_layer_overlay->edge_aa_mask, bounds_rect, filter); |
| 4039 } |
| 4040 |
3858 } // namespace cc | 4041 } // namespace cc |
OLD | NEW |