This sets up API to release OutputSurface from LTHClient.
[chromium-blink-merge.git] / cc / surfaces / surface_display_output_surface.cc
blobed26b491bf080292975ed4a8d0161bcc1995cd40
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.
5 #include "cc/surfaces/surface_display_output_surface.h"
7 #include "base/bind.h"
8 #include "cc/output/compositor_frame.h"
9 #include "cc/output/compositor_frame_ack.h"
10 #include "cc/surfaces/display.h"
11 #include "cc/surfaces/onscreen_display_client.h"
12 #include "cc/surfaces/surface.h"
13 #include "cc/surfaces/surface_manager.h"
15 namespace cc {
17 SurfaceDisplayOutputSurface::SurfaceDisplayOutputSurface(
18 SurfaceManager* surface_manager,
19 SurfaceIdAllocator* allocator,
20 const scoped_refptr<ContextProvider>& context_provider,
21 const scoped_refptr<ContextProvider>& worker_context_provider)
22 : OutputSurface(context_provider, worker_context_provider),
23 display_client_(NULL),
24 factory_(surface_manager, this),
25 allocator_(allocator) {
26 factory_.set_needs_sync_points(false);
27 capabilities_.delegated_rendering = true;
28 capabilities_.max_frames_pending = 1;
29 capabilities_.adjust_deadline_for_parent = true;
30 capabilities_.can_force_reclaim_resources = true;
31 // Display and SurfaceDisplayOutputSurface share a GL context, so sync
32 // points aren't needed when passing resources between them.
33 capabilities_.delegated_sync_points_required = false;
36 SurfaceDisplayOutputSurface::~SurfaceDisplayOutputSurface() {
37 client_ = NULL;
38 if (!surface_id_.is_null()) {
39 factory_.Destroy(surface_id_);
43 void SurfaceDisplayOutputSurface::ReceivedVSyncParameters(
44 base::TimeTicks timebase,
45 base::TimeDelta interval) {
46 CommitVSyncParameters(timebase, interval);
49 void SurfaceDisplayOutputSurface::SwapBuffers(CompositorFrame* frame) {
50 gfx::Size frame_size =
51 frame->delegated_frame_data->render_pass_list.back()->output_rect.size();
52 if (frame_size.IsEmpty() || frame_size != display_size_) {
53 if (!surface_id_.is_null()) {
54 factory_.Destroy(surface_id_);
56 surface_id_ = allocator_->GenerateId();
57 factory_.Create(surface_id_);
58 display_size_ = frame_size;
60 display_client_->display()->SetSurfaceId(surface_id_,
61 frame->metadata.device_scale_factor);
63 client_->DidSwapBuffers();
65 scoped_ptr<CompositorFrame> frame_copy(new CompositorFrame());
66 frame->AssignTo(frame_copy.get());
67 factory_.SubmitCompositorFrame(
68 surface_id_, frame_copy.Pass(),
69 base::Bind(&SurfaceDisplayOutputSurface::SwapBuffersComplete,
70 base::Unretained(this)));
73 bool SurfaceDisplayOutputSurface::BindToClient(OutputSurfaceClient* client) {
74 DCHECK(client);
75 DCHECK(display_client_);
76 client_ = client;
77 // Avoid initializing GL context here, as this should be sharing the
78 // Display's context.
79 return display_client_->Initialize();
82 void SurfaceDisplayOutputSurface::ForceReclaimResources() {
83 if (!surface_id_.is_null())
84 factory_.SubmitCompositorFrame(surface_id_, nullptr,
85 SurfaceFactory::DrawCallback());
88 void SurfaceDisplayOutputSurface::ReturnResources(
89 const ReturnedResourceArray& resources) {
90 CompositorFrameAck ack;
91 ack.resources = resources;
92 if (client_)
93 client_->ReclaimResources(&ack);
96 void SurfaceDisplayOutputSurface::SwapBuffersComplete(SurfaceDrawStatus drawn) {
97 if (client_ && !display_client_->output_surface_lost())
98 client_->DidSwapBuffersComplete();
101 } // namespace cc