Index: content/browser/renderer_host/render_widget_host_view_aura.cc |
diff --git a/content/browser/renderer_host/render_widget_host_view_aura.cc b/content/browser/renderer_host/render_widget_host_view_aura.cc |
index 7f690e31fd089574505bb2c1d81f782913598ce0..4ffce27ea964b21ac43e89762508a721f837579e 100644 |
--- a/content/browser/renderer_host/render_widget_host_view_aura.cc |
+++ b/content/browser/renderer_host/render_widget_host_view_aura.cc |
@@ -310,60 +310,6 @@ bool PointerEventActivates(const ui::Event& event) { |
return false; |
} |
-// Swap ack for the renderer when kCompositeToMailbox is enabled. |
-void SendCompositorFrameAck( |
- int32 route_id, |
- uint32 output_surface_id, |
- int renderer_host_id, |
- const gpu::Mailbox& received_mailbox, |
- const gfx::Size& received_size, |
- bool skip_frame, |
- const scoped_refptr<ui::Texture>& texture_to_produce) { |
- cc::CompositorFrameAck ack; |
- ack.gl_frame_data.reset(new cc::GLFrameData()); |
- DCHECK(!texture_to_produce.get() || !skip_frame); |
- if (texture_to_produce.get()) { |
- std::string mailbox_name = texture_to_produce->Produce(); |
- std::copy(mailbox_name.data(), |
- mailbox_name.data() + mailbox_name.length(), |
- reinterpret_cast<char*>(ack.gl_frame_data->mailbox.name)); |
- ack.gl_frame_data->size = texture_to_produce->size(); |
- ack.gl_frame_data->sync_point = |
- content::ImageTransportFactory::GetInstance()->InsertSyncPoint(); |
- } else if (skip_frame) { |
- // Skip the frame, i.e. tell the producer to reuse the same buffer that |
- // we just received. |
- ack.gl_frame_data->size = received_size; |
- ack.gl_frame_data->mailbox = received_mailbox; |
- } |
- |
- RenderWidgetHostImpl::SendSwapCompositorFrameAck( |
- route_id, output_surface_id, renderer_host_id, ack); |
-} |
- |
-void AcknowledgeBufferForGpu( |
- int32 route_id, |
- int gpu_host_id, |
- const std::string& received_mailbox, |
- bool skip_frame, |
- const scoped_refptr<ui::Texture>& texture_to_produce) { |
- AcceleratedSurfaceMsg_BufferPresented_Params ack; |
- uint32 sync_point = 0; |
- DCHECK(!texture_to_produce.get() || !skip_frame); |
- if (texture_to_produce.get()) { |
- ack.mailbox_name = texture_to_produce->Produce(); |
- sync_point = |
- content::ImageTransportFactory::GetInstance()->InsertSyncPoint(); |
- } else if (skip_frame) { |
- ack.mailbox_name = received_mailbox; |
- ack.sync_point = 0; |
- } |
- |
- ack.sync_point = sync_point; |
- RenderWidgetHostImpl::AcknowledgeBufferPresent( |
- route_id, gpu_host_id, ack); |
-} |
- |
} // namespace |
// We need to watch for mouse events outside a Web Popup or its parent |
@@ -467,7 +413,7 @@ RenderWidgetHostViewAura::RenderWidgetHostViewAura(RenderWidgetHost* host) |
last_output_surface_id_(0), |
pending_delegated_ack_count_(0), |
skipped_frames_(false), |
- last_swapped_surface_scale_factor_(1.f), |
+ last_swapped_software_frame_scale_factor_(1.f), |
paint_canvas_(NULL), |
synthetic_move_sent_(false), |
accelerated_compositing_state_changed_(false), |
@@ -592,7 +538,7 @@ void RenderWidgetHostViewAura::WasShown() { |
NotifyRendererOfCursorVisibilityState(cursor_client->IsCursorVisible()); |
} |
- if (!current_surface_.get() && host_->is_accelerated_compositing_active() && |
+ if (host_->is_accelerated_compositing_active() && |
!released_front_lock_.get()) { |
ui::Compositor* compositor = GetCompositor(); |
if (compositor) |
@@ -701,7 +647,7 @@ bool RenderWidgetHostViewAura::ShouldCreateResizeLock() { |
return false; |
gfx::Size desired_size = window_->bounds().size(); |
- if (desired_size == current_frame_size_) |
+ if (desired_size == current_frame_size_in_dip_) |
return false; |
aura::WindowEventDispatcher* dispatcher = window_->GetDispatcher(); |
@@ -1195,7 +1141,8 @@ void RenderWidgetHostViewAura::InternalSetBounds(const gfx::Rect& rect) { |
} |
void RenderWidgetHostViewAura::CheckResizeLock() { |
- if (!resize_lock_ || resize_lock_->expected_size() != current_frame_size_) |
+ if (!resize_lock_ || |
+ resize_lock_->expected_size() != current_frame_size_in_dip_) |
return; |
// Since we got the size we were looking for, unlock the compositor. But delay |
@@ -1217,22 +1164,15 @@ void RenderWidgetHostViewAura::UpdateExternalTexture() { |
accelerated_compositing_state_changed_ = false; |
bool is_compositing_active = host_->is_accelerated_compositing_active(); |
- if (is_compositing_active && current_surface_.get()) { |
- window_->layer()->SetExternalTexture(current_surface_.get()); |
- current_frame_size_ = ConvertSizeToDIP( |
- current_surface_->device_scale_factor(), current_surface_->size()); |
- CheckResizeLock(); |
- software_frame_manager_->DiscardCurrentFrame(); |
- } else if (is_compositing_active && |
- software_frame_manager_->HasCurrentFrame()) { |
+ if (is_compositing_active && software_frame_manager_->HasCurrentFrame()) { |
cc::TextureMailbox mailbox; |
scoped_ptr<cc::SingleReleaseCallback> callback; |
software_frame_manager_->GetCurrentFrameMailbox(&mailbox, &callback); |
- window_->layer()->SetTextureMailbox(mailbox, |
- callback.Pass(), |
- last_swapped_surface_scale_factor_); |
- current_frame_size_ = ConvertSizeToDIP(last_swapped_surface_scale_factor_, |
- mailbox.shared_memory_size()); |
+ window_->layer()->SetTextureMailbox( |
+ mailbox, callback.Pass(), last_swapped_software_frame_scale_factor_); |
+ current_frame_size_in_dip_ = |
+ ConvertSizeToDIP(last_swapped_software_frame_scale_factor_, |
+ mailbox.shared_memory_size()); |
CheckResizeLock(); |
} else { |
window_->layer()->SetShowPaintedContent(); |
@@ -1242,59 +1182,6 @@ void RenderWidgetHostViewAura::UpdateExternalTexture() { |
} |
} |
-bool RenderWidgetHostViewAura::SwapBuffersPrepare( |
- const gfx::Rect& surface_rect, |
- float surface_scale_factor, |
- const gfx::Rect& damage_rect, |
- const std::string& mailbox_name, |
- const BufferPresentedCallback& ack_callback) { |
- if (last_swapped_surface_size_ != surface_rect.size()) { |
- // The surface could have shrunk since we skipped an update, in which |
- // case we can expect a full update. |
- DLOG_IF(ERROR, damage_rect != surface_rect) << "Expected full damage rect"; |
- skipped_damage_.setEmpty(); |
- last_swapped_surface_size_ = surface_rect.size(); |
- last_swapped_surface_scale_factor_ = surface_scale_factor; |
- } |
- |
- if (ShouldSkipFrame(ConvertSizeToDIP(surface_scale_factor, |
- surface_rect.size())) || |
- mailbox_name.empty()) { |
- skipped_damage_.op(RectToSkIRect(damage_rect), SkRegion::kUnion_Op); |
- ack_callback.Run(true, scoped_refptr<ui::Texture>()); |
- return false; |
- } |
- |
- ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
- current_surface_ = |
- factory->CreateTransportClient(surface_scale_factor); |
- if (!current_surface_.get()) { |
- LOG(ERROR) << "Failed to create ImageTransport texture"; |
- ack_callback.Run(true, scoped_refptr<ui::Texture>()); |
- return false; |
- } |
- |
- current_surface_->Consume(mailbox_name, surface_rect.size()); |
- released_front_lock_ = NULL; |
- UpdateExternalTexture(); |
- |
- return true; |
-} |
- |
-void RenderWidgetHostViewAura::SwapBuffersCompleted( |
- const BufferPresentedCallback& ack_callback, |
- const scoped_refptr<ui::Texture>& texture_to_return) { |
- ui::Compositor* compositor = GetCompositor(); |
- if (!compositor) { |
- ack_callback.Run(false, texture_to_return); |
- } else { |
- AddOnCommitCallbackAndDisableLocks( |
- base::Bind(ack_callback, false, texture_to_return)); |
- } |
- |
- DidReceiveFrameFromRenderer(); |
-} |
- |
void RenderWidgetHostViewAura::DidReceiveFrameFromRenderer() { |
if (frame_subscriber() && CanCopyToVideoFrame()) { |
const base::TimeTicks present_time = base::TimeTicks::Now(); |
@@ -1303,7 +1190,7 @@ void RenderWidgetHostViewAura::DidReceiveFrameFromRenderer() { |
if (frame_subscriber()->ShouldCaptureFrame(present_time, |
&frame, &callback)) { |
CopyFromCompositingSurfaceToVideoFrame( |
- gfx::Rect(current_frame_size_), |
+ gfx::Rect(current_frame_size_in_dip_), |
frame, |
base::Bind(callback, present_time)); |
} |
@@ -1335,22 +1222,7 @@ void RenderWidgetHostViewAura::UpdateCutoutRects() { |
void RenderWidgetHostViewAura::AcceleratedSurfaceBuffersSwapped( |
const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params_in_pixel, |
int gpu_host_id) { |
- BufferPresentedCallback ack_callback = base::Bind( |
- &AcknowledgeBufferForGpu, |
- params_in_pixel.route_id, |
- gpu_host_id, |
- params_in_pixel.mailbox_name); |
- // TODO(miletus) : Pass the params_in_pixel.latency_info directly into |
- // BuffersSwapped() once GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params |
- // is converted to contain std::vector<ui::LatencyInfo>. |
- std::vector<ui::LatencyInfo> latency_info; |
- latency_info.push_back(params_in_pixel.latency_info); |
- BuffersSwapped(params_in_pixel.size, |
- gfx::Rect(params_in_pixel.size), |
- params_in_pixel.scale_factor, |
- params_in_pixel.mailbox_name, |
- latency_info, |
- ack_callback); |
+ NOTREACHED(); |
piman
2014/01/09 23:24:19
nit: Technically, a malicious renderer could swap
|
} |
void RenderWidgetHostViewAura::SwapDelegatedFrame( |
@@ -1430,7 +1302,7 @@ void RenderWidgetHostViewAura::SwapDelegatedFrame( |
// this by making a new |frame_provider_| also to ensure the scale change |
// is presented in sync with the new frame content. |
if (!frame_provider_.get() || frame_size != frame_provider_->frame_size() || |
- frame_size_in_dip != current_frame_size_) { |
+ frame_size_in_dip != current_frame_size_in_dip_) { |
frame_provider_ = new cc::DelegatedFrameProvider( |
resource_collection_.get(), frame_data.Pass()); |
window_->layer()->SetShowDelegatedContent(frame_provider_.get(), |
@@ -1440,7 +1312,7 @@ void RenderWidgetHostViewAura::SwapDelegatedFrame( |
} |
} |
released_front_lock_ = NULL; |
- current_frame_size_ = frame_size_in_dip; |
+ current_frame_size_in_dip_ = frame_size_in_dip; |
CheckResizeLock(); |
if (paint_observer_) |
@@ -1529,18 +1401,18 @@ void RenderWidgetHostViewAura::SwapSoftwareFrame( |
return; |
} |
- if (last_swapped_surface_size_ != frame_size) { |
+ if (last_swapped_software_frame_size_ != frame_size) { |
DLOG_IF(ERROR, damage_rect != gfx::Rect(frame_size)) |
<< "Expected full damage rect"; |
} |
- last_swapped_surface_size_ = frame_size; |
- last_swapped_surface_scale_factor_ = frame_device_scale_factor; |
+ last_swapped_software_frame_size_ = frame_size; |
+ last_swapped_software_frame_scale_factor_ = frame_device_scale_factor; |
cc::TextureMailbox mailbox; |
scoped_ptr<cc::SingleReleaseCallback> callback; |
software_frame_manager_->GetCurrentFrameMailbox(&mailbox, &callback); |
DCHECK(mailbox.IsSharedMemory()); |
- current_frame_size_ = frame_size_in_dip; |
+ current_frame_size_in_dip_ = frame_size_in_dip; |
released_front_lock_ = NULL; |
CheckResizeLock(); |
@@ -1616,40 +1488,11 @@ void RenderWidgetHostViewAura::OnSwapCompositorFrame( |
return; |
} |
- if (frame->software_frame_data) { |
- SwapSoftwareFrame(output_surface_id, |
- frame->software_frame_data.Pass(), |
- frame->metadata.device_scale_factor, |
- frame->metadata.latency_info); |
- return; |
- } |
- |
- if (!frame->gl_frame_data || frame->gl_frame_data->mailbox.IsZero()) |
- return; |
- |
- BufferPresentedCallback ack_callback = base::Bind( |
- &SendCompositorFrameAck, |
- host_->GetRoutingID(), output_surface_id, host_->GetProcess()->GetID(), |
- frame->gl_frame_data->mailbox, frame->gl_frame_data->size); |
- |
- if (!frame->gl_frame_data->sync_point) { |
- LOG(ERROR) << "CompositorFrame without sync point. Skipping frame..."; |
- ack_callback.Run(true, scoped_refptr<ui::Texture>()); |
- return; |
- } |
- |
- ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
- factory->WaitSyncPoint(frame->gl_frame_data->sync_point); |
- |
- std::string mailbox_name( |
- reinterpret_cast<const char*>(frame->gl_frame_data->mailbox.name), |
- sizeof(frame->gl_frame_data->mailbox.name)); |
- BuffersSwapped(frame->gl_frame_data->size, |
- frame->gl_frame_data->sub_buffer_rect, |
- frame->metadata.device_scale_factor, |
- mailbox_name, |
- frame->metadata.latency_info, |
- ack_callback); |
+ DCHECK(frame->software_frame_data); |
piman
2014/01/09 23:24:19
Not DCHECK since a malicious renderer can still se
|
+ SwapSoftwareFrame(output_surface_id, |
+ frame->software_frame_data.Pass(), |
+ frame->metadata.device_scale_factor, |
+ frame->metadata.latency_info); |
} |
#if defined(OS_WIN) |
@@ -1667,122 +1510,16 @@ gfx::NativeViewId RenderWidgetHostViewAura::GetParentForWindowlessPlugin() |
} |
#endif |
-void RenderWidgetHostViewAura::BuffersSwapped( |
- const gfx::Size& surface_size, |
- const gfx::Rect& damage_rect, |
- float surface_scale_factor, |
- const std::string& mailbox_name, |
- const std::vector<ui::LatencyInfo>& latency_info, |
- const BufferPresentedCallback& ack_callback) { |
- scoped_refptr<ui::Texture> previous_texture(current_surface_); |
- const gfx::Rect surface_rect = gfx::Rect(surface_size); |
- software_frame_manager_->DiscardCurrentFrame(); |
- |
- if (!SwapBuffersPrepare(surface_rect, |
- surface_scale_factor, |
- damage_rect, |
- mailbox_name, |
- ack_callback)) { |
- return; |
- } |
- |
- SkRegion damage(RectToSkIRect(damage_rect)); |
- if (!skipped_damage_.isEmpty()) { |
- damage.op(skipped_damage_, SkRegion::kUnion_Op); |
- skipped_damage_.setEmpty(); |
- } |
- |
- DCHECK(surface_rect.Contains(SkIRectToRect(damage.getBounds()))); |
- ui::Texture* current_texture = current_surface_.get(); |
- |
- const gfx::Size surface_size_in_pixel = surface_size; |
- DLOG_IF(ERROR, previous_texture.get() && |
- previous_texture->size() != current_texture->size() && |
- SkIRectToRect(damage.getBounds()) != surface_rect) << |
- "Expected full damage rect after size change"; |
- if (previous_texture.get() && !previous_damage_.isEmpty() && |
- previous_texture->size() == current_texture->size()) { |
- ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
- GLHelper* gl_helper = factory->GetGLHelper(); |
- gl_helper->CopySubBufferDamage( |
- current_texture->PrepareTexture(), |
- previous_texture->PrepareTexture(), |
- damage, |
- previous_damage_); |
- } |
- previous_damage_ = damage; |
- |
- ui::Compositor* compositor = GetCompositor(); |
- if (compositor) { |
- // Co-ordinates come in OpenGL co-ordinate space. |
- // We need to convert to layer space. |
- gfx::Rect rect_to_paint = |
- ConvertRectToDIP(surface_scale_factor, |
- gfx::Rect(damage_rect.x(), |
- surface_size_in_pixel.height() - |
- damage_rect.y() - damage_rect.height(), |
- damage_rect.width(), |
- damage_rect.height())); |
- |
- // Damage may not have been DIP aligned, so inflate damage to compensate |
- // for any round-off error. |
- rect_to_paint.Inset(-1, -1); |
- rect_to_paint.Intersect(window_->bounds()); |
- |
- if (paint_observer_) |
- paint_observer_->OnUpdateCompositorContent(); |
- window_->SchedulePaintInRect(rect_to_paint); |
- for (size_t i = 0; i < latency_info.size(); i++) |
- compositor->SetLatencyInfo(latency_info[i]); |
- } |
- |
- SwapBuffersCompleted(ack_callback, previous_texture); |
-} |
- |
void RenderWidgetHostViewAura::AcceleratedSurfacePostSubBuffer( |
const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params_in_pixel, |
int gpu_host_id) { |
- gfx::Rect damage_rect(params_in_pixel.x, |
- params_in_pixel.y, |
- params_in_pixel.width, |
- params_in_pixel.height); |
- BufferPresentedCallback ack_callback = |
- base::Bind(&AcknowledgeBufferForGpu, |
- params_in_pixel.route_id, |
- gpu_host_id, |
- params_in_pixel.mailbox_name); |
- // TODO(miletus) : Pass the params_in_pixel.latency_info directly into |
- // BuffersSwapped() once GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params |
- // is converted to contain std::vector<ui::LatencyInfo>. |
- std::vector<ui::LatencyInfo> latency_info; |
- latency_info.push_back(params_in_pixel.latency_info); |
- BuffersSwapped(params_in_pixel.surface_size, |
- damage_rect, |
- params_in_pixel.surface_scale_factor, |
- params_in_pixel.mailbox_name, |
- latency_info, |
- ack_callback); |
+ NOTREACHED(); |
piman
2014/01/09 23:24:19
nit: could be reached too.
|
} |
void RenderWidgetHostViewAura::AcceleratedSurfaceSuspend() { |
} |
void RenderWidgetHostViewAura::AcceleratedSurfaceRelease() { |
- // This really tells us to release the frontbuffer. |
- if (current_surface_.get()) { |
- ui::Compositor* compositor = GetCompositor(); |
- if (compositor) { |
- // We need to wait for a commit to clear to guarantee that all we |
- // will not issue any more GL referencing the previous surface. |
- AddOnCommitCallbackAndDisableLocks( |
- base::Bind(&RenderWidgetHostViewAura::SetSurfaceNotInUseByCompositor, |
- AsWeakPtr(), |
- current_surface_)); // Hold a ref so the texture will not |
- // get deleted until after commit. |
- } |
- current_surface_ = NULL; |
- UpdateExternalTexture(); |
- } |
} |
bool RenderWidgetHostViewAura::HasAcceleratedSurface( |
@@ -2623,31 +2360,11 @@ void RenderWidgetHostViewAura::DidRecreateLayer(ui::Layer *old_layer, |
float mailbox_scale_factor; |
cc::TextureMailbox old_mailbox = |
old_layer->GetTextureMailbox(&mailbox_scale_factor); |
- scoped_refptr<ui::Texture> old_texture = old_layer->external_texture(); |
// The new_layer is the one that will be used by our Window, so that's the one |
// that should keep our texture. old_layer will be returned to the |
// RecreateLayer caller, and should have a copy. |
- if (old_texture.get()) { |
- ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
- GLHelper* gl_helper = factory->GetGLHelper(); |
- scoped_refptr<ui::Texture> new_texture; |
- if (host_->is_accelerated_compositing_active() && |
- gl_helper && current_surface_.get()) { |
- GLuint texture_id = |
- gl_helper->CopyTexture(current_surface_->PrepareTexture(), |
- current_surface_->size()); |
- if (texture_id) { |
- new_texture = factory->CreateOwnedTexture( |
- current_surface_->size(), |
- current_surface_->device_scale_factor(), texture_id); |
- } |
- } |
- if (new_texture.get()) |
- old_layer->SetExternalTexture(new_texture.get()); |
- else |
- old_layer->SetShowPaintedContent(); |
- new_layer->SetExternalTexture(old_texture.get()); |
- } else if (old_mailbox.IsSharedMemory()) { |
+ if (old_mailbox.IsValid()) { |
+ DCHECK(old_mailbox.IsSharedMemory()); |
piman
2014/01/10 01:45:09
nit: I think that code was still fine, since this
danakj
2014/01/10 17:51:42
You mean the if (IsSharedMemory)? I was thinking t
|
base::SharedMemory* old_buffer = old_mailbox.shared_memory(); |
const size_t size = old_mailbox.shared_memory_size_in_bytes(); |
@@ -2668,7 +2385,7 @@ void RenderWidgetHostViewAura::DidRecreateLayer(ui::Layer *old_layer, |
} |
} else if (frame_provider_.get()) { |
new_layer->SetShowDelegatedContent(frame_provider_.get(), |
- current_frame_size_); |
+ current_frame_size_in_dip_); |
} |
} |
@@ -3113,7 +2830,8 @@ void RenderWidgetHostViewAura::OnCompositingDidCommit( |
can_lock_compositor_ = YES_DID_LOCK; |
} |
RunOnCommitCallbacks(); |
- if (resize_lock_ && resize_lock_->expected_size() == current_frame_size_) { |
+ if (resize_lock_ && |
+ resize_lock_->expected_size() == current_frame_size_in_dip_) { |
resize_lock_.reset(); |
host_->WasResized(); |
// We may have had a resize while we had the lock (e.g. if the lock expired, |
@@ -3220,7 +2938,6 @@ void RenderWidgetHostViewAura::FatalAccessibilityTreeError() { |
// RenderWidgetHostViewAura, ImageTransportFactoryObserver implementation: |
void RenderWidgetHostViewAura::OnLostResources() { |
- current_surface_ = NULL; |
UpdateExternalTexture(); |
idle_frame_subscriber_textures_.clear(); |
@@ -3436,8 +3153,6 @@ void RenderWidgetHostViewAura::AddedToRootWindow() { |
cursor_client->AddObserver(this); |
NotifyRendererOfCursorVisibilityState(cursor_client->IsCursorVisible()); |
} |
- if (current_surface_.get()) |
- UpdateExternalTexture(); |
if (HasFocus()) { |
ui::InputMethod* input_method = GetInputMethod(); |
if (input_method) |
@@ -3456,18 +3171,10 @@ void RenderWidgetHostViewAura::RemovingFromRootWindow() { |
event_filter_for_popup_exit_.reset(); |
window_->GetDispatcher()->RemoveRootWindowObserver(this); |
host_->ParentChanged(0); |
- ui::Compositor* compositor = GetCompositor(); |
- if (current_surface_.get()) { |
- // We can't get notification for commits after this point, which would |
- // guarantee that the compositor isn't using an old texture any more, so |
- // instead we force the layer to stop using any external resources which |
- // synchronizes with the compositor thread, and makes it safe to run the |
- // callback. |
- window_->layer()->SetShowPaintedContent(); |
- } |
RunOnCommitCallbacks(); |
resize_lock_.reset(); |
host_->WasResized(); |
+ ui::Compositor* compositor = GetCompositor(); |
if (compositor && compositor->HasObserver(this)) |
compositor->RemoveObserver(this); |
} |