blob: c07eece512293528fc01698a59af5a46cb112b4f [file] [log] [blame]
[email protected]b95a2ee2014-06-01 12:25:391// 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
jbaumanf400ce532015-02-03 04:54:595#include "cc/surfaces/surface_display_output_surface.h"
[email protected]b95a2ee2014-06-01 12:25:396
jamesr9b8fda32015-03-16 19:11:057#include "base/bind.h"
[email protected]b95a2ee2014-06-01 12:25:398#include "cc/output/compositor_frame.h"
[email protected]387b59d2014-06-27 01:17:349#include "cc/output/compositor_frame_ack.h"
[email protected]b95a2ee2014-06-01 12:25:3910#include "cc/surfaces/display.h"
jbaumanf400ce532015-02-03 04:54:5911#include "cc/surfaces/onscreen_display_client.h"
[email protected]b95a2ee2014-06-01 12:25:3912#include "cc/surfaces/surface.h"
13#include "cc/surfaces/surface_manager.h"
14
jbaumanf400ce532015-02-03 04:54:5915namespace cc {
[email protected]b95a2ee2014-06-01 12:25:3916
17SurfaceDisplayOutputSurface::SurfaceDisplayOutputSurface(
jbaumanf400ce532015-02-03 04:54:5918 SurfaceManager* surface_manager,
19 SurfaceIdAllocator* allocator,
20 const scoped_refptr<ContextProvider>& context_provider)
caseqff9c74c2015-02-10 14:56:2921 : OutputSurface(context_provider),
jbaumana8c5cc92014-10-03 20:51:2322 display_client_(NULL),
[email protected]387b59d2014-06-27 01:17:3423 surface_manager_(surface_manager),
[email protected]cde792132014-07-02 06:52:4624 factory_(surface_manager, this),
jbaumanfdc3baa2014-10-10 00:22:0925 allocator_(allocator) {
[email protected]b95a2ee2014-06-01 12:25:3926 capabilities_.delegated_rendering = true;
27 capabilities_.max_frames_pending = 1;
jbauman9bfb1a52015-01-09 08:16:0328 capabilities_.can_force_reclaim_resources = true;
[email protected]b95a2ee2014-06-01 12:25:3929}
30
31SurfaceDisplayOutputSurface::~SurfaceDisplayOutputSurface() {
[email protected]72728b12014-07-18 03:39:1732 client_ = NULL;
33 if (!surface_id_.is_null()) {
34 factory_.Destroy(surface_id_);
35 }
[email protected]b95a2ee2014-06-01 12:25:3936}
37
jbaumanc6bf8b942014-09-23 01:51:2938void SurfaceDisplayOutputSurface::ReceivedVSyncParameters(
39 base::TimeTicks timebase,
40 base::TimeDelta interval) {
41 CommitVSyncParameters(timebase, interval);
42}
43
jbaumanf400ce532015-02-03 04:54:5944void SurfaceDisplayOutputSurface::SwapBuffers(CompositorFrame* frame) {
[email protected]b95a2ee2014-06-01 12:25:3945 gfx::Size frame_size =
46 frame->delegated_frame_data->render_pass_list.back()->output_rect.size();
jbauman43ad5f2c2015-02-26 01:12:3647 if (frame_size.IsEmpty() || frame_size != display_size_) {
[email protected]cde792132014-07-02 06:52:4648 if (!surface_id_.is_null()) {
49 factory_.Destroy(surface_id_);
50 }
jbaumanfdc3baa2014-10-10 00:22:0951 surface_id_ = allocator_->GenerateId();
jbaumane0d57192014-11-25 00:32:4252 factory_.Create(surface_id_);
[email protected]cde792132014-07-02 06:52:4653 display_size_ = frame_size;
[email protected]cde792132014-07-02 06:52:4654 }
jbauman616238a2014-12-03 03:17:5355 display_client_->display()->SetSurfaceId(surface_id_,
56 frame->metadata.device_scale_factor);
[email protected]b95a2ee2014-06-01 12:25:3957
jbaumanf400ce532015-02-03 04:54:5958 scoped_ptr<CompositorFrame> frame_copy(new CompositorFrame());
[email protected]b95a2ee2014-06-01 12:25:3959 frame->AssignTo(frame_copy.get());
jbauman878e9532014-08-23 22:10:2360 factory_.SubmitFrame(
jbaumanf400ce532015-02-03 04:54:5961 surface_id_, frame_copy.Pass(),
jbauman878e9532014-08-23 22:10:2362 base::Bind(&SurfaceDisplayOutputSurface::SwapBuffersComplete,
63 base::Unretained(this)));
[email protected]b95a2ee2014-06-01 12:25:3964
[email protected]b95a2ee2014-06-01 12:25:3965 client_->DidSwapBuffers();
[email protected]b95a2ee2014-06-01 12:25:3966}
67
jbaumanf400ce532015-02-03 04:54:5968bool SurfaceDisplayOutputSurface::BindToClient(OutputSurfaceClient* client) {
jbaumana8c5cc92014-10-03 20:51:2369 DCHECK(client);
70 DCHECK(display_client_);
71 client_ = client;
jbaumana8c5cc92014-10-03 20:51:2372 // Avoid initializing GL context here, as this should be sharing the
73 // Display's context.
jbauman81c69d42014-10-28 05:52:2974 return display_client_->Initialize();
jbaumana8c5cc92014-10-03 20:51:2375}
76
jbauman9bfb1a52015-01-09 08:16:0377void SurfaceDisplayOutputSurface::ForceReclaimResources() {
78 if (!surface_id_.is_null()) {
jbaumanf400ce532015-02-03 04:54:5979 scoped_ptr<CompositorFrame> empty_frame(new CompositorFrame());
80 empty_frame->delegated_frame_data.reset(new DelegatedFrameData);
jbauman9bfb1a52015-01-09 08:16:0381 factory_.SubmitFrame(surface_id_, empty_frame.Pass(),
jbaumanf400ce532015-02-03 04:54:5982 SurfaceFactory::DrawCallback());
jbauman9bfb1a52015-01-09 08:16:0383 }
84}
85
[email protected]387b59d2014-06-27 01:17:3486void SurfaceDisplayOutputSurface::ReturnResources(
jbaumanf400ce532015-02-03 04:54:5987 const ReturnedResourceArray& resources) {
88 CompositorFrameAck ack;
[email protected]387b59d2014-06-27 01:17:3489 ack.resources = resources;
[email protected]72728b12014-07-18 03:39:1790 if (client_)
91 client_->ReclaimResources(&ack);
[email protected]387b59d2014-06-27 01:17:3492}
93
jbaumanf400ce532015-02-03 04:54:5994void SurfaceDisplayOutputSurface::SwapBuffersComplete(SurfaceDrawStatus drawn) {
jbaumanc247da12015-01-27 02:53:0095 if (client_ && !display_client_->output_surface_lost())
jbauman6a2b78c72014-12-11 03:21:2896 client_->DidSwapBuffersComplete();
jbauman878e9532014-08-23 22:10:2397}
98
jbaumanf400ce532015-02-03 04:54:5999} // namespace cc