| Index: content/browser/android/transient_ui_resource.cc
|
| diff --git a/content/browser/android/transient_ui_resource.cc b/content/browser/android/transient_ui_resource.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..1ec6a6ed0329aabcc4aa9c2523f3f3213fcc4c99
|
| --- /dev/null
|
| +++ b/content/browser/android/transient_ui_resource.cc
|
| @@ -0,0 +1,53 @@
|
| +// 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 "content/browser/android/transient_ui_resource.h"
|
| +
|
| +#include "base/basictypes.h"
|
| +#include "base/bind.h"
|
| +#include "cc/resources/ui_resource_bitmap.h"
|
| +#include "cc/trees/layer_tree_host.h"
|
| +#include "third_party/skia/include/core/SkBitmap.h"
|
| +
|
| +namespace content {
|
| +
|
| +scoped_ptr<TransientUIResource> TransientUIResource::Create(
|
| + cc::LayerTreeHost* host,
|
| + const cc::UIResourceBitmap& bitmap) {
|
| + return make_scoped_ptr(new TransientUIResource(host, bitmap));
|
| +}
|
| +
|
| +TransientUIResource::TransientUIResource(cc::LayerTreeHost* host,
|
| + const cc::UIResourceBitmap& bitmap)
|
| + : bitmap_(new cc::UIResourceBitmap(bitmap)), host_(host) {
|
| + DCHECK(host_);
|
| + id_ = host_->CreateUIResource(this);
|
| +}
|
| +
|
| +// User must make sure that host is still valid before this object goes out of
|
| +// scope.
|
| +TransientUIResource::~TransientUIResource() {
|
| + if (id_) {
|
| + DCHECK(host_);
|
| + host_->DeleteUIResource(id_);
|
| + }
|
| +}
|
| +
|
| +cc::UIResourceBitmap TransientUIResource::GetBitmap(cc::UIResourceId uid,
|
| + bool resource_lost) {
|
| + if (bitmap_) {
|
| + cc::UIResourceBitmap out_bitmap = *bitmap_.get();
|
| + // Frees the bitmap after it's been accessed.
|
| + bitmap_.reset();
|
| + return out_bitmap;
|
| + }
|
| +
|
| + SkBitmap place_holder;
|
| + place_holder.setConfig(SkBitmap::kARGB_8888_Config, 1, 1);
|
| + place_holder.allocPixels();
|
| + place_holder.setImmutable();
|
| + return cc::UIResourceBitmap(place_holder);
|
| +}
|
| +
|
| +} // namespace content
|
|
|