• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2012 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 "cc/layers/heads_up_display_layer.h"
6 
7 #include <algorithm>
8 
9 #include "base/debug/trace_event.h"
10 #include "cc/layers/heads_up_display_layer_impl.h"
11 #include "cc/trees/layer_tree_host.h"
12 
13 namespace cc {
14 
Create()15 scoped_refptr<HeadsUpDisplayLayer> HeadsUpDisplayLayer::Create() {
16   return make_scoped_refptr(new HeadsUpDisplayLayer());
17 }
18 
HeadsUpDisplayLayer()19 HeadsUpDisplayLayer::HeadsUpDisplayLayer() {
20   SetIsDrawable(true);
21   UpdateDrawsContent(HasDrawableContent());
22 }
23 
~HeadsUpDisplayLayer()24 HeadsUpDisplayLayer::~HeadsUpDisplayLayer() {}
25 
PrepareForCalculateDrawProperties(const gfx::Size & device_viewport,float device_scale_factor)26 void HeadsUpDisplayLayer::PrepareForCalculateDrawProperties(
27     const gfx::Size& device_viewport, float device_scale_factor) {
28   gfx::Size device_viewport_in_layout_pixels = gfx::Size(
29       device_viewport.width() / device_scale_factor,
30       device_viewport.height() / device_scale_factor);
31 
32   gfx::Size bounds;
33   gfx::Transform matrix;
34   matrix.MakeIdentity();
35 
36   if (layer_tree_host()->debug_state().ShowHudRects()) {
37     int max_texture_size =
38         layer_tree_host()->GetRendererCapabilities().max_texture_size;
39     bounds.SetSize(std::min(max_texture_size,
40                             device_viewport_in_layout_pixels.width()),
41                    std::min(max_texture_size,
42                             device_viewport_in_layout_pixels.height()));
43   } else {
44     int size = 256;
45     bounds.SetSize(size, size);
46     matrix.Translate(device_viewport_in_layout_pixels.width() - size, 0.0);
47   }
48 
49   SetBounds(bounds);
50   SetTransform(matrix);
51 }
52 
HasDrawableContent() const53 bool HeadsUpDisplayLayer::HasDrawableContent() const {
54   return true;
55 }
56 
CreateLayerImpl(LayerTreeImpl * tree_impl)57 scoped_ptr<LayerImpl> HeadsUpDisplayLayer::CreateLayerImpl(
58     LayerTreeImpl* tree_impl) {
59   return HeadsUpDisplayLayerImpl::Create(tree_impl, layer_id_).
60       PassAs<LayerImpl>();
61 }
62 
63 }  // namespace cc
64