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"
19 ContentLayerPainter::ContentLayerPainter(ContentLayerClient
* 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
)
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();
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()
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());
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
);
115 m_updater
->setOpaque(opaque
);
118 void ContentLayer::updateUseLCDText()
120 if (m_useLCDText
== drawProperties().can_use_lcd_text
)
123 if (!useLCDTextWillChange())
126 m_useLCDText
= drawProperties().can_use_lcd_text
;
127 useLCDTextDidChange();
130 bool ContentLayer::useLCDTextWillChange() const
132 // Always allow disabling LCD text.
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.