2 * Copyright (C) 2010 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #if USE(ACCELERATED_COMPOSITING)
35 #include "ContentLayerChromium.h"
37 #include "LayerPainterChromium.h"
38 #include "LayerRendererChromium.h"
39 #include "LayerTextureUpdaterCanvas.h"
40 #include "PlatformSupport.h"
41 #include "cc/CCLayerTreeHost.h"
42 #include <wtf/CurrentTime.h>
46 class ContentLayerPainter : public LayerPainterChromium {
47 WTF_MAKE_NONCOPYABLE(ContentLayerPainter);
49 static PassOwnPtr<ContentLayerPainter> create(CCLayerDelegate* delegate)
51 return adoptPtr(new ContentLayerPainter(delegate));
54 virtual void paint(GraphicsContext& context, const IntRect& contentRect)
56 double paintStart = currentTime();
57 context.clearRect(contentRect);
58 context.clip(contentRect);
59 m_delegate->paintContents(context, contentRect);
60 double paintEnd = currentTime();
61 double pixelsPerSec = (contentRect.width() * contentRect.height()) / (paintEnd - paintStart);
62 PlatformSupport::histogramCustomCounts("Renderer4.AccelContentPaintDurationMS", (paintEnd - paintStart) * 1000, 0, 120, 30);
63 PlatformSupport::histogramCustomCounts("Renderer4.AccelContentPaintMegapixPerSecond", pixelsPerSec / 1000000, 10, 210, 30);
66 explicit ContentLayerPainter(CCLayerDelegate* delegate)
67 : m_delegate(delegate)
71 CCLayerDelegate* m_delegate;
74 PassRefPtr<ContentLayerChromium> ContentLayerChromium::create(CCLayerDelegate* delegate)
76 return adoptRef(new ContentLayerChromium(delegate));
79 ContentLayerChromium::ContentLayerChromium(CCLayerDelegate* delegate)
80 : TiledLayerChromium(delegate)
84 ContentLayerChromium::~ContentLayerChromium()
89 void ContentLayerChromium::cleanupResources()
91 m_textureUpdater.clear();
92 TiledLayerChromium::cleanupResources();
95 void ContentLayerChromium::paintContentsIfDirty()
97 ASSERT(drawsContent());
99 updateTileSizeAndTilingOption();
101 const IntRect& layerRect = visibleLayerRect();
102 if (layerRect.isEmpty())
105 IntRect dirty = enclosingIntRect(m_dirtyRect);
106 dirty.intersect(IntRect(IntPoint(), contentBounds()));
107 invalidateRect(dirty);
112 prepareToUpdate(layerRect);
113 m_dirtyRect = FloatRect();
116 bool ContentLayerChromium::drawsContent() const
118 return m_delegate && m_delegate->drawsContent() && TiledLayerChromium::drawsContent();
121 void ContentLayerChromium::createTextureUpdater(const CCLayerTreeHost* host)
124 // Note that host->skiaContext() will crash if called while in threaded
125 // mode. This thus depends on CCLayerTreeHost::initialize turning off
126 // acceleratePainting to prevent this from crashing.
127 if (host->settings().acceleratePainting) {
128 m_textureUpdater = LayerTextureUpdaterSkPicture::create(ContentLayerPainter::create(m_delegate));
133 m_textureUpdater = LayerTextureUpdaterBitmap::create(ContentLayerPainter::create(m_delegate), host->layerRendererCapabilities().usingMapSub);
137 #endif // USE(ACCELERATED_COMPOSITING)