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 868 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
879 // in case the filter expands the result. | 879 // in case the filter expands the result. |
880 backdrop_rect.Inset(-1, -1, -1, -1); | 880 backdrop_rect.Inset(-1, -1, -1, -1); |
881 } | 881 } |
882 | 882 |
883 backdrop_rect.Intersect(MoveFromDrawToWindowSpace( | 883 backdrop_rect.Intersect(MoveFromDrawToWindowSpace( |
884 frame, frame->current_render_pass->output_rect)); | 884 frame, frame->current_render_pass->output_rect)); |
885 return backdrop_rect; | 885 return backdrop_rect; |
886 } | 886 } |
887 | 887 |
888 std::unique_ptr<ScopedResource> GLRenderer::GetBackdropTexture( | 888 std::unique_ptr<ScopedResource> GLRenderer::GetBackdropTexture( |
| 889 DrawingFrame* frame, |
889 const gfx::Rect& bounding_rect) { | 890 const gfx::Rect& bounding_rect) { |
890 std::unique_ptr<ScopedResource> device_background_texture = | 891 std::unique_ptr<ScopedResource> device_background_texture = |
891 ScopedResource::Create(resource_provider_); | 892 ScopedResource::Create(resource_provider_); |
892 // CopyTexImage2D fails when called on a texture having immutable storage. | 893 // CopyTexImage2D fails when called on a texture having immutable storage. |
893 device_background_texture->Allocate(bounding_rect.size(), | 894 device_background_texture->Allocate( |
894 ResourceProvider::TEXTURE_HINT_DEFAULT, | 895 bounding_rect.size(), ResourceProvider::TEXTURE_HINT_DEFAULT, |
895 resource_provider_->best_texture_format(), | 896 resource_provider_->best_texture_format(), frame->device_color_space); |
896 output_surface_->device_color_space()); | |
897 { | 897 { |
898 ResourceProvider::ScopedWriteLockGL lock( | 898 ResourceProvider::ScopedWriteLockGL lock( |
899 resource_provider_, device_background_texture->id(), false); | 899 resource_provider_, device_background_texture->id(), false); |
900 GetFramebufferTexture(lock.texture_id(), bounding_rect); | 900 GetFramebufferTexture(lock.texture_id(), bounding_rect); |
901 } | 901 } |
902 return device_background_texture; | 902 return device_background_texture; |
903 } | 903 } |
904 | 904 |
905 sk_sp<SkImage> GLRenderer::ApplyBackgroundFilters( | 905 sk_sp<SkImage> GLRenderer::ApplyBackgroundFilters( |
906 const RenderPassDrawQuad* quad, | 906 const RenderPassDrawQuad* quad, |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1031 params.quad = quad; | 1031 params.quad = quad; |
1032 params.frame = frame; | 1032 params.frame = frame; |
1033 params.clip_region = clip_region; | 1033 params.clip_region = clip_region; |
1034 params.window_matrix = frame->window_matrix; | 1034 params.window_matrix = frame->window_matrix; |
1035 params.projection_matrix = frame->projection_matrix; | 1035 params.projection_matrix = frame->projection_matrix; |
1036 if (bypass != render_pass_bypass_quads_.end()) { | 1036 if (bypass != render_pass_bypass_quads_.end()) { |
1037 TileDrawQuad* tile_quad = &bypass->second; | 1037 TileDrawQuad* tile_quad = &bypass->second; |
1038 // RGBA_8888 here is arbitrary and unused. | 1038 // RGBA_8888 here is arbitrary and unused. |
1039 Resource tile_resource(tile_quad->resource_id(), tile_quad->texture_size, | 1039 Resource tile_resource(tile_quad->resource_id(), tile_quad->texture_size, |
1040 ResourceFormat::RGBA_8888, | 1040 ResourceFormat::RGBA_8888, |
1041 output_surface_->device_color_space()); | 1041 frame->device_color_space); |
1042 // The projection matrix used by GLRenderer has a flip. As tile texture | 1042 // The projection matrix used by GLRenderer has a flip. As tile texture |
1043 // inputs are oriented opposite to framebuffer outputs, don't flip via | 1043 // inputs are oriented opposite to framebuffer outputs, don't flip via |
1044 // texture coords and let the projection matrix naturallyd o it. | 1044 // texture coords and let the projection matrix naturallyd o it. |
1045 params.flip_texture = false; | 1045 params.flip_texture = false; |
1046 params.contents_texture = &tile_resource; | 1046 params.contents_texture = &tile_resource; |
1047 DrawRenderPassQuadInternal(¶ms); | 1047 DrawRenderPassQuadInternal(¶ms); |
1048 } else { | 1048 } else { |
1049 ScopedResource* contents_texture = | 1049 ScopedResource* contents_texture = |
1050 render_pass_textures_[quad->render_pass_id].get(); | 1050 render_pass_textures_[quad->render_pass_id].get(); |
1051 DCHECK(contents_texture); | 1051 DCHECK(contents_texture); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1137 if (!params->background_rect.IsEmpty()) { | 1137 if (!params->background_rect.IsEmpty()) { |
1138 // The pixels from the filtered background should completely replace the | 1138 // The pixels from the filtered background should completely replace the |
1139 // current pixel values. | 1139 // current pixel values. |
1140 if (blend_enabled()) | 1140 if (blend_enabled()) |
1141 SetBlendEnabled(false); | 1141 SetBlendEnabled(false); |
1142 | 1142 |
1143 // Read the pixels in the bounding box into a buffer R. | 1143 // Read the pixels in the bounding box into a buffer R. |
1144 // This function allocates a texture, which should contribute to the | 1144 // This function allocates a texture, which should contribute to the |
1145 // amount of memory used by render surfaces: | 1145 // amount of memory used by render surfaces: |
1146 // LayerTreeHost::CalculateMemoryForRenderSurfaces. | 1146 // LayerTreeHost::CalculateMemoryForRenderSurfaces. |
1147 params->background_texture = GetBackdropTexture(params->background_rect); | 1147 params->background_texture = |
| 1148 GetBackdropTexture(params->frame, params->background_rect); |
1148 | 1149 |
1149 if (ShouldApplyBackgroundFilters(quad) && params->background_texture) { | 1150 if (ShouldApplyBackgroundFilters(quad) && params->background_texture) { |
1150 // Apply the background filters to R, so that it is applied in the | 1151 // Apply the background filters to R, so that it is applied in the |
1151 // pixels' coordinate space. | 1152 // pixels' coordinate space. |
1152 params->background_image = | 1153 params->background_image = |
1153 ApplyBackgroundFilters(quad, params->background_texture.get(), | 1154 ApplyBackgroundFilters(quad, params->background_texture.get(), |
1154 gfx::RectF(params->background_rect)); | 1155 gfx::RectF(params->background_rect)); |
1155 if (params->background_image) { | 1156 if (params->background_image) { |
1156 params->background_image_id = | 1157 params->background_image_id = |
1157 skia::GrBackendObjectToGrGLTextureInfo( | 1158 skia::GrBackendObjectToGrGLTextureInfo( |
(...skipping 1233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2391 yuv_to_rgb_multiplied[i] = yuv_to_rgb[i] * quad->resource_multiplier; | 2392 yuv_to_rgb_multiplied[i] = yuv_to_rgb[i] * quad->resource_multiplier; |
2392 | 2393 |
2393 for (int i = 0; i < 3; ++i) { | 2394 for (int i = 0; i < 3; ++i) { |
2394 yuv_adjust_with_offset[i] = | 2395 yuv_adjust_with_offset[i] = |
2395 yuv_adjust[i] * adjustment_multiplier / quad->resource_multiplier - | 2396 yuv_adjust[i] * adjustment_multiplier / quad->resource_multiplier - |
2396 quad->resource_offset; | 2397 quad->resource_offset; |
2397 } | 2398 } |
2398 | 2399 |
2399 if (lut_texture_location != -1) { | 2400 if (lut_texture_location != -1) { |
2400 unsigned int lut_texture = color_lut_cache_.GetLUT( | 2401 unsigned int lut_texture = color_lut_cache_.GetLUT( |
2401 quad->video_color_space, output_surface_->device_color_space(), 32); | 2402 quad->video_color_space, frame->device_color_space, 32); |
2402 gl_->ActiveTexture(GL_TEXTURE5); | 2403 gl_->ActiveTexture(GL_TEXTURE5); |
2403 gl_->BindTexture(GL_TEXTURE_2D, lut_texture); | 2404 gl_->BindTexture(GL_TEXTURE_2D, lut_texture); |
2404 gl_->Uniform1i(lut_texture_location, 5); | 2405 gl_->Uniform1i(lut_texture_location, 5); |
2405 gl_->ActiveTexture(GL_TEXTURE0); | 2406 gl_->ActiveTexture(GL_TEXTURE0); |
2406 } | 2407 } |
2407 | 2408 |
2408 if (resource_multiplier_location != -1) { | 2409 if (resource_multiplier_location != -1) { |
2409 gl_->Uniform1f(resource_multiplier_location, quad->resource_multiplier); | 2410 gl_->Uniform1f(resource_multiplier_location, quad->resource_multiplier); |
2410 } | 2411 } |
2411 | 2412 |
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2883 | 2884 |
2884 gl_->DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0); | 2885 gl_->DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0); |
2885 } | 2886 } |
2886 | 2887 |
2887 void GLRenderer::SwapBuffers(std::vector<ui::LatencyInfo> latency_info) { | 2888 void GLRenderer::SwapBuffers(std::vector<ui::LatencyInfo> latency_info) { |
2888 DCHECK(visible_); | 2889 DCHECK(visible_); |
2889 | 2890 |
2890 TRACE_EVENT0("cc,benchmark", "GLRenderer::SwapBuffers"); | 2891 TRACE_EVENT0("cc,benchmark", "GLRenderer::SwapBuffers"); |
2891 // We're done! Time to swapbuffers! | 2892 // We're done! Time to swapbuffers! |
2892 | 2893 |
| 2894 gfx::Size surface_size = surface_size_for_swap_buffers(); |
| 2895 |
2893 OutputSurfaceFrame output_frame; | 2896 OutputSurfaceFrame output_frame; |
2894 output_frame.latency_info = std::move(latency_info); | 2897 output_frame.latency_info = std::move(latency_info); |
2895 output_frame.size = surface_size_for_swap_buffers_; | 2898 output_frame.size = surface_size; |
2896 if (use_partial_swap_) { | 2899 if (use_partial_swap_) { |
2897 // If supported, we can save significant bandwidth by only swapping the | 2900 // If supported, we can save significant bandwidth by only swapping the |
2898 // damaged/scissored region (clamped to the viewport). | 2901 // damaged/scissored region (clamped to the viewport). |
2899 swap_buffer_rect_.Intersect(gfx::Rect(surface_size_for_swap_buffers_)); | 2902 swap_buffer_rect_.Intersect(gfx::Rect(surface_size)); |
2900 int flipped_y_pos_of_rect_bottom = surface_size_for_swap_buffers_.height() - | 2903 int flipped_y_pos_of_rect_bottom = surface_size.height() - |
2901 swap_buffer_rect_.y() - | 2904 swap_buffer_rect_.y() - |
2902 swap_buffer_rect_.height(); | 2905 swap_buffer_rect_.height(); |
2903 output_frame.sub_buffer_rect = | 2906 output_frame.sub_buffer_rect = |
2904 gfx::Rect(swap_buffer_rect_.x(), | 2907 gfx::Rect(swap_buffer_rect_.x(), |
2905 FlippedRootFramebuffer() ? flipped_y_pos_of_rect_bottom | 2908 FlippedRootFramebuffer() ? flipped_y_pos_of_rect_bottom |
2906 : swap_buffer_rect_.y(), | 2909 : swap_buffer_rect_.y(), |
2907 swap_buffer_rect_.width(), swap_buffer_rect_.height()); | 2910 swap_buffer_rect_.width(), swap_buffer_rect_.height()); |
2908 } else { | 2911 } else { |
2909 // Expand the swap rect to the full surface unless it's empty, and empty | 2912 // Expand the swap rect to the full surface unless it's empty, and empty |
2910 // swap is allowed. | 2913 // swap is allowed. |
2911 if (!swap_buffer_rect_.IsEmpty() || !allow_empty_swap_) { | 2914 if (!swap_buffer_rect_.IsEmpty() || !allow_empty_swap_) { |
2912 swap_buffer_rect_ = gfx::Rect(surface_size_for_swap_buffers_); | 2915 swap_buffer_rect_ = gfx::Rect(surface_size); |
2913 } | 2916 } |
2914 output_frame.sub_buffer_rect = swap_buffer_rect_; | 2917 output_frame.sub_buffer_rect = swap_buffer_rect_; |
2915 } | 2918 } |
2916 | 2919 |
2917 swapping_overlay_resources_.push_back(std::move(pending_overlay_resources_)); | 2920 swapping_overlay_resources_.push_back(std::move(pending_overlay_resources_)); |
2918 pending_overlay_resources_.clear(); | 2921 pending_overlay_resources_.clear(); |
2919 | 2922 |
2920 output_surface_->SwapBuffers(std::move(output_frame)); | 2923 output_surface_->SwapBuffers(std::move(output_frame)); |
2921 | 2924 |
2922 swap_buffer_rect_ = gfx::Rect(); | 2925 swap_buffer_rect_ = gfx::Rect(); |
(...skipping 983 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3906 // memory fragmentation. https://crbug.com/146070. This also allows IOSurfaces | 3909 // memory fragmentation. https://crbug.com/146070. This also allows IOSurfaces |
3907 // to be more easily reused during a resize operation. | 3910 // to be more easily reused during a resize operation. |
3908 uint32_t iosurface_multiple = 64; | 3911 uint32_t iosurface_multiple = 64; |
3909 uint32_t iosurface_width = MathUtil::UncheckedRoundUp( | 3912 uint32_t iosurface_width = MathUtil::UncheckedRoundUp( |
3910 static_cast<uint32_t>(updated_dst_rect.width()), iosurface_multiple); | 3913 static_cast<uint32_t>(updated_dst_rect.width()), iosurface_multiple); |
3911 uint32_t iosurface_height = MathUtil::UncheckedRoundUp( | 3914 uint32_t iosurface_height = MathUtil::UncheckedRoundUp( |
3912 static_cast<uint32_t>(updated_dst_rect.height()), iosurface_multiple); | 3915 static_cast<uint32_t>(updated_dst_rect.height()), iosurface_multiple); |
3913 | 3916 |
3914 *resource = overlay_resource_pool_->AcquireResource( | 3917 *resource = overlay_resource_pool_->AcquireResource( |
3915 gfx::Size(iosurface_width, iosurface_height), ResourceFormat::RGBA_8888, | 3918 gfx::Size(iosurface_width, iosurface_height), ResourceFormat::RGBA_8888, |
3916 output_surface_->device_color_space()); | 3919 external_frame->device_color_space); |
3917 *new_bounds = | 3920 *new_bounds = |
3918 gfx::RectF(updated_dst_rect.x(), updated_dst_rect.y(), | 3921 gfx::RectF(updated_dst_rect.x(), updated_dst_rect.y(), |
3919 (*resource)->size().width(), (*resource)->size().height()); | 3922 (*resource)->size().width(), (*resource)->size().height()); |
3920 | 3923 |
3921 // Calculate new projection and window matrices for a minimally sized viewport | 3924 // Calculate new projection and window matrices for a minimally sized viewport |
3922 // using InitializeViewport(). This requires creating a dummy DrawingFrame. | 3925 // using InitializeViewport(). This requires creating a dummy DrawingFrame. |
3923 { | 3926 { |
3924 DrawingFrame frame; | 3927 DrawingFrame frame; |
3925 force_drawing_frame_framebuffer_unflipped_ = true; | 3928 force_drawing_frame_framebuffer_unflipped_ = true; |
3926 gfx::Rect frame_rect = | 3929 gfx::Rect frame_rect = |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4032 | 4035 |
4033 gl_->ScheduleCALayerSharedStateCHROMIUM( | 4036 gl_->ScheduleCALayerSharedStateCHROMIUM( |
4034 ca_layer_overlay->shared_state->opacity, is_clipped, clip_rect, | 4037 ca_layer_overlay->shared_state->opacity, is_clipped, clip_rect, |
4035 sorting_context_id, gl_transform); | 4038 sorting_context_id, gl_transform); |
4036 gl_->ScheduleCALayerCHROMIUM( | 4039 gl_->ScheduleCALayerCHROMIUM( |
4037 texture_id, contents_rect, ca_layer_overlay->background_color, | 4040 texture_id, contents_rect, ca_layer_overlay->background_color, |
4038 ca_layer_overlay->edge_aa_mask, bounds_rect, filter); | 4041 ca_layer_overlay->edge_aa_mask, bounds_rect, filter); |
4039 } | 4042 } |
4040 | 4043 |
4041 } // namespace cc | 4044 } // namespace cc |
OLD | NEW |