summaryrefslogtreecommitdiffstats
path: root/content/browser/compositor/surface_display_output_surface.cc
blob: dae35426f8cd0f52ed28edb67931d37ffe435ea9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/browser/compositor/surface_display_output_surface.h"

#include "cc/output/compositor_frame.h"
#include "cc/surfaces/display.h"
#include "cc/surfaces/surface.h"
#include "cc/surfaces/surface_manager.h"

namespace content {

SurfaceDisplayOutputSurface::SurfaceDisplayOutputSurface(
    cc::Display* display,
    cc::SurfaceManager* surface_manager,
    const scoped_refptr<cc::ContextProvider>& context_provider)
    : cc::OutputSurface(context_provider,
                        scoped_ptr<cc::SoftwareOutputDevice>()),
      display_(display),
      surface_manager_(surface_manager) {
  capabilities_.delegated_rendering = true;
  capabilities_.max_frames_pending = 1;
}

SurfaceDisplayOutputSurface::~SurfaceDisplayOutputSurface() {
}

void SurfaceDisplayOutputSurface::SwapBuffers(cc::CompositorFrame* frame) {
  gfx::Size frame_size =
      frame->delegated_frame_data->render_pass_list.back()->output_rect.size();
  display_->Resize(frame_size);
  int surface_id = display_->CurrentSurfaceID();
  cc::Surface* surface = surface_manager_->GetSurfaceForID(surface_id);
  if (!surface)
    return;

  scoped_ptr<cc::CompositorFrame> frame_copy(new cc::CompositorFrame());
  frame->AssignTo(frame_copy.get());
  surface->QueueFrame(frame_copy.Pass());

  if (!display_->Draw())
    return;

  client_->DidSwapBuffers();
  client_->DidSwapBuffersComplete();
}

}  // namespace content