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

Side by Side 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, 10 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 unified diff | Download patch
OLDNEW
(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 "content/browser/android/transient_ui_resource.h"
6
7 #include "base/basictypes.h"
8 #include "base/bind.h"
9 #include "cc/resources/etc1_pixel_ref.h"
10 #include "cc/resources/ui_resource_bitmap.h"
11 #include "cc/trees/layer_tree_host.h"
12
13 namespace content {
14
15 scoped_ptr<TransientUIResource> TransientUIResource::Create(
16 cc::LayerTreeHost* host,
17 const cc::UIResourceBitmap& bitmap) {
18 return make_scoped_ptr(new TransientUIResource(host, bitmap));
19 }
20
21 TransientUIResource::TransientUIResource(cc::LayerTreeHost* host,
22 const cc::UIResourceBitmap& bitmap)
23 : bitmap_(new cc::UIResourceBitmap(bitmap)), host_(host) {
24 DCHECK(host_);
25 id_ = host_->CreateUIResource(this);
26 }
27
28 // User must make sure that host is still valid before this object goes out of
29 // scope.
30 TransientUIResource::~TransientUIResource() {
31 if (id_) {
32 DCHECK(host_);
33 host_->DeleteUIResource(id_);
34 }
35 }
36
37 cc::UIResourceBitmap TransientUIResource::GetBitmap(cc::UIResourceId uid,
38 bool resource_lost) {
39 if (bitmap_) {
40 cc::UIResourceBitmap out_bitmap = *bitmap_.get();
41 // Frees the bitmap after it's been accessed.
42 bitmap_.reset();
43 return out_bitmap;
44 }
45
46 SkImageInfo info = {4, 4, kPMColor_SkColorType, kPremul_SkAlphaType};
47 size_t rowBytes = info.minRowBytes();
48 scoped_ptr<uint8_t[]> pixels(new uint8_t[rowBytes * info.fHeight]);
49 skia::RefPtr<cc::ETC1PixelRef> etc1_pixel_ref =
50 skia::AdoptRef(new cc::ETC1PixelRef(info, rowBytes, pixels.Pass()));
51 return cc::UIResourceBitmap(etc1_pixel_ref,
52 gfx::Size(info.fWidth, info.fHeight));
53 }
54
55 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698