WebKit Roll 139512:139548
[chromium-blink-merge.git] / cc / content_layer.cc
bloba0ddc89515e484158182c89937e21914f400a27e
1 // Copyright 2010 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/content_layer.h"
7 #include "base/auto_reset.h"
8 #include "base/debug/trace_event.h"
9 #include "base/metrics/histogram.h"
10 #include "base/time.h"
11 #include "cc/bitmap_content_layer_updater.h"
12 #include "cc/bitmap_skpicture_content_layer_updater.h"
13 #include "cc/content_layer_client.h"
14 #include "cc/layer_painter.h"
15 #include "cc/layer_tree_host.h"
17 namespace cc {
19 ContentLayerPainter::ContentLayerPainter(ContentLayerClient* client)
20 : m_client(client)
24 scoped_ptr<ContentLayerPainter> ContentLayerPainter::create(ContentLayerClient* client)
26 return make_scoped_ptr(new ContentLayerPainter(client));
29 void ContentLayerPainter::paint(SkCanvas* canvas, gfx::Rect contentRect, gfx::RectF& opaque)
31 base::TimeTicks paintStart = base::TimeTicks::HighResNow();
32 m_client->paintContents(canvas, contentRect, opaque);
33 base::TimeTicks paintEnd = base::TimeTicks::HighResNow();
34 double pixelsPerSec = (contentRect.width() * contentRect.height()) / (paintEnd - paintStart).InSecondsF();
35 HISTOGRAM_CUSTOM_COUNTS("Renderer4.AccelContentPaintDurationMS", (paintEnd - paintStart).InMilliseconds(), 0, 120, 30);
36 HISTOGRAM_CUSTOM_COUNTS("Renderer4.AccelContentPaintMegapixPerSecond", pixelsPerSec / 1000000, 10, 210, 30);
39 const int ContentLayer::kLCDTextMaxChangeCount = 1;
41 scoped_refptr<ContentLayer> ContentLayer::create(ContentLayerClient* client)
43 return make_scoped_refptr(new ContentLayer(client));
46 ContentLayer::ContentLayer(ContentLayerClient* client)
47 : TiledLayer()
48 , m_client(client)
49 , m_useLCDText(false)
50 , m_lcdTextChangeCount(0)
54 ContentLayer::~ContentLayer()
58 bool ContentLayer::drawsContent() const
60 return TiledLayer::drawsContent() && m_client;
63 void ContentLayer::setTexturePriorities(const PriorityCalculator& priorityCalc)
65 // Update the tile data before creating all the layer's tiles.
66 updateTileSizeAndTilingOption();
68 TiledLayer::setTexturePriorities(priorityCalc);
71 void ContentLayer::update(ResourceUpdateQueue& queue, const OcclusionTracker* occlusion, RenderingStats& stats)
74 base::AutoReset<bool> ignoreSetNeedsCommit(&m_ignoreSetNeedsCommit, true);
76 createUpdaterIfNeeded();
77 updateUseLCDText();
80 TiledLayer::update(queue, occlusion, stats);
81 m_needsDisplay = false;
84 bool ContentLayer::needMoreUpdates()
86 return needsIdlePaint();
89 LayerUpdater* ContentLayer::updater() const
91 return m_updater.get();
94 void ContentLayer::createUpdaterIfNeeded()
96 if (m_updater)
97 return;
98 scoped_ptr<LayerPainter> painter = ContentLayerPainter::create(m_client).PassAs<LayerPainter>();
99 if (layerTreeHost()->settings().acceleratePainting)
100 m_updater = SkPictureContentLayerUpdater::create(painter.Pass());
101 else if (layerTreeHost()->settings().perTilePaintingEnabled)
102 m_updater = BitmapSkPictureContentLayerUpdater::create(painter.Pass());
103 else
104 m_updater = BitmapContentLayerUpdater::create(painter.Pass());
105 m_updater->setOpaque(contentsOpaque());
107 unsigned textureFormat = layerTreeHost()->rendererCapabilities().bestTextureFormat;
108 setTextureFormat(textureFormat);
111 void ContentLayer::setContentsOpaque(bool opaque)
113 Layer::setContentsOpaque(opaque);
114 if (m_updater)
115 m_updater->setOpaque(opaque);
118 void ContentLayer::updateUseLCDText()
120 if (m_useLCDText == drawProperties().can_use_lcd_text)
121 return;
123 if (!useLCDTextWillChange())
124 return;
126 m_useLCDText = drawProperties().can_use_lcd_text;
127 useLCDTextDidChange();
130 bool ContentLayer::useLCDTextWillChange() const
132 // Always allow disabling LCD text.
133 if (m_useLCDText)
134 return true;
136 return m_lcdTextChangeCount < kLCDTextMaxChangeCount;
139 void ContentLayer::useLCDTextDidChange()
141 if (m_lcdTextChangeCount > 0) {
142 // Do not record the first time LCD text is enabled because
143 // it does not really cause any invalidation.
144 TRACE_EVENT_INSTANT0("cc", "ContentLayer::canUseLCDTextDidChange");
146 ++m_lcdTextChangeCount;
148 // Need to repaint the layer with different text AA setting.
149 setNeedsDisplay();
152 } // namespace cc