OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "webkit/glue/plugins/pepper_resource_tracker.h" | 5 #include "webkit/glue/plugins/pepper_resource_tracker.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "third_party/ppapi/c/pp_resource.h" | 10 #include "third_party/ppapi/c/pp_resource.h" |
11 #include "webkit/glue/plugins/pepper_device_context_2d.h" | 11 #include "webkit/glue/plugins/pepper_device_context_2d.h" |
12 #include "webkit/glue/plugins/pepper_image_data.h" | 12 #include "webkit/glue/plugins/pepper_image_data.h" |
13 #include "webkit/glue/plugins/pepper_resource.h" | 13 #include "webkit/glue/plugins/pepper_resource.h" |
14 | 14 |
15 namespace pepper { | 15 namespace pepper { |
16 | 16 |
17 ResourceTracker::ResourceTracker() { | 17 ResourceTracker::ResourceTracker() { |
18 } | 18 } |
19 | 19 |
20 ResourceTracker::~ResourceTracker() { | 20 ResourceTracker::~ResourceTracker() { |
21 } | 21 } |
22 | 22 |
23 // static | 23 // static |
24 ResourceTracker* ResourceTracker::Get() { | 24 ResourceTracker* ResourceTracker::Get() { |
25 return Singleton<ResourceTracker>::get(); | 25 return Singleton<ResourceTracker>::get(); |
26 } | 26 } |
27 | 27 |
28 scoped_refptr<Resource> ResourceTracker::GetResource(PP_Resource res) const { | 28 scoped_refptr<Resource> ResourceTracker::GetResource(PP_Resource res) const { |
29 AutoLock lock(lock_); | 29 AutoLock lock(lock_); |
30 Resource* resource = reinterpret_cast<Resource*>(res.id); | 30 Resource* resource = reinterpret_cast<Resource*>(res); |
31 if (live_resources_.find(resource) == live_resources_.end()) | 31 if (live_resources_.find(resource) == live_resources_.end()) |
32 return scoped_refptr<Resource>(); | 32 return scoped_refptr<Resource>(); |
33 return scoped_refptr<Resource>(resource); | 33 return scoped_refptr<Resource>(resource); |
34 } | 34 } |
35 | 35 |
36 void ResourceTracker::AddResource(Resource* resource) { | 36 void ResourceTracker::AddResource(Resource* resource) { |
37 AutoLock lock(lock_); | 37 AutoLock lock(lock_); |
38 DCHECK(live_resources_.find(resource) == live_resources_.end()); | 38 DCHECK(live_resources_.find(resource) == live_resources_.end()); |
39 live_resources_.insert(resource); | 39 live_resources_.insert(resource); |
40 } | 40 } |
(...skipping 18 matching lines...) Expand all Loading... |
59 | 59 |
60 scoped_refptr<ImageData> ResourceTracker::GetAsImageData( | 60 scoped_refptr<ImageData> ResourceTracker::GetAsImageData( |
61 PP_Resource res) const { | 61 PP_Resource res) const { |
62 scoped_refptr<Resource> resource = GetResource(res); | 62 scoped_refptr<Resource> resource = GetResource(res); |
63 if (!resource.get()) | 63 if (!resource.get()) |
64 return scoped_refptr<ImageData>(); | 64 return scoped_refptr<ImageData>(); |
65 return scoped_refptr<ImageData>(resource->AsImageData()); | 65 return scoped_refptr<ImageData>(resource->AsImageData()); |
66 } | 66 } |
67 | 67 |
68 } // namespace pepper | 68 } // namespace pepper |
OLD | NEW |