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