diff options
Diffstat (limited to 'cc/scoped_resource.cc')
-rw-r--r-- | cc/scoped_resource.cc | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/cc/scoped_resource.cc b/cc/scoped_resource.cc new file mode 100644 index 0000000..5729718 --- /dev/null +++ b/cc/scoped_resource.cc @@ -0,0 +1,53 @@ +// Copyright 2012 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 "config.h" + +#include "cc/scoped_resource.h" + +namespace cc { + +ScopedResource::ScopedResource(ResourceProvider* resourceProvider) + : m_resourceProvider(resourceProvider) +{ + DCHECK(m_resourceProvider); +} + +ScopedResource::~ScopedResource() +{ + free(); +} + +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)); + +#ifndef NDEBUG + m_allocateThreadIdentifier = base::PlatformThread::CurrentId(); +#endif + + return id(); +} + +void ScopedResource::free() +{ + if (id()) { +#ifndef NDEBUG + DCHECK(m_allocateThreadIdentifier == base::PlatformThread::CurrentId()); +#endif + m_resourceProvider->deleteResource(id()); + } + setId(0); +} + +void ScopedResource::leak() +{ + setId(0); +} + +} // namespace cc |