|
OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2013 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_ui_resource.h" | |
6 | |
7 #include "base/basictypes.h" | |
8 #include "base/bind.h" | |
9 #include "cc/trees/layer_tree_host.h" | |
10 | |
11 namespace cc { | |
12 | |
13 ScopedUIResource::ScopedUIResource(LayerTreeHost* host, | |
14 scoped_refptr<UIResourceBitmap> bitmap) | |
15 : id_(0), | |
16 bitmap_(bitmap) { | |
17 ResetResource(host, bitmap); | |
18 } | |
19 | |
20 scoped_refptr<ScopedUIResource> ScopedUIResource::Create( | |
21 LayerTreeHost* host, | |
22 scoped_refptr<UIResourceBitmap> bitmap) { | |
23 return make_scoped_refptr(new ScopedUIResource(host, bitmap)); | |
24 } | |
25 | |
26 // ClearResource deletes the bitmap owned by this class. | |
27 void ScopedUIResource::ClearResource() { | |
aelias_OOO_until_Jul13
2013/07/25 23:45:11
This method is not ever safe to call on its own, y
powei
2013/07/26 23:07:27
Done.
| |
28 id_ = 0; | |
29 bitmap_ = NULL; | |
30 } | |
31 | |
32 void ScopedUIResource::ResetResource(LayerTreeHost* host, | |
33 scoped_refptr<UIResourceBitmap> bitmap) { | |
34 // If there was already a resource, release it. | |
35 ReleaseResource(host); | |
aelias_OOO_until_Jul13
2013/07/25 23:45:11
No guarantee it's the same host.
powei
2013/07/26 23:07:27
Done.
| |
36 | |
37 bitmap_ = bitmap; | |
38 if (host) | |
aelias_OOO_until_Jul13
2013/07/25 23:45:11
Replace this if with DCHECK(host);
powei
2013/07/26 23:07:27
Done.
| |
39 id_ = | |
40 host->CreateUIResource(base::Bind(&ScopedUIResource::GetBitmap, this)); | |
41 } | |
42 | |
43 // ReleaseResource deletes the UI resource allocated in the resource manager. | |
44 void ScopedUIResource::ReleaseResource(LayerTreeHost* host) { | |
45 if (host && id_) | |
46 host->DeleteUIResource(id_); | |
47 ClearResource(); | |
48 } | |
49 | |
50 scoped_refptr<UIResourceBitmap> ScopedUIResource::GetBitmap( | |
51 bool resource_lost) { | |
52 return bitmap_; | |
53 } | |
54 | |
55 } // namespace cc | |
OLD | NEW |