OLD | NEW |
---|---|
(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(layer_->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 scoped_refptr<cc::Layer> CrushedSpriteLayer::layer() { | |
47 return layer_; | |
48 } | |
49 | |
50 void CrushedSpriteLayer::UpdateCrushedSprite( | |
51 const SkBitmap& src_bitmap, | |
52 const std::vector<std::pair<gfx::Rect, gfx::Rect>>& src_dst_rects, | |
53 bool paint_previous_frame) { | |
54 src_bitmap_ = src_bitmap; | |
55 src_dst_rects_ = src_dst_rects; | |
56 paint_previous_frame_ = paint_previous_frame; | |
57 layer_->SetNeedsDisplay(); | |
58 } | |
59 | |
60 scoped_refptr<cc::DisplayItemList> | |
61 CrushedSpriteLayer::PaintContentsToDisplayList( | |
62 const gfx::Rect& clip, | |
63 PaintingControlSetting painting_control) { | |
64 cc::DisplayItemListSettings settings; | |
65 settings.use_cached_picture = true; | |
66 scoped_refptr<cc::DisplayItemList> display_list = | |
67 cc::DisplayItemList::Create(clip, settings); | |
68 | |
69 SkPictureRecorder recorder; | |
70 SkCanvas* canvas = recorder.beginRecording(gfx::RectToSkRect(clip)); | |
71 PaintContents(canvas, clip, painting_control); | |
72 previous_frame_ = | |
73 skia::AdoptRef(recorder.endRecordingAsPicture()); | |
74 auto* item = display_list->CreateAndAppendItem<cc::DrawingDisplayItem>(); | |
75 item->SetNew(previous_frame_); | |
76 | |
77 display_list->Finalize(); | |
78 return display_list; | |
79 } | |
80 | |
81 bool CrushedSpriteLayer::FillsBoundsCompletely() const { | |
82 return false; | |
83 } | |
84 | |
85 size_t CrushedSpriteLayer::GetApproximateUnsharedMemoryUsage() const { | |
86 size_t memory_usage = 0; | |
87 if (previous_frame_.get()) { | |
88 // TODO(twellington): I have a question for reviewiers - I think | |
89 // previous_frame_ is shared with the DisplayList when it's passed in | |
90 // on line 75 above. Does that seem right? If so, it doesn't need to | |
91 // be included in the memory usage. | |
pedro (no code reviews)
2015/09/29 01:14:40
Good question. I don't know the answer. Same appli
David Trainor- moved to gerrit
2015/09/29 22:23:09
I would imagine it's asking memory that this class
Theresa
2015/10/01 01:57:31
As discussed offline, I'm going to leave in the sr
| |
92 memory_usage += previous_frame_->approximateBytesUsed(); | |
93 } | |
94 if (!src_bitmap_.isNull()) { | |
95 // TODO(twellington): Same question here about shared memory - I think | |
96 // the underlying bits for SkPixelRef are shared w/ the UI resource. | |
97 memory_usage += src_bitmap_.getSize(); | |
98 } | |
99 if (!src_dst_rects_.empty()) { | |
100 memory_usage += sizeof(std::vector<std::pair<gfx::Rect, gfx::Rect>>); | |
101 memory_usage += sizeof(gfx::Rect) * src_dst_rects_.size() * 2; | |
102 } | |
103 return memory_usage; | |
104 } | |
105 | |
106 CrushedSpriteLayer::CrushedSpriteLayer() | |
107 : layer_(cc::PictureLayer::Create(content::Compositor::LayerSettings(), | |
108 this)), | |
109 paint_previous_frame_(false) { | |
110 } | |
111 | |
112 CrushedSpriteLayer::~CrushedSpriteLayer() { | |
113 previous_frame_ = NULL; | |
David Trainor- moved to gerrit
2015/09/29 22:23:09
I'm not sure this is necessary. It will just run
Theresa
2015/10/01 01:57:31
Done.
| |
114 if (!src_bitmap_.isNull()) | |
115 src_bitmap_.reset(); | |
David Trainor- moved to gerrit
2015/09/29 22:23:09
Also might not be necessary? It looks like the un
Theresa
2015/10/01 01:57:31
I think you're right. I removed this and previous_
| |
116 } | |
117 | |
118 } // namespace android | |
119 } // namespace chrome | |
OLD | NEW |