summaryrefslogtreecommitdiffstats
path: root/cc/surfaces/surface_factory.cc
diff options
context:
space:
mode:
authorjamesr@chromium.org <jamesr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-27 01:17:34 +0000
committerjamesr@chromium.org <jamesr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-27 01:17:34 +0000
commit387b59dfaa6e4d21cf106b212763eda19a6bf6bb (patch)
treedb15559e1081e6e0c32ea4e734d2667ca52b75d6 /cc/surfaces/surface_factory.cc
parent48d2b7c54479f23c092bbaf923fd47db3b8e2f91 (diff)
downloadchromium_src-387b59dfaa6e4d21cf106b212763eda19a6bf6bb.zip
chromium_src-387b59dfaa6e4d21cf106b212763eda19a6bf6bb.tar.gz
chromium_src-387b59dfaa6e4d21cf106b212763eda19a6bf6bb.tar.bz2
Use a SurfaceFactory and manage resources for that group of surfaces
This adds a SurfaceFactory by which a client (normally a compositor instance) can create and destroy surfaces that may want to reuse resources. All frames must be submitted through the factory, although a frame may reference surfaces from different factories. BUG=339257 Review URL: https://codereview.chromium.org/332293003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@280189 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/surfaces/surface_factory.cc')
-rw-r--r--cc/surfaces/surface_factory.cc59
1 files changed, 59 insertions, 0 deletions
diff --git a/cc/surfaces/surface_factory.cc b/cc/surfaces/surface_factory.cc
new file mode 100644
index 0000000..09c9f45
--- /dev/null
+++ b/cc/surfaces/surface_factory.cc
@@ -0,0 +1,59 @@
+// 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/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());
+}
+
+SurfaceId SurfaceFactory::Create(const gfx::Size& size) {
+ SurfaceId id = manager_->AllocateId();
+ scoped_ptr<Surface> surface(new Surface(id, size, this));
+ manager_->RegisterSurface(surface.get());
+ surface_map_.add(id, surface.Pass());
+ return id;
+}
+
+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) {
+ OwningSurfaceMap::iterator it = surface_map_.find(surface_id);
+ DCHECK(it != surface_map_.end());
+ DCHECK(it->second->factory() == this);
+ it->second->QueueFrame(frame.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