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

Unified Diff: content/browser/android/transient_ui_resource.cc

Issue 143803004: android: Migrate old content readback to use async readback (and delegated renderer) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: turn clipping off for readback Created 6 years, 11 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 side-by-side diff with in-line comments
Download patch
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..386f6d2f1d50d2f05b77af3ca964f40a53721c1b
--- /dev/null
+++ b/content/browser/android/transient_ui_resource.cc
@@ -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 "content/browser/android/transient_ui_resource.h"
+
+#include "base/basictypes.h"
+#include "base/bind.h"
+#include "cc/resources/etc1_pixel_ref.h"
+#include "cc/resources/ui_resource_bitmap.h"
+#include "cc/trees/layer_tree_host.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;
+ }
+
+ SkImageInfo info = {4, 4, kPMColor_SkColorType, kPremul_SkAlphaType};
+ size_t rowBytes = info.minRowBytes();
+ scoped_ptr<uint8_t[]> pixels(new uint8_t[rowBytes * info.fHeight]);
+ skia::RefPtr<cc::ETC1PixelRef> etc1_pixel_ref =
+ skia::AdoptRef(new cc::ETC1PixelRef(info, rowBytes, pixels.Pass()));
+ return cc::UIResourceBitmap(etc1_pixel_ref,
+ gfx::Size(info.fWidth, info.fHeight));
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698