| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/resources/scoped_resource.h" | 5 #include "cc/resources/scoped_resource.h" |
| 6 | 6 |
| 7 namespace cc { | 7 namespace cc { |
| 8 | 8 |
| 9 ScopedResource::ScopedResource(ResourceProvider* resource_provider) | 9 ScopedResource::ScopedResource(ResourceProvider* resource_provider) |
| 10 : resource_provider_(resource_provider) { | 10 : resource_provider_(resource_provider) { |
| 11 DCHECK(resource_provider_); | 11 DCHECK(resource_provider_); |
| 12 } | 12 } |
| 13 | 13 |
| 14 ScopedResource::~ScopedResource() { | 14 ScopedResource::~ScopedResource() { |
| 15 Free(); | 15 Free(); |
| 16 } | 16 } |
| 17 | 17 |
| 18 void ScopedResource::Allocate(const gfx::Size& size, | 18 void ScopedResource::Allocate(const gfx::Size& size, |
| 19 ResourceProvider::TextureHint hint, | 19 ResourceProvider::TextureHint hint, |
| 20 ResourceFormat format) { | 20 ResourceFormat format) { |
| 21 DCHECK(!id()); | 21 DCHECK(!id()); |
| 22 DCHECK(!size.IsEmpty()); | 22 DCHECK(!size.IsEmpty()); |
| 23 | 23 |
| 24 set_dimensions(size, format); | 24 set_dimensions(size, format); |
| 25 set_id(resource_provider_->CreateResource( | 25 set_id(resource_provider_->CreateResource( |
| 26 size, GL_CLAMP_TO_EDGE, hint, format)); | 26 size, GL_CLAMP_TO_EDGE, hint, format)); |
| 27 | 27 |
| 28 #if DCHECK_IS_ON | 28 #if DCHECK_IS_ON() |
| 29 allocate_thread_id_ = base::PlatformThread::CurrentId(); | 29 allocate_thread_id_ = base::PlatformThread::CurrentId(); |
| 30 #endif | 30 #endif |
| 31 } | 31 } |
| 32 | 32 |
| 33 void ScopedResource::AllocateManaged(const gfx::Size& size, | 33 void ScopedResource::AllocateManaged(const gfx::Size& size, |
| 34 GLenum target, | 34 GLenum target, |
| 35 ResourceFormat format) { | 35 ResourceFormat format) { |
| 36 DCHECK(!id()); | 36 DCHECK(!id()); |
| 37 DCHECK(!size.IsEmpty()); | 37 DCHECK(!size.IsEmpty()); |
| 38 | 38 |
| 39 set_dimensions(size, format); | 39 set_dimensions(size, format); |
| 40 set_id(resource_provider_->CreateManagedResource( | 40 set_id(resource_provider_->CreateManagedResource( |
| 41 size, | 41 size, |
| 42 target, | 42 target, |
| 43 GL_CLAMP_TO_EDGE, | 43 GL_CLAMP_TO_EDGE, |
| 44 ResourceProvider::TextureHintImmutable, | 44 ResourceProvider::TextureHintImmutable, |
| 45 format)); | 45 format)); |
| 46 | 46 |
| 47 #if DCHECK_IS_ON | 47 #if DCHECK_IS_ON() |
| 48 allocate_thread_id_ = base::PlatformThread::CurrentId(); | 48 allocate_thread_id_ = base::PlatformThread::CurrentId(); |
| 49 #endif | 49 #endif |
| 50 } | 50 } |
| 51 | 51 |
| 52 void ScopedResource::Free() { | 52 void ScopedResource::Free() { |
| 53 if (id()) { | 53 if (id()) { |
| 54 #if DCHECK_IS_ON | 54 #if DCHECK_IS_ON() |
| 55 DCHECK(allocate_thread_id_ == base::PlatformThread::CurrentId()); | 55 DCHECK(allocate_thread_id_ == base::PlatformThread::CurrentId()); |
| 56 #endif | 56 #endif |
| 57 resource_provider_->DeleteResource(id()); | 57 resource_provider_->DeleteResource(id()); |
| 58 } | 58 } |
| 59 set_id(0); | 59 set_id(0); |
| 60 } | 60 } |
| 61 | 61 |
| 62 } // namespace cc | 62 } // namespace cc |
| OLD | NEW |