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