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

Side by Side Diff: chrome/browser/android/compositor/layer/crushed_sprite_layer.cc

Issue 1337703002: [Contextual Search] Add support for crushed sprites and animate the search provider icon (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 2 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 2015 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 "chrome/browser/android/compositor/layer/crushed_sprite_layer.h"
6
7 #include "cc/layers/layer.h"
8 #include "cc/layers/picture_layer.h"
9 #include "cc/playback/display_item_list.h"
10 #include "cc/playback/display_item_list_settings.h"
11 #include "cc/playback/drawing_display_item.h"
12 #include "content/public/browser/android/compositor.h"
13 #include "third_party/skia/include/core/SkPictureRecorder.h"
14 #include "ui/gfx/canvas.h"
15 #include "ui/gfx/skia_util.h"
16
17 namespace chrome {
18 namespace android {
19
20 // static
21 scoped_refptr<CrushedSpriteLayer> CrushedSpriteLayer::Create() {
22 return make_scoped_refptr(new CrushedSpriteLayer());
23 }
24
25 void CrushedSpriteLayer::PaintContents(
26 SkCanvas* canvas,
27 const gfx::Rect& clip,
28 PaintingControlSetting painting_control) {
29 gfx::Rect rect(bounds());
30 canvas->clipRect(RectToSkRect(rect));
31
32 if (paint_previous_frame_)
33 canvas->drawPicture(previous_frame_.get());
34
35 if (src_dst_rects_.empty() || src_bitmap_.empty())
36 return;
37
38 for (auto rect : src_dst_rects_) {
39 canvas->drawBitmapRect(src_bitmap_,
40 gfx::RectToSkRect(rect.first),
41 gfx::RectToSkRect(rect.second),
42 nullptr);
43 }
44 }
45
46 void CrushedSpriteLayer::UpdateCrushedSprite(
47 const SkBitmap& src_bitmap,
48 const std::vector<std::pair<gfx::Rect, gfx::Rect>>& src_dst_rects,
49 bool paint_previous_frame) {
50 src_bitmap_ = src_bitmap;
51 src_dst_rects_ = src_dst_rects;
52 paint_previous_frame_ = paint_previous_frame;
53 SetNeedsDisplay();
54 }
55
56 scoped_refptr<cc::DisplayItemList>
57 CrushedSpriteLayer::PaintContentsToDisplayList(
58 const gfx::Rect& clip,
59 PaintingControlSetting painting_control) {
60 cc::DisplayItemListSettings settings;
61 settings.use_cached_picture = true;
62 scoped_refptr<cc::DisplayItemList> display_list =
63 cc::DisplayItemList::Create(clip, settings);
64
65 SkPictureRecorder recorder;
66 SkCanvas* canvas = recorder.beginRecording(gfx::RectToSkRect(clip));
67 PaintContents(canvas, clip, painting_control);
68 previous_frame_ =
69 skia::AdoptRef(recorder.endRecordingAsPicture());
70 auto* item = display_list->CreateAndAppendItem<cc::DrawingDisplayItem>();
71 item->SetNew(previous_frame_);
72
73 display_list->Finalize();
74 return display_list;
75 }
76
77 bool CrushedSpriteLayer::FillsBoundsCompletely() const {
78 return false;
79 }
80
81 size_t CrushedSpriteLayer::GetApproximateUnsharedMemoryUsage() const {
82 size_t memory_usage = 0;
83 if (previous_frame_.get()) {
84 // TODO(twellington): I have a question for reviewiers - I think
85 // previous_frame_ is shared with the DisplayList when it's passed in
86 // on line 75 above. Does that seem right? If so, it doesn't need to
87 // be included in the memory usage.
88 memory_usage += previous_frame_->approximateBytesUsed();
89 }
90 if (!src_bitmap_.isNull()) {
91 // TODO(twellington): Same question here about shared memory - I think
92 // the underlying bits for SkPixelRef are shared w/ the UI resource.
93 memory_usage += src_bitmap_.getSize();
94 }
95 if (!src_dst_rects_.empty()) {
96 memory_usage += sizeof(std::vector<std::pair<gfx::Rect, gfx::Rect>>);
97 memory_usage += sizeof(gfx::Rect) * src_dst_rects_.size() * 2;
98 }
99 return memory_usage;
100 }
101
102 CrushedSpriteLayer::CrushedSpriteLayer()
103 : cc::PictureLayer(content::Compositor::LayerSettings(), this),
104 paint_previous_frame_(false) {
105 }
106
107 CrushedSpriteLayer::~CrushedSpriteLayer() {
108 }
109
110 } // namespace android
111 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698