- add sources.
[platform/framework/web/crosswalk.git] / src / cc / resources / scoped_resource.cc
1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "cc/resources/scoped_resource.h"
6
7 namespace cc {
8
9 ScopedResource::ScopedResource(ResourceProvider* resource_provider)
10     : resource_provider_(resource_provider) {
11   DCHECK(resource_provider_);
12 }
13
14 ScopedResource::~ScopedResource() {
15   Free();
16 }
17
18 bool ScopedResource::Allocate(gfx::Size size,
19                               ResourceProvider::TextureUsageHint hint,
20                               ResourceFormat format) {
21   DCHECK(!id());
22   DCHECK(!size.IsEmpty());
23
24   set_dimensions(size, format);
25   set_id(resource_provider_->CreateResource(
26       size, GL_CLAMP_TO_EDGE, hint, format));
27
28 #ifndef NDEBUG
29   allocate_thread_id_ = base::PlatformThread::CurrentId();
30 #endif
31
32   return id() != 0;
33 }
34
35 void ScopedResource::Free() {
36   if (id()) {
37 #ifndef NDEBUG
38     DCHECK(allocate_thread_id_ == base::PlatformThread::CurrentId());
39 #endif
40     resource_provider_->DeleteResource(id());
41   }
42   set_id(0);
43 }
44
45 void ScopedResource::Leak() {
46   set_id(0);
47 }
48
49 }  // namespace cc