Commit 54bf8134 authored by jamesr@chromium.org's avatar jamesr@chromium.org

Skeleton surface interfaces in cc/surfaces

This adds a very basic surface class with tests under cc/surfaces
to establish gyp and DEPS rules. While this system is under early
development it shouldn't be used by anything outside of unit tests.

BUG=334090

Review URL: https://codereview.chromium.org/131893003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@245137 0039d316-1c4b-4281-b951-d872f2087c98
parent 31a8825b
...@@ -5,6 +5,7 @@ include_rules = [ ...@@ -5,6 +5,7 @@ include_rules = [
"+android_webview/public/browser", "+android_webview/public/browser",
"+cc", "+cc",
"-cc/surfaces",
"+components/auto_login_parser", "+components/auto_login_parser",
"+components/autofill/content/browser", "+components/autofill/content/browser",
......
include_rules = [ include_rules = [
"-cc/surfaces", # cc shouldn't depend directly on the surface implementation
"+gpu/GLES2", "+gpu/GLES2",
"+gpu/command_buffer/client/context_support.h", "+gpu/command_buffer/client/context_support.h",
"+gpu/command_buffer/client/gles2_interface.h", "+gpu/command_buffer/client/gles2_interface.h",
......
...@@ -21,6 +21,9 @@ ...@@ -21,6 +21,9 @@
'<(DEPTH)/ui/gfx/gfx.gyp:gfx_geometry', '<(DEPTH)/ui/gfx/gfx.gyp:gfx_geometry',
'<(DEPTH)/ui/gl/gl.gyp:gl', '<(DEPTH)/ui/gl/gl.gyp:gl',
], ],
'export_dependent_settings': [
'<(DEPTH)/skia/skia.gyp:skia',
],
'defines': [ 'defines': [
'CC_IMPLEMENTATION=1', 'CC_IMPLEMENTATION=1',
], ],
...@@ -442,5 +445,26 @@ ...@@ -442,5 +445,26 @@
# TODO(jschuh): crbug.com/167187 fix size_t to int truncations. # TODO(jschuh): crbug.com/167187 fix size_t to int truncations.
'msvs_disabled_warnings': [ 4267, ], 'msvs_disabled_warnings': [ 4267, ],
}, },
{
'target_name': 'cc_surfaces',
'type': '<(component)',
'dependencies': [
'cc',
'<(DEPTH)/base/base.gyp:base',
'<(DEPTH)/base/third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations',
'<(DEPTH)/ui/gfx/gfx.gyp:gfx',
'<(DEPTH)/ui/gfx/gfx.gyp:gfx_geometry',
],
'defines': [
'CC_SURFACES_IMPLEMENTATION=1',
],
'sources': [
'surfaces/surface.cc',
'surfaces/surface.h',
'surfaces/surface_manager.cc',
'surfaces/surface_manager.h',
'surfaces/surfaces_export.h',
],
},
], ],
} }
...@@ -347,6 +347,55 @@ ...@@ -347,6 +347,55 @@
# TODO(jschuh): crbug.com/167187 fix size_t to int truncations. # TODO(jschuh): crbug.com/167187 fix size_t to int truncations.
'msvs_disabled_warnings': [ 4267, ], 'msvs_disabled_warnings': [ 4267, ],
}, },
{
'target_name': 'cc_surfaces_unittests',
'type': '<(gtest_target_type)',
'dependencies': [
'../base/base.gyp:test_support_base',
'../media/media.gyp:media',
'../skia/skia.gyp:skia',
'../testing/gmock.gyp:gmock',
'../testing/gtest.gyp:gtest',
'../ui/gfx/gfx.gyp:gfx',
'../ui/gfx/gfx.gyp:gfx_geometry',
'cc.gyp:cc',
'cc.gyp:cc_surfaces',
'cc_test_support',
],
'sources': [
'test/run_all_unittests.cc',
'test/cc_test_suite.cc',
'surfaces/surface_unittest.cc',
],
'include_dirs': [
'test',
'.',
],
'conditions': [
['OS == "android" and gtest_target_type == "shared_library"',
{
'dependencies': [
'../testing/android/native_test.gyp:native_test_native_code',
],
}
],
[ 'os_posix == 1 and OS != "mac" and OS != "android" and OS != "ios"',
{
'conditions': [
[ 'linux_use_tcmalloc==1',
{
'dependencies': [
'../base/allocator/allocator.gyp:allocator',
],
}
],
],
}
],
],
# TODO(jschuh): crbug.com/167187 fix size_t to int truncations.
'msvs_disabled_warnings': [ 4267, ],
}
], ],
'conditions': [ 'conditions': [
# Special target to wrap a gtest_target_type==shared_library # Special target to wrap a gtest_target_type==shared_library
......
jamesr@chromium.org
// 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.h"
#include "cc/surfaces/surface_manager.h"
namespace cc {
Surface::Surface(SurfaceManager* manager,
SurfaceClient* client,
const gfx::Size& size)
: manager_(manager),
client_(client),
size_(size) {
surface_id_ = manager_->RegisterAndAllocateIDForSurface(this);
}
Surface::~Surface() {
manager_->DeregisterSurface(surface_id_);
}
} // namespace cc
// 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_H_
#define CC_SURFACES_SURFACE_H_
#include "base/macros.h"
#include "cc/surfaces/surfaces_export.h"
#include "ui/gfx/size.h"
namespace cc {
class SurfaceManager;
class SurfaceClient;
class CC_SURFACES_EXPORT Surface {
public:
Surface(SurfaceManager* manager,
SurfaceClient* client,
const gfx::Size& size);
~Surface();
const gfx::Size& size() const { return size_; }
int surface_id() const { return surface_id_; }
private:
SurfaceManager* manager_;
SurfaceClient* client_;
gfx::Size size_;
int surface_id_;
DISALLOW_COPY_AND_ASSIGN(Surface);
};
} // namespace cc
#endif // CC_SURFACES_SURFACE_H_
// 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_manager.h"
#include "base/logging.h"
namespace cc {
SurfaceManager::SurfaceManager()
: next_surface_id_(1) {
}
SurfaceManager::~SurfaceManager() {}
int SurfaceManager::RegisterAndAllocateIDForSurface(Surface* surface) {
DCHECK(surface);
int surface_id = next_surface_id_++;
surface_map_[surface_id] = surface;
return surface_id;
}
void SurfaceManager::DeregisterSurface(int surface_id) {
SurfaceMap::iterator it = surface_map_.find(surface_id);
DCHECK(it != surface_map_.end());
surface_map_.erase(it);
}
Surface* SurfaceManager::GetSurfaceForID(int surface_id) {
SurfaceMap::iterator it = surface_map_.find(surface_id);
if (it == surface_map_.end())
return NULL;
return it->second;
}
} // namespace cc
// 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_MANAGER_H_
#define CC_SURFACES_SURFACE_MANAGER_H_
#include "base/containers/hash_tables.h"
#include "base/macros.h"
#include "cc/surfaces/surfaces_export.h"
namespace gfx { class Size; }
namespace cc {
class CompositorFrame;
class Surface;
class CC_SURFACES_EXPORT SurfaceManager {
public:
SurfaceManager();
~SurfaceManager();
int RegisterAndAllocateIDForSurface(Surface* surface);
void DeregisterSurface(int surface_id);
Surface* GetSurfaceForID(int surface_id);
private:
typedef base::hash_map<int, Surface*> SurfaceMap;
SurfaceMap surface_map_;
int next_surface_id_;
DISALLOW_COPY_AND_ASSIGN(SurfaceManager);
};
} // namespace cc
#endif // CC_SURFACES_SURFACE_MANAGER_H_
// 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.h"
#include "cc/surfaces/surface_manager.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/size.h"
namespace cc {
namespace {
TEST(SurfaceTest, SurfaceLifetime) {
SurfaceManager manager;
int surface_id = 0;
{
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_EQ(NULL, manager.GetSurfaceForID(surface_id));
}
} // namespace
} // namespace cc
// 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_SURFACES_EXPORT_H_
#define CC_SURFACES_SURFACES_EXPORT_H_
#if defined(COMPONENT_BUILD)
#if defined(WIN32)
#if defined(CC_SURFACES_IMPLEMENTATION)
#define CC_SURFACES_EXPORT __declspec(dllexport)
#else
#define CC_SURFACES_EXPORT __declspec(dllimport)
#endif // defined(CC_SURFACES_IMPLEMENTATION)
#else // defined(WIN32)
#if defined(CC_SURFACES_IMPLEMENTATION)
#define CC_SURFACES_EXPORT __attribute__((visibility("default")))
#else
#define CC_SURFACES_EXPORT
#endif
#endif
#else // defined(COMPONENT_BUILD)
#define CC_SURFACES_EXPORT
#endif
#endif // CC_SURFACES_SURFACES_EXPORT_H_
...@@ -17,6 +17,7 @@ include_rules = [ ...@@ -17,6 +17,7 @@ include_rules = [
"-base/prefs", "-base/prefs",
"+cc", "+cc",
"-cc/surfaces",
# If you want to use any of these files, move them to src/base first. # If you want to use any of these files, move them to src/base first.
"-cc/base/scoped_ptr_algorithm.h", "-cc/base/scoped_ptr_algorithm.h",
"-cc/base/scoped_ptr_deque.h", "-cc/base/scoped_ptr_deque.h",
......
include_rules = [ include_rules = [
"+cc",
"+media/audio", "+media/audio",
"+media/base", "+media/base",
"-webkit/browser", "-webkit/browser",
......
include_rules = [ include_rules = [
"+cc", "+cc",
"-cc/surfaces",
"+gpu/command_buffer/client/gles2_interface.h", "+gpu/command_buffer/client/gles2_interface.h",
"+third_party/khronos", "+third_party/khronos",
] ]
include_rules = [ include_rules = [
"+cc", "+cc",
"-cc/surfaces",
"+gpu/command_buffer/client/gles2_interface.h", "+gpu/command_buffer/client/gles2_interface.h",
"+third_party/skia", "+third_party/skia",
"+ui/gfx", "+ui/gfx",
......
include_rules = [ include_rules = [
"+cc", "+cc",
"-cc/surfaces",
"+skia/ext", "+skia/ext",
"+third_party/skia", "+third_party/skia",
"+ui/aura", "+ui/aura",
......
...@@ -9,6 +9,7 @@ include_rules = [ ...@@ -9,6 +9,7 @@ include_rules = [
# For bridge/c/c_utility.h in npruntime_util.cc # For bridge/c/c_utility.h in npruntime_util.cc
"+bridge", "+bridge",
"+cc", "+cc",
"-cc/surfaces",
"+grit", # For generated headers "+grit", # For generated headers
"+skia", "+skia",
"+third_party/angle", "+third_party/angle",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment