2 * Copyright 2011, The Android Open Source Project
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include "PaintedSurface.h"
30 #include "LayerAndroid.h"
31 #include "TiledTexture.h"
32 #include "TilesManager.h"
34 #include "SkPicture.h"
36 #include <cutils/log.h>
37 #include <wtf/CurrentTime.h>
38 #include <wtf/text/CString.h>
41 #define XLOGC(...) android_printLog(ANDROID_LOG_DEBUG, "PaintedSurface", __VA_ARGS__)
46 #define XLOG(...) android_printLog(ANDROID_LOG_DEBUG, "PaintedSurface", __VA_ARGS__)
55 // Allows layers using less than MAX_UNCLIPPED_AREA tiles to
56 // schedule all of them instead of clipping the area with the visible rect.
57 #define MAX_UNCLIPPED_AREA 16
61 PaintedSurface::PaintedSurface()
68 TilesManager::instance()->addPaintedSurface(this);
70 ClassTracker::instance()->increment("PaintedSurface");
72 m_tiledTexture = new DualTiledTexture(this);
75 PaintedSurface::~PaintedSurface()
78 ClassTracker::instance()->decrement("PaintedSurface");
80 delete m_tiledTexture;
83 void PaintedSurface::prepare(GLWebViewState* state)
85 XLOG("PS %p has PL %p, DL %p", this, m_paintingLayer, m_drawingLayer);
86 LayerAndroid* paintingLayer = m_paintingLayer;
88 paintingLayer = m_drawingLayer;
93 bool startFastSwap = false;
94 if (state->isScrolling()) {
95 // when scrolling, block updates and swap tiles as soon as they're ready
99 XLOG("prepare layer %d %x at scale %.2f",
100 paintingLayer->uniqueId(), paintingLayer,
101 paintingLayer->getScale());
103 IntRect visibleArea = computeVisibleArea(paintingLayer);
105 m_scale = state->scale();
107 // If we do not have text, we may as well limit ourselves to
108 // a scale factor of one... this saves up textures.
109 if (m_scale > 1 && !paintingLayer->hasText())
112 m_tiledTexture->prepare(state, m_scale, m_pictureUsed != paintingLayer->pictureUsed(),
113 startFastSwap, visibleArea);
116 bool PaintedSurface::draw()
118 if (!m_drawingLayer || !m_drawingLayer->needsTexture())
121 bool askRedraw = false;
123 askRedraw = m_tiledTexture->draw();
128 void PaintedSurface::setPaintingLayer(LayerAndroid* layer, const SkRegion& dirtyArea)
130 m_paintingLayer = layer;
132 m_tiledTexture->update(dirtyArea, layer->picture());
135 bool PaintedSurface::isReady()
138 return m_tiledTexture->isReady();
142 void PaintedSurface::swapTiles()
145 m_tiledTexture->swapTiles();
148 float PaintedSurface::opacity() {
150 return m_drawingLayer->drawOpacity();
154 const TransformationMatrix* PaintedSurface::transform() {
155 // used exclusively for drawing, so only use m_drawingLayer
159 return m_drawingLayer->drawTransform();
162 void PaintedSurface::computeTexturesAmount(TexturesResult* result)
167 // for now, always done on drawinglayer
168 LayerAndroid* layer = m_drawingLayer;
173 IntRect unclippedArea = layer->unclippedArea();
174 IntRect clippedVisibleArea = layer->visibleArea();
175 // get two numbers here:
176 // - textures needed for a clipped area
177 // - textures needed for an un-clipped area
178 int nbTexturesUnclipped = m_tiledTexture->nbTextures(unclippedArea, m_scale);
179 int nbTexturesClipped = m_tiledTexture->nbTextures(clippedVisibleArea, m_scale);
181 // Set kFixedLayers level
182 if (layer->isFixed())
183 result->fixed += nbTexturesClipped;
185 // Set kScrollableAndFixedLayers level
186 if (layer->contentIsScrollable()
188 result->scrollable += nbTexturesClipped;
190 // Set kClippedTextures level
191 result->clipped += nbTexturesClipped;
193 // Set kAllTextures level
194 if (layer->contentIsScrollable())
195 result->full += nbTexturesClipped;
197 result->full += nbTexturesUnclipped;
200 IntRect PaintedSurface::computeVisibleArea(LayerAndroid* layer) {
205 if (!layer->contentIsScrollable()
206 && layer->state()->layersRenderingMode() == GLWebViewState::kAllTextures)
207 area = layer->unclippedArea();
209 area = layer->visibleArea();
214 bool PaintedSurface::owns(BaseTileTexture* texture)
217 return m_tiledTexture->owns(texture);
221 } // namespace WebCore