summaryrefslogtreecommitdiffstats
path: root/cc/surfaces/surface_factory.cc
blob: 79bbe5eabd1cc762e8f836cccf02e7902f01e259 (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// 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 "cc/surfaces/surface_factory.h"

#include "cc/output/compositor_frame.h"
#include "cc/output/copy_output_request.h"
#include "cc/surfaces/surface.h"
#include "cc/surfaces/surface_manager.h"
#include "ui/gfx/geometry/size.h"

namespace cc {
SurfaceFactory::SurfaceFactory(SurfaceManager* manager,
                               SurfaceFactoryClient* client)
    : manager_(manager), client_(client), holder_(client) {
}

SurfaceFactory::~SurfaceFactory() {
  DCHECK_EQ(0u, surface_map_.size());
}

void SurfaceFactory::Create(SurfaceId surface_id, const gfx::Size& size) {
  scoped_ptr<Surface> surface(new Surface(surface_id, size, this));
  manager_->RegisterSurface(surface.get());
  DCHECK(!surface_map_.count(surface_id));
  surface_map_.add(surface_id, surface.Pass());
}

void SurfaceFactory::Destroy(SurfaceId surface_id) {
  OwningSurfaceMap::iterator it = surface_map_.find(surface_id);
  DCHECK(it != surface_map_.end());
  DCHECK(it->second->factory() == this);
  manager_->DeregisterSurface(surface_id);
  surface_map_.erase(it);
}

void SurfaceFactory::SubmitFrame(SurfaceId surface_id,
                                 scoped_ptr<CompositorFrame> frame,
                                 const base::Closure& callback) {
  OwningSurfaceMap::iterator it = surface_map_.find(surface_id);
  DCHECK(it != surface_map_.end());
  DCHECK(it->second->factory() == this);
  it->second->QueueFrame(frame.Pass(), callback);
  manager_->SurfaceModified(surface_id);
}

void SurfaceFactory::RequestCopyOfSurface(
    SurfaceId surface_id,
    scoped_ptr<CopyOutputRequest> copy_request) {
  OwningSurfaceMap::iterator it = surface_map_.find(surface_id);
  if (it == surface_map_.end()) {
    copy_request->SendEmptyResult();
    return;
  }
  DCHECK(it->second->factory() == this);
  it->second->RequestCopyOfOutput(copy_request.Pass());
}

void SurfaceFactory::ReceiveFromChild(
    const TransferableResourceArray& resources) {
  holder_.ReceiveFromChild(resources);
}

void SurfaceFactory::RefResources(const TransferableResourceArray& resources) {
  holder_.RefResources(resources);
}

void SurfaceFactory::UnrefResources(const ReturnedResourceArray& resources) {
  holder_.UnrefResources(resources);
}

}  // namespace cc