0

Switched cc::Resource and cc::ScopedResource to Chrome coding style.

BUG=144576,144577

Review URL: https://chromiumcodereview.appspot.com/11412022

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@168152 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
skaslev@chromium.org
2012-11-16 07:36:20 +00:00
parent 8a08d9e497
commit 46f4611b34
12 changed files with 98 additions and 107 deletions

@ -136,7 +136,7 @@ void DirectRenderer::decideRenderPassAllocationsForFrame(const RenderPassList& r
DCHECK(texture);
if (texture->id() && (texture->size() != requiredSize || texture->format() != requiredFormat))
texture->free();
texture->Free();
}
// Delete RenderPass textures from the previous frame that will not be used again.
@ -213,7 +213,7 @@ bool DirectRenderer::useRenderPass(DrawingFrame& frame, const RenderPass* render
CachedResource* texture = m_renderPassTextures.get(renderPass->id());
DCHECK(texture);
if (!texture->id() && !texture->allocate(Renderer::ImplPool, renderPassTextureSize(renderPass), renderPassTextureFormat(renderPass), ResourceProvider::TextureUsageFramebuffer))
if (!texture->id() && !texture->Allocate(Renderer::ImplPool, renderPassTextureSize(renderPass), renderPassTextureFormat(renderPass), ResourceProvider::TextureUsageFramebuffer))
return false;
return bindFramebufferToTexture(frame, texture, renderPass->outputRect());

@ -478,7 +478,7 @@ scoped_ptr<ScopedResource> GLRenderer::drawBackgroundFilters(
int filteredDeviceBackgroundTextureId = texture->getTextureHandle();
scoped_ptr<ScopedResource> backgroundTexture = ScopedResource::create(m_resourceProvider);
if (!backgroundTexture->allocate(Renderer::ImplPool, quad->quadRect().size(), GL_RGBA, ResourceProvider::TextureUsageFramebuffer))
if (!backgroundTexture->Allocate(Renderer::ImplPool, quad->quadRect().size(), GL_RGBA, ResourceProvider::TextureUsageFramebuffer))
return scoped_ptr<ScopedResource>();
const RenderPass* targetRenderPass = frame.currentRenderPass;
@ -1277,7 +1277,7 @@ bool GLRenderer::getFramebufferTexture(ScopedResource* texture, const gfx::Rect&
{
DCHECK(!texture->id() || (texture->size() == deviceRect.size() && texture->format() == GL_RGB));
if (!texture->id() && !texture->allocate(Renderer::ImplPool, deviceRect.size(), GL_RGB, ResourceProvider::TextureUsageAny))
if (!texture->id() && !texture->Allocate(Renderer::ImplPool, deviceRect.size(), GL_RGB, ResourceProvider::TextureUsageAny))
return false;
ResourceProvider::ScopedWriteLockGL lock(m_resourceProvider, texture->id());

@ -76,10 +76,10 @@ void HeadsUpDisplayLayerImpl::willDraw(ResourceProvider* resourceProvider)
// FIXME: Scale the HUD by deviceScale to make it more friendly under high DPI.
if (m_hudTexture->size() != bounds())
m_hudTexture->free();
m_hudTexture->Free();
if (!m_hudTexture->id())
m_hudTexture->allocate(Renderer::ImplPool, bounds(), GL_RGBA, ResourceProvider::TextureUsageAny);
m_hudTexture->Allocate(Renderer::ImplPool, bounds(), GL_RGBA, ResourceProvider::TextureUsageAny);
}
void HeadsUpDisplayLayerImpl::appendQuads(QuadSink& quadSink, AppendQuadsData& appendQuadsData)

@ -642,7 +642,7 @@ size_t LayerTreeHost::calculateMemoryForRenderSurfaces(const LayerList& updateLi
Layer* renderSurfaceLayer = updateList[i].get();
RenderSurface* renderSurface = renderSurfaceLayer->renderSurface();
size_t bytes = Resource::memorySizeBytes(renderSurface->contentRect().size(), GL_RGBA);
size_t bytes = Resource::MemorySizeBytes(renderSurface->contentRect().size(), GL_RGBA);
contentsTextureBytes += bytes;
if (renderSurfaceLayer->backgroundFilters().isEmpty())
@ -651,7 +651,7 @@ size_t LayerTreeHost::calculateMemoryForRenderSurfaces(const LayerList& updateLi
if (bytes > maxBackgroundTextureBytes)
maxBackgroundTextureBytes = bytes;
if (!readbackBytes)
readbackBytes = Resource::memorySizeBytes(m_deviceViewportSize, GL_RGBA);
readbackBytes = Resource::MemorySizeBytes(m_deviceViewportSize, GL_RGBA);
}
return readbackBytes + maxBackgroundTextureBytes + contentsTextureBytes;
}

@ -28,7 +28,7 @@ PrioritizedResource::PrioritizedResource(PrioritizedResourceManager* manager, gf
// m_manager is set in registerTexture() so validity can be checked.
DCHECK(format || size.IsEmpty());
if (format)
m_bytes = Resource::memorySizeBytes(size, format);
m_bytes = Resource::MemorySizeBytes(size, format);
if (manager)
manager->registerTexture(this);
}
@ -55,7 +55,7 @@ void PrioritizedResource::setDimensions(gfx::Size size, GLenum format)
m_isAbovePriorityCutoff = false;
m_format = format;
m_size = size;
m_bytes = Resource::memorySizeBytes(size, format);
m_bytes = Resource::MemorySizeBytes(size, format);
DCHECK(m_manager || !m_backing);
if (m_manager)
m_manager->returnBackingTexture(this);
@ -158,7 +158,7 @@ void PrioritizedResource::Backing::deleteResource(ResourceProvider* resourceProv
#endif
resourceProvider->deleteResource(id());
setId(0);
set_id(0);
m_resourceHasBeenDeleted = true;
}

@ -36,7 +36,7 @@ public:
size_t texturesMemorySize(size_t textureCount)
{
return Resource::memorySizeBytes(m_textureSize, m_textureFormat) * textureCount;
return Resource::MemorySizeBytes(m_textureSize, m_textureFormat) * textureCount;
}
scoped_ptr<PrioritizedResourceManager> createManager(size_t maxTextures)

@ -7,41 +7,38 @@
namespace cc {
void Resource::setDimensions(const gfx::Size& size, GLenum format)
{
m_size = size;
m_format = format;
void Resource::set_dimensions(const gfx::Size& size, GLenum format) {
size_ = size;
format_ = format;
}
size_t Resource::bytes() const
{
if (m_size.IsEmpty())
return 0u;
size_t Resource::bytes() const {
if (size_.IsEmpty())
return 0;
return memorySizeBytes(m_size, m_format);
return MemorySizeBytes(size_, format_);
}
size_t Resource::bytesPerPixel(GLenum format)
{
unsigned int componentsPerPixel = 0;
unsigned int bytesPerComponent = 1;
switch (format) {
size_t Resource::BytesPerPixel(GLenum format) {
size_t components_per_pixel = 0;
size_t bytes_per_component = 1;
switch (format) {
case GL_RGBA:
case GL_BGRA_EXT:
componentsPerPixel = 4;
break;
components_per_pixel = 4;
break;
case GL_LUMINANCE:
componentsPerPixel = 1;
break;
components_per_pixel = 1;
break;
default:
NOTREACHED();
}
return componentsPerPixel * bytesPerComponent;
NOTREACHED();
}
return components_per_pixel * bytes_per_component;
}
size_t Resource::memorySizeBytes(const gfx::Size& size, GLenum format)
{
return bytesPerPixel(format) * size.width() * size.height();
size_t Resource::MemorySizeBytes(const gfx::Size& size, GLenum format) {
return BytesPerPixel(format) * size.width() * size.height();
}
} // namespace cc

@ -13,31 +13,30 @@
namespace cc {
class CC_EXPORT Resource {
public:
Resource() : m_id(0) { }
Resource(unsigned id, gfx::Size size, GLenum format)
: m_id(id)
, m_size(size)
, m_format(format) { }
public:
Resource() : id_(0) { }
Resource(unsigned id, gfx::Size size, GLenum format)
: id_(id), size_(size), format_(format) { }
ResourceProvider::ResourceId id() const { return m_id; }
const gfx::Size& size() const { return m_size; }
GLenum format() const { return m_format; }
ResourceProvider::ResourceId id() const { return id_; }
const gfx::Size& size() const { return size_; }
GLenum format() const { return format_; }
void setId(ResourceProvider::ResourceId id) { m_id = id; }
void setDimensions(const gfx::Size&, GLenum format);
size_t bytes() const;
size_t bytes() const;
static size_t BytesPerPixel(GLenum format);
static size_t MemorySizeBytes(const gfx::Size& size, GLenum format);
static size_t bytesPerPixel(GLenum format);
static size_t memorySizeBytes(const gfx::Size&, GLenum format);
protected:
void set_id(ResourceProvider::ResourceId id) { id_ = id; }
void set_dimensions(const gfx::Size&, GLenum format);
private:
ResourceProvider::ResourceId m_id;
gfx::Size m_size;
GLenum m_format;
private:
ResourceProvider::ResourceId id_;
gfx::Size size_;
GLenum format_;
};
}
} // namespace cc
#endif // CC_RESOURCE_H_

@ -6,46 +6,42 @@
namespace cc {
ScopedResource::ScopedResource(ResourceProvider* resourceProvider)
: m_resourceProvider(resourceProvider)
{
DCHECK(m_resourceProvider);
ScopedResource::ScopedResource(ResourceProvider* resource_provider)
: resource_provider_(resource_provider) {
DCHECK(resource_provider_);
}
ScopedResource::~ScopedResource()
{
free();
ScopedResource::~ScopedResource() {
Free();
}
bool ScopedResource::allocate(int pool, const gfx::Size& size, GLenum format, ResourceProvider::TextureUsageHint hint)
{
DCHECK(!id());
DCHECK(!size.IsEmpty());
bool ScopedResource::Allocate(int pool, const gfx::Size& size, GLenum format,
ResourceProvider::TextureUsageHint hint) {
DCHECK(!id());
DCHECK(!size.IsEmpty());
setDimensions(size, format);
setId(m_resourceProvider->createResource(pool, size, format, hint));
set_dimensions(size, format);
set_id(resource_provider_->createResource(pool, size, format, hint));
#ifndef NDEBUG
m_allocateThreadIdentifier = base::PlatformThread::CurrentId();
allocate_thread_id_ = base::PlatformThread::CurrentId();
#endif
return id();
return id();
}
void ScopedResource::free()
{
if (id()) {
void ScopedResource::Free() {
if (id()) {
#ifndef NDEBUG
DCHECK(m_allocateThreadIdentifier == base::PlatformThread::CurrentId());
DCHECK(allocate_thread_id_ == base::PlatformThread::CurrentId());
#endif
m_resourceProvider->deleteResource(id());
}
setId(0);
resource_provider_->deleteResource(id());
}
set_id(0);
}
void ScopedResource::leak()
{
setId(0);
void ScopedResource::Leak() {
set_id(0);
}
} // namespace cc

@ -17,31 +17,30 @@
namespace cc {
class CC_EXPORT ScopedResource : protected Resource {
public:
static scoped_ptr<ScopedResource> create(ResourceProvider* resourceProvider) { return make_scoped_ptr(new ScopedResource(resourceProvider)); }
virtual ~ScopedResource();
class CC_EXPORT ScopedResource : public Resource {
public:
static scoped_ptr<ScopedResource> create(
ResourceProvider* resource_provider) {
return make_scoped_ptr(new ScopedResource(resource_provider));
}
virtual ~ScopedResource();
using Resource::id;
using Resource::size;
using Resource::format;
using Resource::bytes;
bool Allocate(int pool, const gfx::Size&, GLenum format,
ResourceProvider::TextureUsageHint);
void Free();
void Leak();
bool allocate(int pool, const gfx::Size&, GLenum format, ResourceProvider::TextureUsageHint);
void free();
void leak();
protected:
explicit ScopedResource(ResourceProvider*);
protected:
explicit ScopedResource(ResourceProvider*);
private:
ResourceProvider* m_resourceProvider;
private:
ResourceProvider* resource_provider_;
#ifndef NDEBUG
base::PlatformThreadId m_allocateThreadIdentifier;
base::PlatformThreadId allocate_thread_id_;
#endif
DISALLOW_COPY_AND_ASSIGN(ScopedResource);
DISALLOW_COPY_AND_ASSIGN(ScopedResource);
};
}

@ -34,7 +34,7 @@ TEST(ScopedResourceTest, CreateScopedResource)
scoped_ptr<GraphicsContext> context(createFakeGraphicsContext());
scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(context.get()));
scoped_ptr<ScopedResource> texture = ScopedResource::create(resourceProvider.get());
texture->allocate(Renderer::ImplPool, gfx::Size(30, 30), GL_RGBA, ResourceProvider::TextureUsageAny);
texture->Allocate(Renderer::ImplPool, gfx::Size(30, 30), GL_RGBA, ResourceProvider::TextureUsageAny);
// The texture has an allocated byte-size now.
size_t expectedBytes = 30 * 30 * 4;
@ -54,7 +54,7 @@ TEST(ScopedResourceTest, ScopedResourceIsDeleted)
scoped_ptr<ScopedResource> texture = ScopedResource::create(resourceProvider.get());
EXPECT_EQ(0u, resourceProvider->numResources());
texture->allocate(Renderer::ImplPool, gfx::Size(30, 30), GL_RGBA, ResourceProvider::TextureUsageAny);
texture->Allocate(Renderer::ImplPool, gfx::Size(30, 30), GL_RGBA, ResourceProvider::TextureUsageAny);
EXPECT_LT(0u, texture->id());
EXPECT_EQ(1u, resourceProvider->numResources());
}
@ -64,10 +64,10 @@ TEST(ScopedResourceTest, ScopedResourceIsDeleted)
{
scoped_ptr<ScopedResource> texture = ScopedResource::create(resourceProvider.get());
EXPECT_EQ(0u, resourceProvider->numResources());
texture->allocate(Renderer::ImplPool, gfx::Size(30, 30), GL_RGBA, ResourceProvider::TextureUsageAny);
texture->Allocate(Renderer::ImplPool, gfx::Size(30, 30), GL_RGBA, ResourceProvider::TextureUsageAny);
EXPECT_LT(0u, texture->id());
EXPECT_EQ(1u, resourceProvider->numResources());
texture->free();
texture->Free();
EXPECT_EQ(0u, resourceProvider->numResources());
}
}
@ -81,15 +81,15 @@ TEST(ScopedResourceTest, LeakScopedResource)
scoped_ptr<ScopedResource> texture = ScopedResource::create(resourceProvider.get());
EXPECT_EQ(0u, resourceProvider->numResources());
texture->allocate(Renderer::ImplPool, gfx::Size(30, 30), GL_RGBA, ResourceProvider::TextureUsageAny);
texture->Allocate(Renderer::ImplPool, gfx::Size(30, 30), GL_RGBA, ResourceProvider::TextureUsageAny);
EXPECT_LT(0u, texture->id());
EXPECT_EQ(1u, resourceProvider->numResources());
texture->leak();
texture->Leak();
EXPECT_EQ(0u, texture->id());
EXPECT_EQ(1u, resourceProvider->numResources());
texture->free();
texture->Free();
EXPECT_EQ(0u, texture->id());
EXPECT_EQ(1u, resourceProvider->numResources());
}

@ -228,7 +228,7 @@ void TextureUploader::uploadWithTexSubImage(const uint8* image,
gfx::Vector2d offset(source_rect.origin() - image_rect.origin());
const uint8* pixel_source;
unsigned int bytes_per_pixel = Resource::bytesPerPixel(format);
unsigned int bytes_per_pixel = Resource::BytesPerPixel(format);
if (image_rect.width() == source_rect.width() && !offset.x()) {
pixel_source = &image[bytes_per_pixel * offset.y() * image_rect.width()];
@ -312,7 +312,7 @@ void TextureUploader::uploadWithMapTexSubImage(const uint8* image,
return;
}
unsigned int bytes_per_pixel = Resource::bytesPerPixel(format);
unsigned int bytes_per_pixel = Resource::BytesPerPixel(format);
if (image_rect.width() == source_rect.width() && !offset.x()) {
memcpy(pixel_dest,