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

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: Manually scale crushed sprites 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 if (scale_ != 1.f)
39 canvas->scale(scale_, scale_);
40
41 for (auto rect : src_dst_rects_) {
42 canvas->drawBitmapRect(src_bitmap_,
43 gfx::RectToSkRect(rect.first),
44 gfx::RectToSkRect(rect.second),
45 nullptr);
46 }
47 }
48
49 void CrushedSpriteLayer::UpdateCrushedSprite(
50 const SkBitmap& src_bitmap,
51 const std::vector<std::pair<gfx::Rect, gfx::Rect>>& src_dst_rects,
52 bool paint_previous_frame,
53 float scale) {
54 src_bitmap_ = src_bitmap;
55 src_dst_rects_ = src_dst_rects;
56 paint_previous_frame_ = paint_previous_frame;
57 scale_ = scale;
58 SetNeedsDisplay();
59 }
60
61 scoped_refptr<cc::DisplayItemList>
62 CrushedSpriteLayer::PaintContentsToDisplayList(
63 const gfx::Rect& clip,
64 PaintingControlSetting painting_control) {
65 cc::DisplayItemListSettings settings;
66 settings.use_cached_picture = true;
67 scoped_refptr<cc::DisplayItemList> display_list =
68 cc::DisplayItemList::Create(clip, settings);
69
70 SkPictureRecorder recorder;
71 SkCanvas* canvas = recorder.beginRecording(gfx::RectToSkRect(clip));
72 PaintContents(canvas, clip, painting_control);
73 previous_frame_ =
74 skia::AdoptRef(recorder.endRecordingAsPicture());
75 auto* item = display_list->CreateAndAppendItem<cc::DrawingDisplayItem>();
76 item->SetNew(previous_frame_);
77
78 display_list->Finalize();
79 return display_list;
80 }
81
82 bool CrushedSpriteLayer::FillsBoundsCompletely() const {
83 return false;
84 }
85
86 size_t CrushedSpriteLayer::GetApproximateUnsharedMemoryUsage() const {
87 size_t memory_usage = 0;
88 if (previous_frame_.get()) {
89 // TODO(twellington): I have a question for reviewiers - I think
90 // previous_frame_ is shared with the DisplayList when it's passed in
91 // on line 75 above. Does that seem right? If so, it doesn't need to
92 // be included in the memory usage.
93 memory_usage += previous_frame_->approximateBytesUsed();
94 }
95 if (!src_bitmap_.isNull()) {
96 // TODO(twellington): Same question here about shared memory - I think
97 // the underlying bits for SkPixelRef are shared w/ the UI resource.
98 memory_usage += src_bitmap_.getSize();
99 }
100 if (!src_dst_rects_.empty()) {
101 memory_usage += sizeof(std::vector<std::pair<gfx::Rect, gfx::Rect>>);
102 memory_usage += sizeof(gfx::Rect) * src_dst_rects_.size() * 2;
103 }
104 return memory_usage;
105 }
106
107 CrushedSpriteLayer::CrushedSpriteLayer()
108 : cc::PictureLayer(content::Compositor::LayerSettings(), this),
109 paint_previous_frame_(false) {
110 }
111
112 CrushedSpriteLayer::~CrushedSpriteLayer() {
113 }
114
115 } // namespace android
116 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698