summaryrefslogtreecommitdiffstats
path: root/cc
diff options
context:
space:
mode:
authorjamesr@chromium.org <jamesr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-13 04:20:16 +0000
committerjamesr@chromium.org <jamesr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-13 04:20:16 +0000
commit16a6af1553f9eddf570459ae859f812a5a100611 (patch)
tree309626d2d0f54826b15d8a8b4997f9b700165388 /cc
parent9289b4e99a23444328d95a736b54a42aab21bb27 (diff)
downloadchromium_src-16a6af1553f9eddf570459ae859f812a5a100611.zip
chromium_src-16a6af1553f9eddf570459ae859f812a5a100611.tar.gz
chromium_src-16a6af1553f9eddf570459ae859f812a5a100611.tar.bz2
Use a struct for cc::Surface ids for more type safety
We currently represent surface ids as just an int, but may want to move to a richer data structure in the future. Identifiers that are ints are also pretty easy to confuse with other ints. R=piman@chromium.org Review URL: https://codereview.chromium.org/331533002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@276923 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc')
-rw-r--r--cc/DEPS1
-rw-r--r--cc/cc.gyp1
-rw-r--r--cc/layers/surface_layer.cc7
-rw-r--r--cc/layers/surface_layer.h5
-rw-r--r--cc/layers/surface_layer_impl.cc9
-rw-r--r--cc/layers/surface_layer_impl.h5
-rw-r--r--cc/layers/surface_layer_impl_unittest.cc3
-rw-r--r--cc/quads/draw_quad_unittest.cc4
-rw-r--r--cc/quads/surface_draw_quad.cc9
-rw-r--r--cc/quads/surface_draw_quad.h7
-rw-r--r--cc/surfaces/display.cc4
-rw-r--r--cc/surfaces/display.h3
-rw-r--r--cc/surfaces/surface.cc2
-rw-r--r--cc/surfaces/surface.h5
-rw-r--r--cc/surfaces/surface_aggregator.cc28
-rw-r--r--cc/surfaces/surface_aggregator.h5
-rw-r--r--cc/surfaces/surface_aggregator_test_helpers.cc2
-rw-r--r--cc/surfaces/surface_aggregator_test_helpers.h6
-rw-r--r--cc/surfaces/surface_aggregator_unittest.cc11
-rw-r--r--cc/surfaces/surface_id.h29
-rw-r--r--cc/surfaces/surface_manager.cc12
-rw-r--r--cc/surfaces/surface_manager.h10
-rw-r--r--cc/surfaces/surface_unittest.cc8
23 files changed, 110 insertions, 66 deletions
diff --git a/cc/DEPS b/cc/DEPS
index d1fb990..33793d7 100644
--- a/cc/DEPS
+++ b/cc/DEPS
@@ -1,5 +1,4 @@
include_rules = [
- "-cc/surfaces", # cc shouldn't depend directly on the surface implementation
"+gpu/GLES2",
"+gpu/command_buffer/client/context_support.h",
"+gpu/command_buffer/client/gles2_interface.h",
diff --git a/cc/cc.gyp b/cc/cc.gyp
index 7e33f42..6864e3a 100644
--- a/cc/cc.gyp
+++ b/cc/cc.gyp
@@ -494,6 +494,7 @@
'surfaces/display_client.h',
'surfaces/surface.cc',
'surfaces/surface.h',
+ 'surfaces/surface_id.h',
'surfaces/surface_aggregator.cc',
'surfaces/surface_aggregator.h',
'surfaces/surface_client.h',
diff --git a/cc/layers/surface_layer.cc b/cc/layers/surface_layer.cc
index 385f158..f345b74 100644
--- a/cc/layers/surface_layer.cc
+++ b/cc/layers/surface_layer.cc
@@ -12,11 +12,12 @@ scoped_refptr<SurfaceLayer> SurfaceLayer::Create() {
return make_scoped_refptr(new SurfaceLayer);
}
-SurfaceLayer::SurfaceLayer() : Layer(), surface_id_(0) {}
+SurfaceLayer::SurfaceLayer() : Layer() {
+}
SurfaceLayer::~SurfaceLayer() {}
-void SurfaceLayer::SetSurfaceId(int surface_id) {
+void SurfaceLayer::SetSurfaceId(SurfaceId surface_id) {
surface_id_ = surface_id;
SetNeedsPushProperties();
}
@@ -26,7 +27,7 @@ scoped_ptr<LayerImpl> SurfaceLayer::CreateLayerImpl(LayerTreeImpl* tree_impl) {
}
bool SurfaceLayer::DrawsContent() const {
- return surface_id_ && Layer::DrawsContent();
+ return !surface_id_.is_null() && Layer::DrawsContent();
}
void SurfaceLayer::PushPropertiesTo(LayerImpl* layer) {
diff --git a/cc/layers/surface_layer.h b/cc/layers/surface_layer.h
index 8ff3151..cf150ab 100644
--- a/cc/layers/surface_layer.h
+++ b/cc/layers/surface_layer.h
@@ -7,6 +7,7 @@
#include "cc/base/cc_export.h"
#include "cc/layers/layer.h"
+#include "cc/surfaces/surface_id.h"
namespace cc {
@@ -16,7 +17,7 @@ class CC_EXPORT SurfaceLayer : public Layer {
public:
static scoped_refptr<SurfaceLayer> Create();
- void SetSurfaceId(int surface_id);
+ void SetSurfaceId(SurfaceId surface_id);
// Layer overrides.
virtual scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl)
@@ -30,7 +31,7 @@ class CC_EXPORT SurfaceLayer : public Layer {
private:
virtual ~SurfaceLayer();
- int surface_id_;
+ SurfaceId surface_id_;
DISALLOW_COPY_AND_ASSIGN(SurfaceLayer);
};
diff --git a/cc/layers/surface_layer_impl.cc b/cc/layers/surface_layer_impl.cc
index 3bfae2d..6557e20 100644
--- a/cc/layers/surface_layer_impl.cc
+++ b/cc/layers/surface_layer_impl.cc
@@ -11,7 +11,8 @@
namespace cc {
SurfaceLayerImpl::SurfaceLayerImpl(LayerTreeImpl* tree_impl, int id)
- : LayerImpl(tree_impl, id), surface_id_(0) {}
+ : LayerImpl(tree_impl, id) {
+}
SurfaceLayerImpl::~SurfaceLayerImpl() {}
@@ -20,7 +21,7 @@ scoped_ptr<LayerImpl> SurfaceLayerImpl::CreateLayerImpl(
return SurfaceLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>();
}
-void SurfaceLayerImpl::SetSurfaceId(int surface_id) {
+void SurfaceLayerImpl::SetSurfaceId(SurfaceId surface_id) {
if (surface_id_ == surface_id)
return;
@@ -42,7 +43,7 @@ void SurfaceLayerImpl::AppendQuads(QuadSink* quad_sink,
AppendDebugBorderQuad(quad_sink, shared_quad_state, append_quads_data);
- if (!surface_id_)
+ if (surface_id_.is_null())
return;
scoped_ptr<SurfaceDrawQuad> quad = SurfaceDrawQuad::Create();
@@ -63,7 +64,7 @@ void SurfaceLayerImpl::GetDebugBorderProperties(SkColor* color,
void SurfaceLayerImpl::AsValueInto(base::DictionaryValue* dict) const {
LayerImpl::AsValueInto(dict);
- dict->SetInteger("surface_id", surface_id_);
+ dict->SetInteger("surface_id", surface_id_.id);
}
const char* SurfaceLayerImpl::LayerTypeAsString() const {
diff --git a/cc/layers/surface_layer_impl.h b/cc/layers/surface_layer_impl.h
index b8447d0..82ac227 100644
--- a/cc/layers/surface_layer_impl.h
+++ b/cc/layers/surface_layer_impl.h
@@ -8,6 +8,7 @@
#include "base/memory/scoped_ptr.h"
#include "cc/base/cc_export.h"
#include "cc/layers/layer_impl.h"
+#include "cc/surfaces/surface_id.h"
namespace cc {
@@ -18,7 +19,7 @@ class CC_EXPORT SurfaceLayerImpl : public LayerImpl {
}
virtual ~SurfaceLayerImpl();
- void SetSurfaceId(int surface_id);
+ void SetSurfaceId(SurfaceId surface_id);
// LayerImpl overrides.
virtual scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl)
@@ -36,7 +37,7 @@ class CC_EXPORT SurfaceLayerImpl : public LayerImpl {
virtual void AsValueInto(base::DictionaryValue* dict) const OVERRIDE;
virtual const char* LayerTypeAsString() const OVERRIDE;
- int surface_id_;
+ SurfaceId surface_id_;
DISALLOW_COPY_AND_ASSIGN(SurfaceLayerImpl);
};
diff --git a/cc/layers/surface_layer_impl_unittest.cc b/cc/layers/surface_layer_impl_unittest.cc
index aeee4b6..fb0ed2f 100644
--- a/cc/layers/surface_layer_impl_unittest.cc
+++ b/cc/layers/surface_layer_impl_unittest.cc
@@ -21,7 +21,8 @@ TEST(SurfaceLayerImplTest, Occlusion) {
surface_layer_impl->SetBounds(layer_size);
surface_layer_impl->SetContentBounds(layer_size);
surface_layer_impl->SetDrawsContent(true);
- surface_layer_impl->SetSurfaceId(9);
+ SurfaceId surface_id(9);
+ surface_layer_impl->SetSurfaceId(surface_id);
impl.CalcDrawProps(viewport_size);
diff --git a/cc/quads/draw_quad_unittest.cc b/cc/quads/draw_quad_unittest.cc
index c038214..7124db2 100644
--- a/cc/quads/draw_quad_unittest.cc
+++ b/cc/quads/draw_quad_unittest.cc
@@ -490,7 +490,7 @@ TEST(DrawQuadTest, CopyStreamVideoDrawQuad) {
TEST(DrawQuadTest, CopySurfaceDrawQuad) {
gfx::Rect visible_rect(40, 50, 30, 20);
- int surface_id = 1234;
+ SurfaceId surface_id(1234);
CREATE_SHARED_STATE();
CREATE_QUAD_2_NEW(SurfaceDrawQuad, visible_rect, surface_id);
@@ -798,7 +798,7 @@ TEST_F(DrawQuadIteratorTest, StreamVideoDrawQuad) {
TEST_F(DrawQuadIteratorTest, SurfaceDrawQuad) {
gfx::Rect visible_rect(40, 50, 30, 20);
- int surface_id = 4321;
+ SurfaceId surface_id(4321);
CREATE_SHARED_STATE();
CREATE_QUAD_2_NEW(SurfaceDrawQuad, visible_rect, surface_id);
diff --git a/cc/quads/surface_draw_quad.cc b/cc/quads/surface_draw_quad.cc
index e7d09d5..8591261c 100644
--- a/cc/quads/surface_draw_quad.cc
+++ b/cc/quads/surface_draw_quad.cc
@@ -9,7 +9,8 @@
namespace cc {
-SurfaceDrawQuad::SurfaceDrawQuad() : surface_id(0) {}
+SurfaceDrawQuad::SurfaceDrawQuad() {
+}
scoped_ptr<SurfaceDrawQuad> SurfaceDrawQuad::Create() {
return make_scoped_ptr(new SurfaceDrawQuad);
@@ -18,7 +19,7 @@ scoped_ptr<SurfaceDrawQuad> SurfaceDrawQuad::Create() {
void SurfaceDrawQuad::SetNew(const SharedQuadState* shared_quad_state,
const gfx::Rect& rect,
const gfx::Rect& visible_rect,
- int surface_id) {
+ SurfaceId surface_id) {
gfx::Rect opaque_rect;
bool needs_blending = false;
DrawQuad::SetAll(shared_quad_state, DrawQuad::SURFACE_CONTENT, rect,
@@ -31,7 +32,7 @@ void SurfaceDrawQuad::SetAll(const SharedQuadState* shared_quad_state,
const gfx::Rect& opaque_rect,
const gfx::Rect& visible_rect,
bool needs_blending,
- int surface_id) {
+ SurfaceId surface_id) {
DrawQuad::SetAll(shared_quad_state, DrawQuad::SURFACE_CONTENT, rect,
opaque_rect, visible_rect, needs_blending);
this->surface_id = surface_id;
@@ -46,7 +47,7 @@ const SurfaceDrawQuad* SurfaceDrawQuad::MaterialCast(const DrawQuad* quad) {
}
void SurfaceDrawQuad::ExtendValue(base::DictionaryValue* value) const {
- value->SetInteger("surface_id", surface_id);
+ value->SetInteger("surface_id", surface_id.id);
}
diff --git a/cc/quads/surface_draw_quad.h b/cc/quads/surface_draw_quad.h
index f309211..e182ea3 100644
--- a/cc/quads/surface_draw_quad.h
+++ b/cc/quads/surface_draw_quad.h
@@ -8,6 +8,7 @@
#include "base/memory/scoped_ptr.h"
#include "cc/base/cc_export.h"
#include "cc/quads/draw_quad.h"
+#include "cc/surfaces/surface_id.h"
namespace cc {
@@ -18,16 +19,16 @@ class CC_EXPORT SurfaceDrawQuad : public DrawQuad {
void SetNew(const SharedQuadState* shared_quad_state,
const gfx::Rect& rect,
const gfx::Rect& visible_rect,
- int surface_id);
+ SurfaceId surface_id);
void SetAll(const SharedQuadState* shared_quad_state,
const gfx::Rect& rect,
const gfx::Rect& opaque_rect,
const gfx::Rect& visible_rect,
bool needs_blending,
- int surface_id);
+ SurfaceId surface_id);
- int surface_id;
+ SurfaceId surface_id;
virtual void IterateResources(const ResourceIteratorCallback& callback)
OVERRIDE;
diff --git a/cc/surfaces/display.cc b/cc/surfaces/display.cc
index 85d28b1..a39695f 100644
--- a/cc/surfaces/display.cc
+++ b/cc/surfaces/display.cc
@@ -153,8 +153,8 @@ bool Display::Draw() {
return true;
}
-int Display::CurrentSurfaceID() {
- return current_surface_ ? current_surface_->surface_id() : 0;
+SurfaceId Display::CurrentSurfaceId() {
+ return current_surface_ ? current_surface_->surface_id() : SurfaceId();
}
void Display::ReturnResources(const ReturnedResourceArray& resources) {
diff --git a/cc/surfaces/display.h b/cc/surfaces/display.h
index 22bd074..85b172a 100644
--- a/cc/surfaces/display.h
+++ b/cc/surfaces/display.h
@@ -11,6 +11,7 @@
#include "cc/output/renderer.h"
#include "cc/surfaces/surface_aggregator.h"
#include "cc/surfaces/surface_client.h"
+#include "cc/surfaces/surface_id.h"
#include "cc/surfaces/surfaces_export.h"
namespace gfx {
@@ -39,7 +40,7 @@ class CC_SURFACES_EXPORT Display : public SurfaceClient,
void Resize(const gfx::Size& new_size);
bool Draw();
- int CurrentSurfaceID();
+ SurfaceId CurrentSurfaceId();
// OutputSurfaceClient implementation.
virtual void DeferredInitialize() OVERRIDE {}
diff --git a/cc/surfaces/surface.cc b/cc/surfaces/surface.cc
index 82a1322..4012814 100644
--- a/cc/surfaces/surface.cc
+++ b/cc/surfaces/surface.cc
@@ -15,7 +15,7 @@ Surface::Surface(SurfaceManager* manager,
: manager_(manager),
client_(client),
size_(size) {
- surface_id_ = manager_->RegisterAndAllocateIDForSurface(this);
+ surface_id_ = manager_->RegisterAndAllocateIdForSurface(this);
}
Surface::~Surface() {
diff --git a/cc/surfaces/surface.h b/cc/surfaces/surface.h
index 8ed4399..60c992c 100644
--- a/cc/surfaces/surface.h
+++ b/cc/surfaces/surface.h
@@ -7,6 +7,7 @@
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
+#include "cc/surfaces/surface_id.h"
#include "cc/surfaces/surfaces_export.h"
#include "ui/gfx/size.h"
@@ -23,7 +24,7 @@ class CC_SURFACES_EXPORT Surface {
~Surface();
const gfx::Size& size() const { return size_; }
- int surface_id() const { return surface_id_; }
+ SurfaceId surface_id() const { return surface_id_; }
void QueueFrame(scoped_ptr<CompositorFrame> frame);
// Returns the most recent frame that is eligible to be rendered.
@@ -33,7 +34,7 @@ class CC_SURFACES_EXPORT Surface {
SurfaceManager* manager_;
SurfaceClient* client_;
gfx::Size size_;
- int surface_id_;
+ SurfaceId surface_id_;
// TODO(jamesr): Support multiple frames in flight.
scoped_ptr<CompositorFrame> current_frame_;
diff --git a/cc/surfaces/surface_aggregator.cc b/cc/surfaces/surface_aggregator.cc
index 6b2178d..72300c0 100644
--- a/cc/surfaces/surface_aggregator.cc
+++ b/cc/surfaces/surface_aggregator.cc
@@ -24,9 +24,9 @@ SurfaceAggregator::SurfaceAggregator(SurfaceManager* manager)
SurfaceAggregator::~SurfaceAggregator() {}
-DelegatedFrameData* SurfaceAggregator::GetReferencedDataForSurfaceID(
- int surface_id) {
- Surface* referenced_surface = manager_->GetSurfaceForID(surface_id);
+DelegatedFrameData* SurfaceAggregator::GetReferencedDataForSurfaceId(
+ SurfaceId surface_id) {
+ Surface* referenced_surface = manager_->GetSurfaceForId(surface_id);
if (!referenced_surface)
return NULL; // Invalid surface id, skip this quad.
CompositorFrame* referenced_frame = referenced_surface->GetEligibleFrame();
@@ -74,16 +74,16 @@ RenderPass::Id SurfaceAggregator::RemapPassId(
void SurfaceAggregator::HandleSurfaceQuad(const SurfaceDrawQuad* surface_quad,
RenderPass* dest_pass) {
- int surface_id = surface_quad->surface_id;
+ SurfaceId surface_id = surface_quad->surface_id;
// If this surface's id is already in our referenced set then it creates
// a cycle in the graph and should be dropped.
- if (referenced_surfaces_.count(surface_id))
+ if (referenced_surfaces_.count(surface_id.id))
return;
DelegatedFrameData* referenced_data =
- GetReferencedDataForSurfaceID(surface_id);
+ GetReferencedDataForSurfaceId(surface_id);
if (!referenced_data)
return;
- std::set<int>::iterator it = referenced_surfaces_.insert(surface_id).first;
+ std::set<int>::iterator it = referenced_surfaces_.insert(surface_id.id).first;
const RenderPassList& referenced_passes = referenced_data->render_pass_list;
for (size_t j = 0; j + 1 < referenced_passes.size(); ++j) {
@@ -91,7 +91,7 @@ void SurfaceAggregator::HandleSurfaceQuad(const SurfaceDrawQuad* surface_quad,
scoped_ptr<RenderPass> copy_pass(RenderPass::Create());
- RenderPass::Id remapped_pass_id = RemapPassId(source.id, surface_id);
+ RenderPass::Id remapped_pass_id = RemapPassId(source.id, surface_id.id);
copy_pass->SetAll(remapped_pass_id,
source.output_rect,
@@ -111,7 +111,7 @@ void SurfaceAggregator::HandleSurfaceQuad(const SurfaceDrawQuad* surface_quad,
source.shared_quad_state_list,
gfx::Transform(),
copy_pass.get(),
- surface_id);
+ surface_id.id);
dest_pass_list_->push_back(copy_pass.Pass());
}
@@ -125,7 +125,7 @@ void SurfaceAggregator::HandleSurfaceQuad(const SurfaceDrawQuad* surface_quad,
last_pass.shared_quad_state_list,
surface_quad->quadTransform(),
dest_pass,
- surface_id);
+ surface_id.id);
referenced_surfaces_.erase(it);
}
@@ -215,8 +215,8 @@ void SurfaceAggregator::CopyPasses(const RenderPassList& source_pass_list,
}
}
-scoped_ptr<CompositorFrame> SurfaceAggregator::Aggregate(int surface_id) {
- Surface* surface = manager_->GetSurfaceForID(surface_id);
+scoped_ptr<CompositorFrame> SurfaceAggregator::Aggregate(SurfaceId surface_id) {
+ Surface* surface = manager_->GetSurfaceForId(surface_id);
if (!surface)
return scoped_ptr<CompositorFrame>();
CompositorFrame* root_surface_frame = surface->GetEligibleFrame();
@@ -231,10 +231,10 @@ scoped_ptr<CompositorFrame> SurfaceAggregator::Aggregate(int surface_id) {
const RenderPassList& source_pass_list =
root_surface_frame->delegated_frame_data->render_pass_list;
- std::set<int>::iterator it = referenced_surfaces_.insert(surface_id).first;
+ std::set<int>::iterator it = referenced_surfaces_.insert(surface_id.id).first;
dest_pass_list_ = &frame->delegated_frame_data->render_pass_list;
- CopyPasses(source_pass_list, surface_id);
+ CopyPasses(source_pass_list, surface_id.id);
referenced_surfaces_.erase(it);
DCHECK(referenced_surfaces_.empty());
diff --git a/cc/surfaces/surface_aggregator.h b/cc/surfaces/surface_aggregator.h
index 4115bc3..fe52050 100644
--- a/cc/surfaces/surface_aggregator.h
+++ b/cc/surfaces/surface_aggregator.h
@@ -10,6 +10,7 @@
#include "base/containers/scoped_ptr_hash_map.h"
#include "base/memory/scoped_ptr.h"
#include "cc/quads/render_pass.h"
+#include "cc/surfaces/surface_id.h"
#include "cc/surfaces/surfaces_export.h"
namespace cc {
@@ -24,10 +25,10 @@ class CC_SURFACES_EXPORT SurfaceAggregator {
explicit SurfaceAggregator(SurfaceManager* manager);
~SurfaceAggregator();
- scoped_ptr<CompositorFrame> Aggregate(int surface_id);
+ scoped_ptr<CompositorFrame> Aggregate(SurfaceId surface_id);
private:
- DelegatedFrameData* GetReferencedDataForSurfaceID(int surface_id);
+ DelegatedFrameData* GetReferencedDataForSurfaceId(SurfaceId surface_id);
RenderPass::Id RemapPassId(RenderPass::Id surface_local_pass_id,
int surface_id);
diff --git a/cc/surfaces/surface_aggregator_test_helpers.cc b/cc/surfaces/surface_aggregator_test_helpers.cc
index 51d1cb6..747f84a 100644
--- a/cc/surfaces/surface_aggregator_test_helpers.cc
+++ b/cc/surfaces/surface_aggregator_test_helpers.cc
@@ -24,7 +24,7 @@ namespace test {
void AddTestSurfaceQuad(TestRenderPass* pass,
const gfx::Size& surface_size,
- int surface_id) {
+ SurfaceId surface_id) {
gfx::Transform content_to_target_transform;
gfx::Size content_bounds = surface_size;
gfx::Rect visible_content_rect = gfx::Rect(surface_size);
diff --git a/cc/surfaces/surface_aggregator_test_helpers.h b/cc/surfaces/surface_aggregator_test_helpers.h
index fd2c8d3..10c5659 100644
--- a/cc/surfaces/surface_aggregator_test_helpers.h
+++ b/cc/surfaces/surface_aggregator_test_helpers.h
@@ -7,6 +7,7 @@
#include "cc/quads/draw_quad.h"
#include "cc/quads/render_pass.h"
+#include "cc/surfaces/surface_id.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/gfx/size.h"
@@ -25,7 +26,7 @@ struct Quad {
return quad;
}
- static Quad SurfaceQuad(int surface_id) {
+ static Quad SurfaceQuad(SurfaceId surface_id) {
Quad quad;
quad.material = DrawQuad::SURFACE_CONTENT;
quad.surface_id = surface_id;
@@ -41,7 +42,7 @@ struct Quad {
DrawQuad::Material material;
// Set when material==DrawQuad::SURFACE_CONTENT.
- int surface_id;
+ SurfaceId surface_id;
// Set when material==DrawQuad::SOLID_COLOR.
SkColor color;
// Set when material==DrawQuad::RENDER_PASS.
@@ -50,7 +51,6 @@ struct Quad {
private:
Quad()
: material(DrawQuad::INVALID),
- surface_id(-1),
color(SK_ColorWHITE),
render_pass_id(-1, -1) {}
};
diff --git a/cc/surfaces/surface_aggregator_unittest.cc b/cc/surfaces/surface_aggregator_unittest.cc
index 1809409..aa5cea0 100644
--- a/cc/surfaces/surface_aggregator_unittest.cc
+++ b/cc/surfaces/surface_aggregator_unittest.cc
@@ -19,7 +19,12 @@
namespace cc {
namespace {
-const int kInvalidSurfaceId = -1;
+
+SurfaceId InvalidSurfaceId() {
+ static SurfaceId invalid;
+ invalid.id = -1;
+ return invalid;
+}
class SurfaceAggregatorTest : public testing::Test {
public:
@@ -31,7 +36,7 @@ class SurfaceAggregatorTest : public testing::Test {
};
TEST_F(SurfaceAggregatorTest, InvalidSurfaceId) {
- scoped_ptr<CompositorFrame> frame = aggregator_.Aggregate(kInvalidSurfaceId);
+ scoped_ptr<CompositorFrame> frame = aggregator_.Aggregate(InvalidSurfaceId());
EXPECT_FALSE(frame);
}
@@ -258,7 +263,7 @@ TEST_F(SurfaceAggregatorValidSurfaceTest, MultiPassSurfaceReference) {
// be dropped.
TEST_F(SurfaceAggregatorValidSurfaceTest, InvalidSurfaceReference) {
test::Quad quads[] = {test::Quad::SolidColorQuad(SK_ColorGREEN),
- test::Quad::SurfaceQuad(kInvalidSurfaceId),
+ test::Quad::SurfaceQuad(InvalidSurfaceId()),
test::Quad::SolidColorQuad(SK_ColorBLUE)};
test::Pass passes[] = {test::Pass(quads, arraysize(quads))};
diff --git a/cc/surfaces/surface_id.h b/cc/surfaces/surface_id.h
new file mode 100644
index 0000000..aa9474d
--- /dev/null
+++ b/cc/surfaces/surface_id.h
@@ -0,0 +1,29 @@
+// 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.
+
+#ifndef CC_SURFACES_SURFACE_ID_H_
+#define CC_SURFACES_SURFACE_ID_H_
+
+namespace cc {
+
+struct SurfaceId {
+ SurfaceId() : id(0) {}
+ explicit SurfaceId(int id) : id(id) {}
+
+ bool is_null() const { return id == 0; }
+
+ int id;
+};
+
+inline bool operator==(const SurfaceId& a, const SurfaceId& b) {
+ return a.id == b.id;
+}
+
+inline bool operator!=(const SurfaceId& a, const SurfaceId& b) {
+ return !(a == b);
+}
+
+} // namespace cc
+
+#endif // CC_SURFACES_SURFACE_ID_H_
diff --git a/cc/surfaces/surface_manager.cc b/cc/surfaces/surface_manager.cc
index 366fa81..b41aefc 100644
--- a/cc/surfaces/surface_manager.cc
+++ b/cc/surfaces/surface_manager.cc
@@ -14,21 +14,21 @@ SurfaceManager::SurfaceManager()
SurfaceManager::~SurfaceManager() {}
-int SurfaceManager::RegisterAndAllocateIDForSurface(Surface* surface) {
+SurfaceId SurfaceManager::RegisterAndAllocateIdForSurface(Surface* surface) {
DCHECK(surface);
int surface_id = next_surface_id_++;
surface_map_[surface_id] = surface;
- return surface_id;
+ return SurfaceId(surface_id);
}
-void SurfaceManager::DeregisterSurface(int surface_id) {
- SurfaceMap::iterator it = surface_map_.find(surface_id);
+void SurfaceManager::DeregisterSurface(SurfaceId surface_id) {
+ SurfaceMap::iterator it = surface_map_.find(surface_id.id);
DCHECK(it != surface_map_.end());
surface_map_.erase(it);
}
-Surface* SurfaceManager::GetSurfaceForID(int surface_id) {
- SurfaceMap::iterator it = surface_map_.find(surface_id);
+Surface* SurfaceManager::GetSurfaceForId(SurfaceId surface_id) {
+ SurfaceMap::iterator it = surface_map_.find(surface_id.id);
if (it == surface_map_.end())
return NULL;
return it->second;
diff --git a/cc/surfaces/surface_manager.h b/cc/surfaces/surface_manager.h
index fe12dbf..b14259d 100644
--- a/cc/surfaces/surface_manager.h
+++ b/cc/surfaces/surface_manager.h
@@ -7,23 +7,23 @@
#include "base/containers/hash_tables.h"
#include "base/macros.h"
+#include "cc/surfaces/surface_id.h"
#include "cc/surfaces/surfaces_export.h"
-namespace gfx { class Size; }
-
namespace cc {
class CompositorFrame;
class Surface;
+class SurfaceClient;
class CC_SURFACES_EXPORT SurfaceManager {
public:
SurfaceManager();
~SurfaceManager();
- int RegisterAndAllocateIDForSurface(Surface* surface);
- void DeregisterSurface(int surface_id);
+ SurfaceId RegisterAndAllocateIdForSurface(Surface* surface);
+ void DeregisterSurface(SurfaceId surface_id);
- Surface* GetSurfaceForID(int surface_id);
+ Surface* GetSurfaceForId(SurfaceId surface_id);
private:
typedef base::hash_map<int, Surface*> SurfaceMap;
diff --git a/cc/surfaces/surface_unittest.cc b/cc/surfaces/surface_unittest.cc
index 7b18512..df41083 100644
--- a/cc/surfaces/surface_unittest.cc
+++ b/cc/surfaces/surface_unittest.cc
@@ -13,15 +13,15 @@ namespace {
TEST(SurfaceTest, SurfaceLifetime) {
SurfaceManager manager;
- int surface_id = 0;
+ SurfaceId surface_id;
{
Surface surface(&manager, NULL, gfx::Size(5, 5));
surface_id = surface.surface_id();
- EXPECT_GT(surface_id, 0);
- EXPECT_EQ(&surface, manager.GetSurfaceForID(surface_id));
+ EXPECT_TRUE(!surface_id.is_null());
+ EXPECT_EQ(&surface, manager.GetSurfaceForId(surface_id));
}
- EXPECT_EQ(NULL, manager.GetSurfaceForID(surface_id));
+ EXPECT_EQ(NULL, manager.GetSurfaceForId(surface_id));
}
} // namespace