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.
7 #include "cc/content_layer.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"
16 #include "cc/settings.h"
20 ContentLayerPainter::ContentLayerPainter(ContentLayerClient
* client
)
25 scoped_ptr
<ContentLayerPainter
> ContentLayerPainter::create(ContentLayerClient
* client
)
27 return make_scoped_ptr(new ContentLayerPainter(client
));
30 void ContentLayerPainter::paint(SkCanvas
* canvas
, const gfx::Rect
& contentRect
, gfx::RectF
& opaque
)
32 base::TimeTicks paintStart
= base::TimeTicks::HighResNow();
33 m_client
->paintContents(canvas
, contentRect
, opaque
);
34 base::TimeTicks paintEnd
= base::TimeTicks::HighResNow();
35 double pixelsPerSec
= (contentRect
.width() * contentRect
.height()) / (paintEnd
- paintStart
).InSecondsF();
36 HISTOGRAM_CUSTOM_COUNTS("Renderer4.AccelContentPaintDurationMS", (paintEnd
- paintStart
).InMilliseconds(), 0, 120, 30);
37 HISTOGRAM_CUSTOM_COUNTS("Renderer4.AccelContentPaintMegapixPerSecond", pixelsPerSec
/ 1000000, 10, 210, 30);
40 scoped_refptr
<ContentLayer
> ContentLayer::create(ContentLayerClient
* client
)
42 return make_scoped_refptr(new ContentLayer(client
));
45 ContentLayer::ContentLayer(ContentLayerClient
* client
)
51 ContentLayer::~ContentLayer()
55 bool ContentLayer::drawsContent() const
57 return TiledLayer::drawsContent() && m_client
;
60 void ContentLayer::setTexturePriorities(const PriorityCalculator
& priorityCalc
)
62 // Update the tile data before creating all the layer's tiles.
63 updateTileSizeAndTilingOption();
65 TiledLayer::setTexturePriorities(priorityCalc
);
68 void ContentLayer::update(ResourceUpdateQueue
& queue
, const OcclusionTracker
* occlusion
, RenderingStats
& stats
)
70 createUpdaterIfNeeded();
71 TiledLayer::update(queue
, occlusion
, stats
);
72 m_needsDisplay
= false;
75 bool ContentLayer::needMoreUpdates()
77 return needsIdlePaint();
80 LayerUpdater
* ContentLayer::updater() const
82 return m_updater
.get();
85 void ContentLayer::createUpdaterIfNeeded()
89 scoped_ptr
<LayerPainter
> painter
= ContentLayerPainter::create(m_client
).PassAs
<LayerPainter
>();
90 if (layerTreeHost()->settings().acceleratePainting
)
91 m_updater
= SkPictureContentLayerUpdater::create(painter
.Pass());
92 else if (Settings::perTilePaintingEnabled())
93 m_updater
= BitmapSkPictureContentLayerUpdater::create(painter
.Pass());
95 m_updater
= BitmapContentLayerUpdater::create(painter
.Pass());
96 m_updater
->setOpaque(contentsOpaque());
98 GLenum textureFormat
= layerTreeHost()->rendererCapabilities().bestTextureFormat
;
99 setTextureFormat(textureFormat
);
102 void ContentLayer::setContentsOpaque(bool opaque
)
104 Layer::setContentsOpaque(opaque
);
106 m_updater
->setOpaque(opaque
);