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/metrics/histogram.h"
9 #include "cc/bitmap_content_layer_updater.h"
10 #include "cc/bitmap_skpicture_content_layer_updater.h"
11 #include "cc/content_layer_client.h"
12 #include "cc/layer_painter.h"
13 #include "cc/layer_tree_host.h"
17 ContentLayerPainter::ContentLayerPainter(ContentLayerClient
* client
)
22 scoped_ptr
<ContentLayerPainter
> ContentLayerPainter::create(ContentLayerClient
* client
)
24 return make_scoped_ptr(new ContentLayerPainter(client
));
27 void ContentLayerPainter::paint(SkCanvas
* canvas
, const gfx::Rect
& contentRect
, gfx::RectF
& opaque
)
29 base::TimeTicks paintStart
= base::TimeTicks::HighResNow();
30 m_client
->paintContents(canvas
, contentRect
, opaque
);
31 base::TimeTicks paintEnd
= base::TimeTicks::HighResNow();
32 double pixelsPerSec
= (contentRect
.width() * contentRect
.height()) / (paintEnd
- paintStart
).InSecondsF();
33 HISTOGRAM_CUSTOM_COUNTS("Renderer4.AccelContentPaintDurationMS", (paintEnd
- paintStart
).InMilliseconds(), 0, 120, 30);
34 HISTOGRAM_CUSTOM_COUNTS("Renderer4.AccelContentPaintMegapixPerSecond", pixelsPerSec
/ 1000000, 10, 210, 30);
37 scoped_refptr
<ContentLayer
> ContentLayer::create(ContentLayerClient
* client
)
39 return make_scoped_refptr(new ContentLayer(client
));
42 ContentLayer::ContentLayer(ContentLayerClient
* client
)
48 ContentLayer::~ContentLayer()
52 bool ContentLayer::drawsContent() const
54 return TiledLayer::drawsContent() && m_client
;
57 void ContentLayer::setTexturePriorities(const PriorityCalculator
& priorityCalc
)
59 // Update the tile data before creating all the layer's tiles.
60 updateTileSizeAndTilingOption();
62 TiledLayer::setTexturePriorities(priorityCalc
);
65 void ContentLayer::update(ResourceUpdateQueue
& queue
, const OcclusionTracker
* occlusion
, RenderingStats
& stats
)
67 createUpdaterIfNeeded();
68 TiledLayer::update(queue
, occlusion
, stats
);
69 m_needsDisplay
= false;
72 bool ContentLayer::needMoreUpdates()
74 return needsIdlePaint();
77 LayerUpdater
* ContentLayer::updater() const
79 return m_updater
.get();
82 void ContentLayer::createUpdaterIfNeeded()
86 scoped_ptr
<LayerPainter
> painter
= ContentLayerPainter::create(m_client
).PassAs
<LayerPainter
>();
87 if (layerTreeHost()->settings().acceleratePainting
)
88 m_updater
= SkPictureContentLayerUpdater::create(painter
.Pass());
89 else if (layerTreeHost()->settings().perTilePaintingEnabled
)
90 m_updater
= BitmapSkPictureContentLayerUpdater::create(painter
.Pass());
92 m_updater
= BitmapContentLayerUpdater::create(painter
.Pass());
93 m_updater
->setOpaque(contentsOpaque());
95 GLenum textureFormat
= layerTreeHost()->rendererCapabilities().bestTextureFormat
;
96 setTextureFormat(textureFormat
);
99 void ContentLayer::setContentsOpaque(bool opaque
)
101 Layer::setContentsOpaque(opaque
);
103 m_updater
->setOpaque(opaque
);