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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
// Copyright 2010 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/content_layer.h"
#include "base/auto_reset.h"
#include "base/debug/trace_event.h"
#include "base/metrics/histogram.h"
#include "base/time.h"
#include "cc/bitmap_content_layer_updater.h"
#include "cc/bitmap_skpicture_content_layer_updater.h"
#include "cc/content_layer_client.h"
#include "cc/layer_painter.h"
#include "cc/layer_tree_host.h"
namespace cc {
ContentLayerPainter::ContentLayerPainter(ContentLayerClient* client)
: m_client(client)
{
}
scoped_ptr<ContentLayerPainter> ContentLayerPainter::create(ContentLayerClient* client)
{
return make_scoped_ptr(new ContentLayerPainter(client));
}
void ContentLayerPainter::paint(SkCanvas* canvas, gfx::Rect contentRect, gfx::RectF& opaque)
{
base::TimeTicks paintStart = base::TimeTicks::HighResNow();
m_client->paintContents(canvas, contentRect, opaque);
base::TimeTicks paintEnd = base::TimeTicks::HighResNow();
double pixelsPerSec = (contentRect.width() * contentRect.height()) / (paintEnd - paintStart).InSecondsF();
HISTOGRAM_CUSTOM_COUNTS("Renderer4.AccelContentPaintDurationMS", (paintEnd - paintStart).InMilliseconds(), 0, 120, 30);
HISTOGRAM_CUSTOM_COUNTS("Renderer4.AccelContentPaintMegapixPerSecond", pixelsPerSec / 1000000, 10, 210, 30);
}
const int ContentLayer::kLCDTextMaxChangeCount = 1;
scoped_refptr<ContentLayer> ContentLayer::create(ContentLayerClient* client)
{
return make_scoped_refptr(new ContentLayer(client));
}
ContentLayer::ContentLayer(ContentLayerClient* client)
: TiledLayer()
, m_client(client)
, m_useLCDText(false)
, m_lcdTextChangeCount(0)
{
}
ContentLayer::~ContentLayer()
{
}
bool ContentLayer::drawsContent() const
{
return TiledLayer::drawsContent() && m_client;
}
void ContentLayer::setTexturePriorities(const PriorityCalculator& priorityCalc)
{
// Update the tile data before creating all the layer's tiles.
updateTileSizeAndTilingOption();
TiledLayer::setTexturePriorities(priorityCalc);
}
void ContentLayer::update(ResourceUpdateQueue& queue, const OcclusionTracker* occlusion, RenderingStats& stats)
{
{
base::AutoReset<bool> ignoreSetNeedsCommit(&m_ignoreSetNeedsCommit, true);
createUpdaterIfNeeded();
updateUseLCDText();
}
TiledLayer::update(queue, occlusion, stats);
m_needsDisplay = false;
}
bool ContentLayer::needMoreUpdates()
{
return needsIdlePaint();
}
LayerUpdater* ContentLayer::updater() const
{
return m_updater.get();
}
void ContentLayer::createUpdaterIfNeeded()
{
if (m_updater)
return;
scoped_ptr<LayerPainter> painter = ContentLayerPainter::create(m_client).PassAs<LayerPainter>();
if (layerTreeHost()->settings().acceleratePainting)
m_updater = SkPictureContentLayerUpdater::create(painter.Pass());
else if (layerTreeHost()->settings().perTilePaintingEnabled)
m_updater = BitmapSkPictureContentLayerUpdater::create(painter.Pass());
else
m_updater = BitmapContentLayerUpdater::create(painter.Pass());
m_updater->setOpaque(contentsOpaque());
unsigned textureFormat = layerTreeHost()->rendererCapabilities().bestTextureFormat;
setTextureFormat(textureFormat);
}
void ContentLayer::setContentsOpaque(bool opaque)
{
Layer::setContentsOpaque(opaque);
if (m_updater)
m_updater->setOpaque(opaque);
}
void ContentLayer::updateUseLCDText()
{
if (m_useLCDText == drawProperties().can_use_lcd_text)
return;
if (!useLCDTextWillChange())
return;
m_useLCDText = drawProperties().can_use_lcd_text;
useLCDTextDidChange();
}
bool ContentLayer::useLCDTextWillChange() const
{
// Always allow disabling LCD text.
if (m_useLCDText)
return true;
return m_lcdTextChangeCount < kLCDTextMaxChangeCount;
}
void ContentLayer::useLCDTextDidChange()
{
if (m_lcdTextChangeCount > 0) {
// Do not record the first time LCD text is enabled because
// it does not really cause any invalidation.
TRACE_EVENT_INSTANT0("cc", "ContentLayer::canUseLCDTextDidChange");
}
++m_lcdTextChangeCount;
// Need to repaint the layer with different text AA setting.
setNeedsDisplay();
}
} // namespace cc
|