Automated Commit: Committing new LKGM version 6953.0.0 for chromeos.
[chromium-blink-merge.git] / cc / surfaces / surface_factory.cc
blobaead4f68201830655340b3ee3507d9f9ed7b229a
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_factory.h"
7 #include "cc/output/compositor_frame.h"
8 #include "cc/output/copy_output_request.h"
9 #include "cc/surfaces/surface.h"
10 #include "cc/surfaces/surface_manager.h"
11 #include "ui/gfx/geometry/size.h"
13 namespace cc {
14 SurfaceFactory::SurfaceFactory(SurfaceManager* manager,
15 SurfaceFactoryClient* client)
16 : manager_(manager), client_(client), holder_(client) {
19 SurfaceFactory::~SurfaceFactory() {
20 if (!surface_map_.empty()) {
21 LOG(ERROR) << "SurfaceFactory has " << surface_map_.size()
22 << " entries in map on destruction.";
24 DestroyAll();
27 void SurfaceFactory::DestroyAll() {
28 for (auto it = surface_map_.begin(); it != surface_map_.end(); ++it)
29 manager_->Destroy(surface_map_.take(it));
30 surface_map_.clear();
33 void SurfaceFactory::Create(SurfaceId surface_id) {
34 scoped_ptr<Surface> surface(new Surface(surface_id, this));
35 manager_->RegisterSurface(surface.get());
36 DCHECK(!surface_map_.count(surface_id));
37 surface_map_.add(surface_id, surface.Pass());
40 void SurfaceFactory::Destroy(SurfaceId surface_id) {
41 OwningSurfaceMap::iterator it = surface_map_.find(surface_id);
42 DCHECK(it != surface_map_.end());
43 DCHECK(it->second->factory().get() == this);
44 manager_->Destroy(surface_map_.take_and_erase(it));
47 void SurfaceFactory::SubmitFrame(SurfaceId surface_id,
48 scoped_ptr<CompositorFrame> frame,
49 const DrawCallback& callback) {
50 OwningSurfaceMap::iterator it = surface_map_.find(surface_id);
51 DCHECK(it != surface_map_.end());
52 DCHECK(it->second->factory().get() == this);
53 it->second->QueueFrame(frame.Pass(), callback);
54 if (!manager_->SurfaceModified(surface_id))
55 it->second->RunDrawCallbacks(SurfaceDrawStatus::DRAW_SKIPPED);
58 void SurfaceFactory::RequestCopyOfSurface(
59 SurfaceId surface_id,
60 scoped_ptr<CopyOutputRequest> copy_request) {
61 OwningSurfaceMap::iterator it = surface_map_.find(surface_id);
62 if (it == surface_map_.end()) {
63 copy_request->SendEmptyResult();
64 return;
66 DCHECK(it->second->factory().get() == this);
67 it->second->RequestCopyOfOutput(copy_request.Pass());
68 manager_->SurfaceModified(surface_id);
71 void SurfaceFactory::ReceiveFromChild(
72 const TransferableResourceArray& resources) {
73 holder_.ReceiveFromChild(resources);
76 void SurfaceFactory::RefResources(const TransferableResourceArray& resources) {
77 holder_.RefResources(resources);
80 void SurfaceFactory::UnrefResources(const ReturnedResourceArray& resources) {
81 holder_.UnrefResources(resources);
84 } // namespace cc