Chromium Code Reviews| Index: cc/surfaces/surface_embedding_base.h |
| diff --git a/cc/surfaces/surface_embedding_base.h b/cc/surfaces/surface_embedding_base.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6907065cf63670c950934c827dd5ad0cfc28378b |
| --- /dev/null |
| +++ b/cc/surfaces/surface_embedding_base.h |
| @@ -0,0 +1,90 @@ |
| +// Copyright (c) 2016 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. |
| + |
| +#ifndef CC_SURFACES_SURFACE_EMBEDDING_BASE_H_ |
| +#define CC_SURFACES_SURFACE_EMBEDDING_BASE_H_ |
| + |
| +#include <memory> |
| + |
| +#include "base/memory/ptr_util.h" |
| +#include "cc/surfaces/surface_id.h" |
| +#include "cc/surfaces/surface_sequence.h" |
| +#include "cc/surfaces/surface_sequence_generator.h" |
| +#include "ui/gfx/geometry/size.h" |
| + |
| +namespace cc { |
| + |
| +struct SurfaceInfo { |
| + SurfaceId id; |
| + float scale = 1.f; |
| + gfx::Size size; |
| + |
| + SurfaceInfo() {} |
| + SurfaceInfo(const SurfaceId& id, float scale, gfx::Size size) |
| + : id(id), scale(scale), size(size) {} |
| + bool operator==(const SurfaceInfo& info) const { |
| + return id == info.id && scale == info.scale && size == info.size; |
| + } |
| +}; |
| + |
| +class CompositorFrameMetadata; |
| +class SurfaceEmbedding; |
| +typedef std::unique_ptr<SurfaceEmbedding> SurfaceEmbeddingPtr; |
| + |
| +class SurfaceEmbeddingOwner { |
| + public: |
| + virtual SurfaceSequenceGenerator* GetSurfaceSequenceGenerator() = 0; |
| +}; |
| + |
| +class SurfaceRef; |
| +typedef std::unique_ptr<SurfaceRef> SurfaceRefPtr; |
| + |
| +class SurfaceRef final { |
|
Fady Samuel
2016/12/12 16:11:59
Make this move only and create on stack. Call it S
|
| + public: |
| + void Destroy(); |
| + void Destroy(CompositorFrameMetadata* metadata); |
| + ~SurfaceRef(); |
| + |
| + private: |
| + friend class SurfaceEmbedding; |
| + explicit SurfaceRef(SurfaceEmbeddingPtr embedding); |
| + bool is_deleted_ = false; |
|
Fady Samuel
2016/12/12 16:11:59
What's the point of this? Set embedding_ = nullptr
|
| + SurfaceEmbeddingPtr embedding_; |
| +}; |
| + |
| +class SurfaceEmbedding { |
|
Fady Samuel
2016/12/12 16:11:59
Make this refcounted.
|
| + public: |
| + explicit SurfaceEmbedding(const SurfaceInfo& info) : info_(info) {} |
| + |
| + SurfaceRefPtr CreateReference(SurfaceEmbeddingOwner* owner) const { |
| + SurfaceEmbeddingPtr clone = Clone(); |
| + clone->owner_ = owner; |
| + return SurfaceRefPtr(new SurfaceRef(std::move(clone))); |
| + } |
| + |
| + const SurfaceInfo& info() const { return info_; } |
| + const SurfaceId& id() const { return info_.id; } |
| + float scale() const { return info_.scale; } |
| + const gfx::Size& size() const { return info_.size; } |
| + |
| + SurfaceEmbeddingPtr Clone() const { return SurfaceEmbeddingPtr(CloneImpl()); } |
| + |
| + protected: |
| + SurfaceEmbeddingOwner* owner() { return owner_; } |
| + |
| + private: |
| + virtual void AddReference() = 0; |
| + virtual void RemoveReference() = 0; |
| + virtual void RemoveReference(CompositorFrameMetadata*) = 0; |
| + virtual SurfaceEmbedding* CloneImpl() const = 0; |
| + |
| + const SurfaceInfo info_; |
| + SurfaceEmbeddingOwner* owner_ = nullptr; |
| + |
| + friend class SurfaceRef; |
| +}; |
| + |
| +} // namespace cc |
| + |
| +#endif // CC_SURFACES_SURFACE_EMBEDDING_BASE_H_ |