blob: c2bd8d1e1088ac6a47efd76150e07923ce007bce [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
[email protected]9c88e562012-09-14 22:21:3021namespace cc {
[email protected]94f206c12012-08-25 00:09:1422
[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]d58499a2012-10-09 22:27:4743scoped_refptr<ContentLayerChromium> ContentLayerChromium::create(ContentLayerChromiumClient* client)
[email protected]94f206c12012-08-25 00:09:1444{
[email protected]d58499a2012-10-09 22:27:4745 return make_scoped_refptr(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
[email protected]76481592012-09-21 16:47:0683LayerTextureUpdater* ContentLayerChromium::textureUpdater() const
84{
85 return m_textureUpdater.get();
86}
87
[email protected]94f206c12012-08-25 00:09:1488void ContentLayerChromium::createTextureUpdaterIfNeeded()
89{
90 if (m_textureUpdater)
91 return;
92 if (layerTreeHost()->settings().acceleratePainting)
[email protected]be3aa6f2012-08-31 23:55:4093 m_textureUpdater = FrameBufferSkPictureCanvasLayerTextureUpdater::create(ContentLayerPainter::create(m_client));
[email protected]94f206c12012-08-25 00:09:1494 else if (CCSettings::perTilePaintingEnabled())
[email protected]be3aa6f2012-08-31 23:55:4095 m_textureUpdater = BitmapSkPictureCanvasLayerTextureUpdater::create(ContentLayerPainter::create(m_client));
[email protected]94f206c12012-08-25 00:09:1496 else
[email protected]be3aa6f2012-08-31 23:55:4097 m_textureUpdater = BitmapCanvasLayerTextureUpdater::create(ContentLayerPainter::create(m_client));
[email protected]048634c2012-10-02 22:33:1498 m_textureUpdater->setOpaque(contentsOpaque());
[email protected]94f206c12012-08-25 00:09:1499
100 GC3Denum textureFormat = layerTreeHost()->rendererCapabilities().bestTextureFormat;
101 setTextureFormat(textureFormat);
102 setSampledTexelFormat(textureUpdater()->sampledTexelFormat(textureFormat));
103}
104
[email protected]048634c2012-10-02 22:33:14105void ContentLayerChromium::setContentsOpaque(bool opaque)
[email protected]94f206c12012-08-25 00:09:14106{
[email protected]048634c2012-10-02 22:33:14107 LayerChromium::setContentsOpaque(opaque);
[email protected]94f206c12012-08-25 00:09:14108 if (m_textureUpdater)
109 m_textureUpdater->setOpaque(opaque);
110}
111
112}
113#endif // USE(ACCELERATED_COMPOSITING)