Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(752)

Side by Side Diff: cc/resources/scoped_resource.cc

Issue 2240873003: Fix a bug that prevents all reuse of ResourcePool resources. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/resources/resource.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 const gfx::ColorSpace& color_space) { 21 const gfx::ColorSpace& color_space) {
22 DCHECK(!id()); 22 DCHECK(!id());
23 DCHECK(!size.IsEmpty()); 23 DCHECK(!size.IsEmpty());
24 24
25 set_dimensions(size, format); 25 set_dimensions(size, format);
26 set_id(resource_provider_->CreateResource(size, hint, format, color_space)); 26 set_id(resource_provider_->CreateResource(size, hint, format, color_space));
27 set_color_space(color_space);
27 28
28 #if DCHECK_IS_ON() 29 #if DCHECK_IS_ON()
29 allocate_thread_id_ = base::PlatformThread::CurrentId(); 30 allocate_thread_id_ = base::PlatformThread::CurrentId();
30 #endif 31 #endif
31 } 32 }
32 33
33 void ScopedResource::AllocateWithGpuMemoryBuffer( 34 void ScopedResource::AllocateWithGpuMemoryBuffer(
34 const gfx::Size& size, 35 const gfx::Size& size,
35 ResourceFormat format, 36 ResourceFormat format,
36 gfx::BufferUsage usage, 37 gfx::BufferUsage usage,
37 const gfx::ColorSpace& color_space) { 38 const gfx::ColorSpace& color_space) {
38 DCHECK(!id()); 39 DCHECK(!id());
39 DCHECK(!size.IsEmpty()); 40 DCHECK(!size.IsEmpty());
40 41
41 set_dimensions(size, format); 42 set_dimensions(size, format);
42 set_id(resource_provider_->CreateGpuMemoryBufferResource( 43 set_id(resource_provider_->CreateGpuMemoryBufferResource(
43 size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format, usage, 44 size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format, usage,
44 color_space)); 45 color_space));
46 set_color_space(color_space);
45 47
46 #if DCHECK_IS_ON() 48 #if DCHECK_IS_ON()
47 allocate_thread_id_ = base::PlatformThread::CurrentId(); 49 allocate_thread_id_ = base::PlatformThread::CurrentId();
48 #endif 50 #endif
49 } 51 }
50 52
51 void ScopedResource::Free() { 53 void ScopedResource::Free() {
52 if (id()) { 54 if (id()) {
53 #if DCHECK_IS_ON() 55 #if DCHECK_IS_ON()
54 DCHECK(allocate_thread_id_ == base::PlatformThread::CurrentId()); 56 DCHECK(allocate_thread_id_ == base::PlatformThread::CurrentId());
55 #endif 57 #endif
56 resource_provider_->DeleteResource(id()); 58 resource_provider_->DeleteResource(id());
57 } 59 }
58 set_id(0); 60 set_id(0);
59 } 61 }
60 62
61 } // namespace cc 63 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/resource.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698