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. 4 5 #include "cc/surfaces/surface_factory.h" 6 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" 12 13 namespace cc { 14 SurfaceFactory::SurfaceFactory(SurfaceManager* manager, 15 SurfaceFactoryClient* client) 16 : manager_(manager), client_(client), holder_(client) { 17 } 18 19 SurfaceFactory::~SurfaceFactory() { 20 } 21 22 void SurfaceFactory::Create(SurfaceId surface_id, const gfx::Size& size) { 23 scoped_ptr<Surface> surface(new Surface(surface_id, size, this)); 24 manager_->RegisterSurface(surface.get()); 25 DCHECK(!surface_map_.count(surface_id)); 26 surface_map_.add(surface_id, surface.Pass()); 27 } 28 29 void SurfaceFactory::Destroy(SurfaceId surface_id) { 30 OwningSurfaceMap::iterator it = surface_map_.find(surface_id); 31 DCHECK(it != surface_map_.end()); 32 DCHECK(it->second->factory() == this); 33 manager_->DeregisterSurface(surface_id); 34 surface_map_.erase(it); 35 } 36 37 void SurfaceFactory::SubmitFrame(SurfaceId surface_id, 38 scoped_ptr<CompositorFrame> frame, 39 const base::Closure& callback) { 40 OwningSurfaceMap::iterator it = surface_map_.find(surface_id); 41 DCHECK(it != surface_map_.end()); 42 DCHECK(it->second->factory() == this); 43 it->second->QueueFrame(frame.Pass(), callback); 44 manager_->SurfaceModified(surface_id); 45 } 46 47 void SurfaceFactory::RequestCopyOfSurface( 48 SurfaceId surface_id, 49 scoped_ptr<CopyOutputRequest> copy_request) { 50 OwningSurfaceMap::iterator it = surface_map_.find(surface_id); 51 if (it == surface_map_.end()) { 52 copy_request->SendEmptyResult(); 53 return; 54 } 55 DCHECK(it->second->factory() == this); 56 it->second->RequestCopyOfOutput(copy_request.Pass()); 57 manager_->SurfaceModified(surface_id); 58 } 59 60 void SurfaceFactory::ReceiveFromChild( 61 const TransferableResourceArray& resources) { 62 holder_.ReceiveFromChild(resources); 63 } 64 65 void SurfaceFactory::RefResources(const TransferableResourceArray& resources) { 66 holder_.RefResources(resources); 67 } 68 69 void SurfaceFactory::UnrefResources(const ReturnedResourceArray& resources) { 70 holder_.UnrefResources(resources); 71 } 72 73 } // namespace cc 74