| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/surfaces/surface_display_output_surface.h" | 5 #include "cc/surfaces/surface_display_output_surface.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/debug/stack_trace.h" |
| 8 #include "cc/output/compositor_frame.h" | 9 #include "cc/output/compositor_frame.h" |
| 9 #include "cc/output/compositor_frame_ack.h" | 10 #include "cc/output/compositor_frame_ack.h" |
| 10 #include "cc/surfaces/display.h" | 11 #include "cc/surfaces/display.h" |
| 11 #include "cc/surfaces/onscreen_display_client.h" | 12 #include "cc/surfaces/onscreen_display_client.h" |
| 12 #include "cc/surfaces/surface.h" | 13 #include "cc/surfaces/surface.h" |
| 13 #include "cc/surfaces/surface_manager.h" | 14 #include "cc/surfaces/surface_manager.h" |
| 14 | 15 |
| 15 namespace cc { | 16 namespace cc { |
| 16 | 17 |
| 17 SurfaceDisplayOutputSurface::SurfaceDisplayOutputSurface( | 18 SurfaceDisplayOutputSurface::SurfaceDisplayOutputSurface( |
| 18 SurfaceManager* surface_manager, | 19 SurfaceManager* surface_manager, |
| 19 SurfaceIdAllocator* allocator, | 20 SurfaceIdAllocator* allocator, |
| 20 const scoped_refptr<ContextProvider>& context_provider) | 21 const scoped_refptr<ContextProvider>& context_provider) |
| 21 : OutputSurface(context_provider), | 22 : OutputSurface(context_provider), |
| 22 display_client_(NULL), | 23 display_client_(NULL), |
| 23 factory_(surface_manager, this), | 24 factory_(surface_manager, this), |
| 24 allocator_(allocator) { | 25 allocator_(allocator), |
| 26 inside_swap_buffers_(0) { |
| 25 factory_.set_needs_sync_points(false); | 27 factory_.set_needs_sync_points(false); |
| 26 capabilities_.delegated_rendering = true; | 28 capabilities_.delegated_rendering = true; |
| 27 capabilities_.max_frames_pending = 1; | 29 capabilities_.max_frames_pending = 1; |
| 28 capabilities_.adjust_deadline_for_parent = true; | 30 capabilities_.adjust_deadline_for_parent = true; |
| 29 capabilities_.can_force_reclaim_resources = true; | 31 capabilities_.can_force_reclaim_resources = true; |
| 30 // Display and SurfaceDisplayOutputSurface share a GL context, so sync | 32 // Display and SurfaceDisplayOutputSurface share a GL context, so sync |
| 31 // points aren't needed when passing resources between them. | 33 // points aren't needed when passing resources between them. |
| 32 capabilities_.delegated_sync_points_required = false; | 34 capabilities_.delegated_sync_points_required = false; |
| 33 } | 35 } |
| 34 | 36 |
| 35 SurfaceDisplayOutputSurface::~SurfaceDisplayOutputSurface() { | 37 SurfaceDisplayOutputSurface::~SurfaceDisplayOutputSurface() { |
| 36 client_ = NULL; | 38 client_ = NULL; |
| 37 if (!surface_id_.is_null()) { | 39 if (!surface_id_.is_null()) { |
| 38 factory_.Destroy(surface_id_); | 40 factory_.Destroy(surface_id_); |
| 39 } | 41 } |
| 40 } | 42 } |
| 41 | 43 |
| 42 void SurfaceDisplayOutputSurface::ReceivedVSyncParameters( | 44 void SurfaceDisplayOutputSurface::ReceivedVSyncParameters( |
| 43 base::TimeTicks timebase, | 45 base::TimeTicks timebase, |
| 44 base::TimeDelta interval) { | 46 base::TimeDelta interval) { |
| 45 CommitVSyncParameters(timebase, interval); | 47 CommitVSyncParameters(timebase, interval); |
| 46 } | 48 } |
| 47 | 49 |
| 48 void SurfaceDisplayOutputSurface::SwapBuffers(CompositorFrame* frame) { | 50 void SurfaceDisplayOutputSurface::SwapBuffers(CompositorFrame* frame) { |
| 51 inside_swap_buffers_ = 1; |
| 52 |
| 49 gfx::Size frame_size = | 53 gfx::Size frame_size = |
| 50 frame->delegated_frame_data->render_pass_list.back()->output_rect.size(); | 54 frame->delegated_frame_data->render_pass_list.back()->output_rect.size(); |
| 51 if (frame_size.IsEmpty() || frame_size != display_size_) { | 55 if (frame_size.IsEmpty() || frame_size != display_size_) { |
| 56 inside_swap_buffers_ = 2; |
| 52 if (!surface_id_.is_null()) { | 57 if (!surface_id_.is_null()) { |
| 53 factory_.Destroy(surface_id_); | 58 factory_.Destroy(surface_id_); |
| 54 } | 59 } |
| 60 inside_swap_buffers_ = 3; |
| 55 surface_id_ = allocator_->GenerateId(); | 61 surface_id_ = allocator_->GenerateId(); |
| 56 factory_.Create(surface_id_); | 62 factory_.Create(surface_id_); |
| 57 display_size_ = frame_size; | 63 display_size_ = frame_size; |
| 58 } | 64 } |
| 65 inside_swap_buffers_ = 4; |
| 59 display_client_->display()->SetSurfaceId(surface_id_, | 66 display_client_->display()->SetSurfaceId(surface_id_, |
| 60 frame->metadata.device_scale_factor); | 67 frame->metadata.device_scale_factor); |
| 61 | 68 |
| 69 inside_swap_buffers_ = 5; |
| 62 scoped_ptr<CompositorFrame> frame_copy(new CompositorFrame()); | 70 scoped_ptr<CompositorFrame> frame_copy(new CompositorFrame()); |
| 71 inside_swap_buffers_ = 6; |
| 63 frame->AssignTo(frame_copy.get()); | 72 frame->AssignTo(frame_copy.get()); |
| 73 inside_swap_buffers_ = 7; |
| 64 factory_.SubmitFrame( | 74 factory_.SubmitFrame( |
| 65 surface_id_, frame_copy.Pass(), | 75 surface_id_, frame_copy.Pass(), |
| 66 base::Bind(&SurfaceDisplayOutputSurface::SwapBuffersComplete, | 76 base::Bind(&SurfaceDisplayOutputSurface::SwapBuffersComplete, |
| 67 base::Unretained(this))); | 77 base::Unretained(this))); |
| 68 | 78 |
| 79 inside_swap_buffers_ = 0; |
| 80 |
| 69 client_->DidSwapBuffers(); | 81 client_->DidSwapBuffers(); |
| 70 } | 82 } |
| 71 | 83 |
| 72 bool SurfaceDisplayOutputSurface::BindToClient(OutputSurfaceClient* client) { | 84 bool SurfaceDisplayOutputSurface::BindToClient(OutputSurfaceClient* client) { |
| 73 DCHECK(client); | 85 DCHECK(client); |
| 74 DCHECK(display_client_); | 86 DCHECK(display_client_); |
| 75 client_ = client; | 87 client_ = client; |
| 76 // Avoid initializing GL context here, as this should be sharing the | 88 // Avoid initializing GL context here, as this should be sharing the |
| 77 // Display's context. | 89 // Display's context. |
| 78 return display_client_->Initialize(); | 90 return display_client_->Initialize(); |
| 79 } | 91 } |
| 80 | 92 |
| 81 void SurfaceDisplayOutputSurface::ForceReclaimResources() { | 93 void SurfaceDisplayOutputSurface::ForceReclaimResources() { |
| 82 if (!surface_id_.is_null()) | 94 if (!surface_id_.is_null()) |
| 83 factory_.SubmitFrame(surface_id_, nullptr, SurfaceFactory::DrawCallback()); | 95 factory_.SubmitFrame(surface_id_, nullptr, SurfaceFactory::DrawCallback()); |
| 84 } | 96 } |
| 85 | 97 |
| 86 void SurfaceDisplayOutputSurface::ReturnResources( | 98 void SurfaceDisplayOutputSurface::ReturnResources( |
| 87 const ReturnedResourceArray& resources) { | 99 const ReturnedResourceArray& resources) { |
| 88 CompositorFrameAck ack; | 100 CompositorFrameAck ack; |
| 89 ack.resources = resources; | 101 ack.resources = resources; |
| 90 if (client_) | 102 if (client_) |
| 91 client_->ReclaimResources(&ack); | 103 client_->ReclaimResources(&ack); |
| 92 } | 104 } |
| 93 | 105 |
| 94 void SurfaceDisplayOutputSurface::SwapBuffersComplete(SurfaceDrawStatus drawn) { | 106 void SurfaceDisplayOutputSurface::SwapBuffersComplete(SurfaceDrawStatus drawn) { |
| 107 DCHECK_EQ(0, inside_swap_buffers_) << base::debug::StackTrace().ToString(); |
| 95 if (client_ && !display_client_->output_surface_lost()) | 108 if (client_ && !display_client_->output_surface_lost()) |
| 96 client_->DidSwapBuffersComplete(); | 109 client_->DidSwapBuffersComplete(); |
| 97 } | 110 } |
| 98 | 111 |
| 99 } // namespace cc | 112 } // namespace cc |
| OLD | NEW |