blob: 4a5b7880bde1d0f7162f617cc1ba904029ac55b8 [file] [log] [blame]
[email protected]94f206c12012-08-25 00:09:141// 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.
4
5#include "config.h"
6
7#if USE(ACCELERATED_COMPOSITING)
8
9#include "ContentLayerChromium.h"
10
11#include "BitmapCanvasLayerTextureUpdater.h"
12#include "BitmapSkPictureCanvasLayerTextureUpdater.h"
13#include "CCLayerTreeHost.h"
14#include "CCSettings.h"
[email protected]be3aa6f2012-08-31 23:55:4015#include "ContentLayerChromiumClient.h"
[email protected]94f206c12012-08-25 00:09:1416#include "FrameBufferSkPictureCanvasLayerTextureUpdater.h"
17#include "LayerPainterChromium.h"
18#include <public/Platform.h>
19#include <wtf/CurrentTime.h>
20
21namespace WebCore {
22
[email protected]be3aa6f2012-08-31 23:55:4023ContentLayerPainter::ContentLayerPainter(ContentLayerChromiumClient* client)
24 : m_client(client)
[email protected]94f206c12012-08-25 00:09:1425{
26}
27
[email protected]be3aa6f2012-08-31 23:55:4028PassOwnPtr<ContentLayerPainter> ContentLayerPainter::create(ContentLayerChromiumClient* client)
[email protected]94f206c12012-08-25 00:09:1429{
[email protected]be3aa6f2012-08-31 23:55:4030 return adoptPtr(new ContentLayerPainter(client));
[email protected]94f206c12012-08-25 00:09:1431}
32
33void ContentLayerPainter::paint(SkCanvas* canvas, const IntRect& contentRect, FloatRect& opaque)
34{
35 double paintStart = currentTime();
[email protected]be3aa6f2012-08-31 23:55:4036 m_client->paintContents(canvas, contentRect, opaque);
[email protected]94f206c12012-08-25 00:09:1437 double paintEnd = currentTime();
38 double pixelsPerSec = (contentRect.width() * contentRect.height()) / (paintEnd - paintStart);
39 WebKit::Platform::current()->histogramCustomCounts("Renderer4.AccelContentPaintDurationMS", (paintEnd - paintStart) * 1000, 0, 120, 30);
40 WebKit::Platform::current()->histogramCustomCounts("Renderer4.AccelContentPaintMegapixPerSecond", pixelsPerSec / 1000000, 10, 210, 30);
41}
42
[email protected]be3aa6f2012-08-31 23:55:4043PassRefPtr<ContentLayerChromium> ContentLayerChromium::create(ContentLayerChromiumClient* client)
[email protected]94f206c12012-08-25 00:09:1444{
[email protected]be3aa6f2012-08-31 23:55:4045 return adoptRef(new ContentLayerChromium(client));
[email protected]94f206c12012-08-25 00:09:1446}
47
[email protected]be3aa6f2012-08-31 23:55:4048ContentLayerChromium::ContentLayerChromium(ContentLayerChromiumClient* client)
[email protected]94f206c12012-08-25 00:09:1449 : TiledLayerChromium()
[email protected]be3aa6f2012-08-31 23:55:4050 , m_client(client)
[email protected]94f206c12012-08-25 00:09:1451{
52}
53
54ContentLayerChromium::~ContentLayerChromium()
55{
56}
57
58bool ContentLayerChromium::drawsContent() const
59{
[email protected]be3aa6f2012-08-31 23:55:4060 return TiledLayerChromium::drawsContent() && m_client;
[email protected]94f206c12012-08-25 00:09:1461}
62
63void ContentLayerChromium::setTexturePriorities(const CCPriorityCalculator& priorityCalc)
64{
65 // Update the tile data before creating all the layer's tiles.
66 updateTileSizeAndTilingOption();
67
68 TiledLayerChromium::setTexturePriorities(priorityCalc);
69}
70
71void ContentLayerChromium::update(CCTextureUpdateQueue& queue, const CCOcclusionTracker* occlusion, CCRenderingStats& stats)
72{
73 createTextureUpdaterIfNeeded();
74 TiledLayerChromium::update(queue, occlusion, stats);
75 m_needsDisplay = false;
76}
77
78bool ContentLayerChromium::needMoreUpdates()
79{
80 return needsIdlePaint();
81}
82
83void ContentLayerChromium::createTextureUpdaterIfNeeded()
84{
85 if (m_textureUpdater)
86 return;
87 if (layerTreeHost()->settings().acceleratePainting)
[email protected]be3aa6f2012-08-31 23:55:4088 m_textureUpdater = FrameBufferSkPictureCanvasLayerTextureUpdater::create(ContentLayerPainter::create(m_client));
[email protected]94f206c12012-08-25 00:09:1489 else if (CCSettings::perTilePaintingEnabled())
[email protected]be3aa6f2012-08-31 23:55:4090 m_textureUpdater = BitmapSkPictureCanvasLayerTextureUpdater::create(ContentLayerPainter::create(m_client));
[email protected]94f206c12012-08-25 00:09:1491 else
[email protected]be3aa6f2012-08-31 23:55:4092 m_textureUpdater = BitmapCanvasLayerTextureUpdater::create(ContentLayerPainter::create(m_client));
[email protected]94f206c12012-08-25 00:09:1493 m_textureUpdater->setOpaque(opaque());
94
95 GC3Denum textureFormat = layerTreeHost()->rendererCapabilities().bestTextureFormat;
96 setTextureFormat(textureFormat);
97 setSampledTexelFormat(textureUpdater()->sampledTexelFormat(textureFormat));
98}
99
100void ContentLayerChromium::setOpaque(bool opaque)
101{
102 LayerChromium::setOpaque(opaque);
103 if (m_textureUpdater)
104 m_textureUpdater->setOpaque(opaque);
105}
106
107}
108#endif // USE(ACCELERATED_COMPOSITING)