cc: Fix hudLayer size and paint rects scale for deviceScaleFactor != 1
[chromium-blink-merge.git] / cc / heads_up_display_layer.cc
blob5f7ba2382dd9837af4c1fccda08e7c81da01639c
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.
5 #include "cc/heads_up_display_layer.h"
7 #include "base/debug/trace_event.h"
8 #include "cc/heads_up_display_layer_impl.h"
9 #include "cc/layer_tree_host.h"
11 namespace cc {
13 scoped_refptr<HeadsUpDisplayLayer> HeadsUpDisplayLayer::create()
15 return make_scoped_refptr(new HeadsUpDisplayLayer());
18 HeadsUpDisplayLayer::HeadsUpDisplayLayer()
19 : Layer()
21 setBounds(gfx::Size(256, 128));
24 HeadsUpDisplayLayer::~HeadsUpDisplayLayer()
28 void HeadsUpDisplayLayer::update(ResourceUpdateQueue&, const OcclusionTracker*, RenderingStats&)
30 const LayerTreeDebugState& debugState = layerTreeHost()->debugState();
31 int maxTextureSize = layerTreeHost()->rendererCapabilities().maxTextureSize;
33 gfx::Size bounds;
34 gfx::Transform matrix;
35 matrix.MakeIdentity();
37 if (debugState.showPlatformLayerTree || debugState.showHudRects()) {
38 int width = std::min(maxTextureSize, layerTreeHost()->layoutViewportSize().width());
39 int height = std::min(maxTextureSize, layerTreeHost()->layoutViewportSize().height());
40 bounds = gfx::Size(width, height);
41 } else {
42 bounds = gfx::Size(256, 128);
43 matrix.Translate(layerTreeHost()->layoutViewportSize().width() - 256, 0);
46 setBounds(bounds);
47 setTransform(matrix);
50 bool HeadsUpDisplayLayer::drawsContent() const
52 return true;
55 void HeadsUpDisplayLayer::setFontAtlas(scoped_ptr<FontAtlas> fontAtlas)
57 m_fontAtlas = fontAtlas.Pass();
58 setNeedsCommit();
61 scoped_ptr<LayerImpl> HeadsUpDisplayLayer::createLayerImpl()
63 return HeadsUpDisplayLayerImpl::create(m_layerId).PassAs<LayerImpl>();
66 void HeadsUpDisplayLayer::pushPropertiesTo(LayerImpl* layerImpl)
68 Layer::pushPropertiesTo(layerImpl);
70 if (!m_fontAtlas)
71 return;
73 HeadsUpDisplayLayerImpl* hudLayerImpl = static_cast<HeadsUpDisplayLayerImpl*>(layerImpl);
74 hudLayerImpl->setFontAtlas(m_fontAtlas.Pass());
77 } // namespace cc