forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheads_up_display_layer.cc
86 lines (69 loc) · 2.65 KB
/
heads_up_display_layer.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright 2012 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 "cc/layers/heads_up_display_layer.h"
#include <algorithm>
#include "base/trace_event/trace_event.h"
#include "cc/layers/heads_up_display_layer_impl.h"
#include "cc/proto/layer.pb.h"
#include "cc/trees/layer_tree_host.h"
namespace cc {
scoped_refptr<HeadsUpDisplayLayer> HeadsUpDisplayLayer::Create(
const LayerSettings& settings) {
return make_scoped_refptr(new HeadsUpDisplayLayer(settings));
}
HeadsUpDisplayLayer::HeadsUpDisplayLayer(const LayerSettings& settings)
: Layer(settings),
typeface_(skia::AdoptRef(
SkTypeface::CreateFromName("times new roman", SkTypeface::kNormal))) {
if (!typeface_) {
typeface_ = skia::AdoptRef(
SkTypeface::CreateFromName("monospace", SkTypeface::kBold));
}
DCHECK(typeface_.get());
SetIsDrawable(true);
UpdateDrawsContent(HasDrawableContent());
}
HeadsUpDisplayLayer::~HeadsUpDisplayLayer() {}
void HeadsUpDisplayLayer::PrepareForCalculateDrawProperties(
const gfx::Size& device_viewport, float device_scale_factor) {
gfx::Size device_viewport_in_layout_pixels = gfx::Size(
device_viewport.width() / device_scale_factor,
device_viewport.height() / device_scale_factor);
gfx::Size bounds;
gfx::Transform matrix;
matrix.MakeIdentity();
if (layer_tree_host()->debug_state().ShowHudRects()) {
int max_texture_size =
layer_tree_host()->GetRendererCapabilities().max_texture_size;
bounds.SetSize(std::min(max_texture_size,
device_viewport_in_layout_pixels.width()),
std::min(max_texture_size,
device_viewport_in_layout_pixels.height()));
} else {
int size = 256;
bounds.SetSize(size, size);
matrix.Translate(device_viewport_in_layout_pixels.width() - size, 0.0);
}
SetBounds(bounds);
SetTransform(matrix);
}
bool HeadsUpDisplayLayer::HasDrawableContent() const {
return true;
}
scoped_ptr<LayerImpl> HeadsUpDisplayLayer::CreateLayerImpl(
LayerTreeImpl* tree_impl) {
return HeadsUpDisplayLayerImpl::Create(tree_impl, layer_id_);
}
void HeadsUpDisplayLayer::SetTypeForProtoSerialization(
proto::LayerNode* proto) const {
proto->set_type(proto::LayerNode::HEADS_UP_DISPLAY_LAYER);
}
void HeadsUpDisplayLayer::PushPropertiesTo(LayerImpl* layer) {
Layer::PushPropertiesTo(layer);
TRACE_EVENT0("cc", "HeadsUpDisplayLayer::PushPropertiesTo");
HeadsUpDisplayLayerImpl* layer_impl =
static_cast<HeadsUpDisplayLayerImpl*>(layer);
layer_impl->SetHUDTypeface(typeface_);
}
} // namespace cc