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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
194 highp_threshold_min)); | 194 highp_threshold_min)); |
195 } | 195 } |
196 | 196 |
197 GLRenderer::GLRenderer(RendererClient* client, | 197 GLRenderer::GLRenderer(RendererClient* client, |
198 const LayerTreeSettings* settings, | 198 const LayerTreeSettings* settings, |
199 OutputSurface* output_surface, | 199 OutputSurface* output_surface, |
200 ResourceProvider* resource_provider, | 200 ResourceProvider* resource_provider, |
201 TextureMailboxDeleter* texture_mailbox_deleter, | 201 TextureMailboxDeleter* texture_mailbox_deleter, |
202 int highp_threshold_min) | 202 int highp_threshold_min) |
203 : DirectRenderer(client, settings, output_surface, resource_provider), | 203 : DirectRenderer(client, settings, output_surface, resource_provider), |
204 overlay_child_(0), | |
204 offscreen_framebuffer_id_(0), | 205 offscreen_framebuffer_id_(0), |
205 shared_geometry_quad_(gfx::RectF(-0.5f, -0.5f, 1.0f, 1.0f)), | 206 shared_geometry_quad_(gfx::RectF(-0.5f, -0.5f, 1.0f, 1.0f)), |
206 gl_(output_surface->context_provider()->ContextGL()), | 207 gl_(output_surface->context_provider()->ContextGL()), |
207 context_support_(output_surface->context_provider()->ContextSupport()), | 208 context_support_(output_surface->context_provider()->ContextSupport()), |
208 texture_mailbox_deleter_(texture_mailbox_deleter), | 209 texture_mailbox_deleter_(texture_mailbox_deleter), |
209 is_backbuffer_discarded_(false), | 210 is_backbuffer_discarded_(false), |
210 visible_(true), | 211 visible_(true), |
211 is_scissor_enabled_(false), | 212 is_scissor_enabled_(false), |
212 scissor_rect_needs_reset_(true), | 213 scissor_rect_needs_reset_(true), |
213 stencil_shadow_(false), | 214 stencil_shadow_(false), |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
249 capabilities_.allow_rasterize_on_demand = true; | 250 capabilities_.allow_rasterize_on_demand = true; |
250 | 251 |
251 InitializeSharedObjects(); | 252 InitializeSharedObjects(); |
252 } | 253 } |
253 | 254 |
254 GLRenderer::~GLRenderer() { | 255 GLRenderer::~GLRenderer() { |
255 while (!pending_async_read_pixels_.empty()) { | 256 while (!pending_async_read_pixels_.empty()) { |
256 PendingAsyncReadPixels* pending_read = pending_async_read_pixels_.back(); | 257 PendingAsyncReadPixels* pending_read = pending_async_read_pixels_.back(); |
257 pending_read->finished_read_pixels_callback.Cancel(); | 258 pending_read->finished_read_pixels_callback.Cancel(); |
258 pending_async_read_pixels_.pop_back(); | 259 pending_async_read_pixels_.pop_back(); |
259 } | 260 } |
piman
2014/03/26 03:43:33
If you keep the "child" logic (see below), you'd n
| |
260 | 261 |
261 CleanupSharedObjects(); | 262 CleanupSharedObjects(); |
262 } | 263 } |
263 | 264 |
264 const RendererCapabilitiesImpl& GLRenderer::Capabilities() const { | 265 const RendererCapabilitiesImpl& GLRenderer::Capabilities() const { |
265 return capabilities_; | 266 return capabilities_; |
266 } | 267 } |
267 | 268 |
268 void GLRenderer::DebugGLCall(GLES2Interface* gl, | 269 void GLRenderer::DebugGLCall(GLES2Interface* gl, |
269 const char* command, | 270 const char* command, |
(...skipping 1723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1993 | 1994 |
1994 GLC(gl_, gl_->BindTexture(GL_TEXTURE_RECTANGLE_ARB, 0)); | 1995 GLC(gl_, gl_->BindTexture(GL_TEXTURE_RECTANGLE_ARB, 0)); |
1995 } | 1996 } |
1996 | 1997 |
1997 void GLRenderer::FinishDrawingFrame(DrawingFrame* frame) { | 1998 void GLRenderer::FinishDrawingFrame(DrawingFrame* frame) { |
1998 current_framebuffer_lock_.reset(); | 1999 current_framebuffer_lock_.reset(); |
1999 swap_buffer_rect_.Union(gfx::ToEnclosingRect(frame->root_damage_rect)); | 2000 swap_buffer_rect_.Union(gfx::ToEnclosingRect(frame->root_damage_rect)); |
2000 | 2001 |
2001 GLC(gl_, gl_->Disable(GL_BLEND)); | 2002 GLC(gl_, gl_->Disable(GL_BLEND)); |
2002 blend_shadow_ = false; | 2003 blend_shadow_ = false; |
2004 | |
2005 ScheduleOverlays(frame); | |
2003 } | 2006 } |
2004 | 2007 |
2005 void GLRenderer::FinishDrawingQuadList() { FlushTextureQuadCache(); } | 2008 void GLRenderer::FinishDrawingQuadList() { FlushTextureQuadCache(); } |
2006 | 2009 |
2007 bool GLRenderer::FlippedFramebuffer() const { return true; } | 2010 bool GLRenderer::FlippedFramebuffer() const { return true; } |
2008 | 2011 |
2009 void GLRenderer::EnsureScissorTestEnabled() { | 2012 void GLRenderer::EnsureScissorTestEnabled() { |
2010 if (is_scissor_enabled_) | 2013 if (is_scissor_enabled_) |
2011 return; | 2014 return; |
2012 | 2015 |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2164 gfx::Rect(swap_buffer_rect_.x(), | 2167 gfx::Rect(swap_buffer_rect_.x(), |
2165 flipped_y_pos_of_rect_bottom, | 2168 flipped_y_pos_of_rect_bottom, |
2166 swap_buffer_rect_.width(), | 2169 swap_buffer_rect_.width(), |
2167 swap_buffer_rect_.height()); | 2170 swap_buffer_rect_.height()); |
2168 } else { | 2171 } else { |
2169 compositor_frame.gl_frame_data->sub_buffer_rect = | 2172 compositor_frame.gl_frame_data->sub_buffer_rect = |
2170 gfx::Rect(output_surface_->SurfaceSize()); | 2173 gfx::Rect(output_surface_->SurfaceSize()); |
2171 } | 2174 } |
2172 output_surface_->SwapBuffers(&compositor_frame); | 2175 output_surface_->SwapBuffers(&compositor_frame); |
2173 | 2176 |
2177 // Release previously used overlay resources and hold onto the pending ones | |
2178 // until the next swap buffers. | |
2179 ReturnedResourceArray unused_overlay_resources; | |
2180 for (TransferableResourceArray::const_iterator it = | |
2181 in_use_overlay_resources_.begin(); | |
2182 it != in_use_overlay_resources_.end(); | |
2183 ++it) { | |
2184 unused_overlay_resources.push_back(it->ToReturnedResource()); | |
2185 } | |
piman
2014/03/26 03:43:33
nit: TransferableResource::ReturnResources
| |
2186 | |
2187 if (unused_overlay_resources.size()) | |
piman
2014/03/26 03:43:33
nit: if (!unused_overlay_resources.empty())
| |
2188 resource_provider()->ReceiveReturnsFromParent(unused_overlay_resources); | |
2189 | |
2190 in_use_overlay_resources_.clear(); | |
2191 in_use_overlay_resources_.swap(pending_overlay_resources_); | |
2192 | |
2174 swap_buffer_rect_ = gfx::Rect(); | 2193 swap_buffer_rect_ = gfx::Rect(); |
2175 | 2194 |
2176 // We don't have real fences, so we mark read fences as passed | 2195 // We don't have real fences, so we mark read fences as passed |
2177 // assuming a double-buffered GPU pipeline. A texture can be | 2196 // assuming a double-buffered GPU pipeline. A texture can be |
2178 // written to after one full frame has past since it was last read. | 2197 // written to after one full frame has past since it was last read. |
2179 if (last_swap_fence_.get()) | 2198 if (last_swap_fence_.get()) |
2180 static_cast<SimpleSwapFence*>(last_swap_fence_.get())->SetHasPassed(); | 2199 static_cast<SimpleSwapFence*>(last_swap_fence_.get())->SetHasPassed(); |
2181 last_swap_fence_ = resource_provider_->GetReadLockFence(); | 2200 last_swap_fence_ = resource_provider_->GetReadLockFence(); |
2182 resource_provider_->SetReadLockFence(new SimpleSwapFence()); | 2201 resource_provider_->SetReadLockFence(new SimpleSwapFence()); |
2183 } | 2202 } |
(...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3040 // Make sure scissoring starts as disabled. | 3059 // Make sure scissoring starts as disabled. |
3041 is_scissor_enabled_ = false; | 3060 is_scissor_enabled_ = false; |
3042 GLC(gl_, gl_->Disable(GL_SCISSOR_TEST)); | 3061 GLC(gl_, gl_->Disable(GL_SCISSOR_TEST)); |
3043 scissor_rect_needs_reset_ = true; | 3062 scissor_rect_needs_reset_ = true; |
3044 } | 3063 } |
3045 | 3064 |
3046 bool GLRenderer::IsContextLost() { | 3065 bool GLRenderer::IsContextLost() { |
3047 return output_surface_->context_provider()->IsContextLost(); | 3066 return output_surface_->context_provider()->IsContextLost(); |
3048 } | 3067 } |
3049 | 3068 |
3069 static void CollectResources(const ReturnedResourceArray& returned) {} | |
alexst (slow to review)
2014/03/26 01:23:51
Since these resources never crossed any process bo
piman
2014/03/26 03:43:33
This will be called from DeclareUsedResourcesFromC
| |
3070 | |
3071 static ResourceProvider::ResourceId ResourceRemapHelper( | |
3072 const ResourceProvider::ResourceIdMap& child_to_parent_map, | |
3073 ResourceProvider::ResourceIdArray* resources_in_frame, | |
3074 ResourceProvider::ResourceId id) { | |
3075 | |
3076 ResourceProvider::ResourceIdMap::const_iterator it = | |
3077 child_to_parent_map.find(id); | |
3078 | |
3079 DCHECK(it != child_to_parent_map.end()); | |
3080 DCHECK_EQ(it->first, id); | |
3081 ResourceProvider::ResourceId remapped_id = it->second; | |
3082 resources_in_frame->push_back(id); | |
3083 return remapped_id; | |
3084 } | |
3085 | |
3086 void GLRenderer::ScheduleOverlays(DrawingFrame* frame) { | |
3087 if (!frame->overlay_list.size()) | |
3088 return; | |
3089 | |
3090 if (!overlay_child_) { | |
3091 overlay_child_ = | |
3092 resource_provider_->CreateChild(base::Bind(&CollectResources)); | |
3093 } | |
3094 | |
3095 ResourceProvider::ResourceIdArray resources; | |
3096 OverlayCandidateList& overlays = frame->overlay_list; | |
3097 OverlayCandidateList::iterator it; | |
3098 for (it = overlays.begin(); it != overlays.end(); ++it) { | |
3099 const OverlayCandidate& overlay = *it; | |
3100 // Skip primary plane. | |
3101 if (overlay.plane_z_order == 0) | |
3102 continue; | |
3103 | |
3104 DCHECK(overlay.resource_id); | |
3105 resources.push_back(overlay.resource_id); | |
3106 } | |
3107 | |
3108 // Make sure the overlay resources appear as exported until it is | |
3109 // safe to return them to their respective renderers. | |
3110 resource_provider()->PrepareSendToParent(resources, | |
3111 &pending_overlay_resources_); | |
3112 resource_provider()->ReceiveFromChild(overlay_child_, | |
3113 pending_overlay_resources_); | |
piman
2014/03/26 03:43:33
So, this is unexpected. Looking at this code, it k
| |
3114 | |
3115 const ResourceProvider::ResourceIdMap& resource_map = | |
3116 resource_provider_->GetChildToParentMap(overlay_child_); | |
3117 resources.clear(); | |
3118 for (it = overlays.begin(); it != overlays.end(); ++it) { | |
3119 const OverlayCandidate& overlay = *it; | |
3120 if (overlay.plane_z_order == 0) | |
3121 continue; | |
3122 | |
3123 ResourceProvider::ResourceId overlay_id = | |
3124 ResourceRemapHelper(resource_map, &resources, overlay.resource_id); | |
3125 | |
3126 ResourceProvider::ScopedReadLockGL overlay_resource_lock( | |
3127 resource_provider(), overlay_id); | |
3128 | |
3129 context_support_->ScheduleOverlayPlane(overlay.plane_z_order, | |
3130 overlay.transform, | |
3131 overlay_resource_lock.texture_id(), | |
3132 overlay.display_rect, | |
3133 overlay.uv_rect); | |
3134 } | |
3135 | |
3136 resource_provider()->DeclareUsedResourcesFromChild(overlay_child_, resources); | |
3137 } | |
3138 | |
3050 } // namespace cc | 3139 } // namespace cc |
OLD | NEW |