[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 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. |
| 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] | be3aa6f | 2012-08-31 23:55:40 | [diff] [blame^] | 15 | #include "ContentLayerChromiumClient.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 16 | #include "FrameBufferSkPictureCanvasLayerTextureUpdater.h" |
| 17 | #include "LayerPainterChromium.h" |
| 18 | #include <public/Platform.h> |
| 19 | #include <wtf/CurrentTime.h> |
| 20 | |
| 21 | namespace WebCore { |
| 22 | |
[email protected] | be3aa6f | 2012-08-31 23:55:40 | [diff] [blame^] | 23 | ContentLayerPainter::ContentLayerPainter(ContentLayerChromiumClient* client) |
| 24 | : m_client(client) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 25 | { |
| 26 | } |
| 27 | |
[email protected] | be3aa6f | 2012-08-31 23:55:40 | [diff] [blame^] | 28 | PassOwnPtr<ContentLayerPainter> ContentLayerPainter::create(ContentLayerChromiumClient* client) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 29 | { |
[email protected] | be3aa6f | 2012-08-31 23:55:40 | [diff] [blame^] | 30 | return adoptPtr(new ContentLayerPainter(client)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | void ContentLayerPainter::paint(SkCanvas* canvas, const IntRect& contentRect, FloatRect& opaque) |
| 34 | { |
| 35 | double paintStart = currentTime(); |
[email protected] | be3aa6f | 2012-08-31 23:55:40 | [diff] [blame^] | 36 | m_client->paintContents(canvas, contentRect, opaque); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 37 | 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] | be3aa6f | 2012-08-31 23:55:40 | [diff] [blame^] | 43 | PassRefPtr<ContentLayerChromium> ContentLayerChromium::create(ContentLayerChromiumClient* client) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 44 | { |
[email protected] | be3aa6f | 2012-08-31 23:55:40 | [diff] [blame^] | 45 | return adoptRef(new ContentLayerChromium(client)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 46 | } |
| 47 | |
[email protected] | be3aa6f | 2012-08-31 23:55:40 | [diff] [blame^] | 48 | ContentLayerChromium::ContentLayerChromium(ContentLayerChromiumClient* client) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 49 | : TiledLayerChromium() |
[email protected] | be3aa6f | 2012-08-31 23:55:40 | [diff] [blame^] | 50 | , m_client(client) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 51 | { |
| 52 | } |
| 53 | |
| 54 | ContentLayerChromium::~ContentLayerChromium() |
| 55 | { |
| 56 | } |
| 57 | |
| 58 | bool ContentLayerChromium::drawsContent() const |
| 59 | { |
[email protected] | be3aa6f | 2012-08-31 23:55:40 | [diff] [blame^] | 60 | return TiledLayerChromium::drawsContent() && m_client; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | void 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 | |
| 71 | void ContentLayerChromium::update(CCTextureUpdateQueue& queue, const CCOcclusionTracker* occlusion, CCRenderingStats& stats) |
| 72 | { |
| 73 | createTextureUpdaterIfNeeded(); |
| 74 | TiledLayerChromium::update(queue, occlusion, stats); |
| 75 | m_needsDisplay = false; |
| 76 | } |
| 77 | |
| 78 | bool ContentLayerChromium::needMoreUpdates() |
| 79 | { |
| 80 | return needsIdlePaint(); |
| 81 | } |
| 82 | |
| 83 | void ContentLayerChromium::createTextureUpdaterIfNeeded() |
| 84 | { |
| 85 | if (m_textureUpdater) |
| 86 | return; |
| 87 | if (layerTreeHost()->settings().acceleratePainting) |
[email protected] | be3aa6f | 2012-08-31 23:55:40 | [diff] [blame^] | 88 | m_textureUpdater = FrameBufferSkPictureCanvasLayerTextureUpdater::create(ContentLayerPainter::create(m_client)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 89 | else if (CCSettings::perTilePaintingEnabled()) |
[email protected] | be3aa6f | 2012-08-31 23:55:40 | [diff] [blame^] | 90 | m_textureUpdater = BitmapSkPictureCanvasLayerTextureUpdater::create(ContentLayerPainter::create(m_client)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 91 | else |
[email protected] | be3aa6f | 2012-08-31 23:55:40 | [diff] [blame^] | 92 | m_textureUpdater = BitmapCanvasLayerTextureUpdater::create(ContentLayerPainter::create(m_client)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 93 | m_textureUpdater->setOpaque(opaque()); |
| 94 | |
| 95 | GC3Denum textureFormat = layerTreeHost()->rendererCapabilities().bestTextureFormat; |
| 96 | setTextureFormat(textureFormat); |
| 97 | setSampledTexelFormat(textureUpdater()->sampledTexelFormat(textureFormat)); |
| 98 | } |
| 99 | |
| 100 | void 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) |