Index: cc/resources/scoped_ui_resource.cc |
=================================================================== |
--- cc/resources/scoped_ui_resource.cc (revision 0) |
+++ cc/resources/scoped_ui_resource.cc (revision 0) |
@@ -0,0 +1,55 @@ |
+// Copyright 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "cc/resources/scoped_ui_resource.h" |
+ |
+#include "base/basictypes.h" |
+#include "base/bind.h" |
+#include "cc/trees/layer_tree_host.h" |
+ |
+namespace cc { |
+ |
+ScopedUIResource::ScopedUIResource(LayerTreeHost* host, |
+ scoped_refptr<UIResourceBitmap> bitmap) |
+ : id_(0), |
+ bitmap_(bitmap) { |
+ ResetResource(host, bitmap); |
+} |
+ |
+scoped_refptr<ScopedUIResource> ScopedUIResource::Create( |
+ LayerTreeHost* host, |
+ scoped_refptr<UIResourceBitmap> bitmap) { |
+ return make_scoped_refptr(new ScopedUIResource(host, bitmap)); |
+} |
+ |
+// ClearResource deletes the bitmap owned by this class. |
+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.
|
+ id_ = 0; |
+ bitmap_ = NULL; |
+} |
+ |
+void ScopedUIResource::ResetResource(LayerTreeHost* host, |
+ scoped_refptr<UIResourceBitmap> bitmap) { |
+ // If there was already a resource, release it. |
+ 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.
|
+ |
+ bitmap_ = bitmap; |
+ 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.
|
+ id_ = |
+ host->CreateUIResource(base::Bind(&ScopedUIResource::GetBitmap, this)); |
+} |
+ |
+// ReleaseResource deletes the UI resource allocated in the resource manager. |
+void ScopedUIResource::ReleaseResource(LayerTreeHost* host) { |
+ if (host && id_) |
+ host->DeleteUIResource(id_); |
+ ClearResource(); |
+} |
+ |
+scoped_refptr<UIResourceBitmap> ScopedUIResource::GetBitmap( |
+ bool resource_lost) { |
+ return bitmap_; |
+} |
+ |
+} // namespace cc |
Property changes on: cc/resources/scoped_ui_resource.cc |
___________________________________________________________________ |
Added: svn:eol-style |
+ LF |