• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2010, The Android Open Source Project
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
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.
12  *
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.
24  */
25 
26 #define LOG_TAG "TileTexture"
27 #define LOG_NDEBUG 1
28 
29 #include "config.h"
30 #include "TileTexture.h"
31 
32 #include "AndroidLog.h"
33 #include "Tile.h"
34 #include "ClassTracker.h"
35 #include "DrawQuadData.h"
36 #include "GLUtils.h"
37 #include "GLWebViewState.h"
38 #include "TextureOwner.h"
39 #include "TilesManager.h"
40 
41 namespace WebCore {
42 
TileTexture(uint32_t w,uint32_t h)43 TileTexture::TileTexture(uint32_t w, uint32_t h)
44     : m_owner(0)
45     , m_isPureColor(false)
46 {
47     m_size.set(w, h);
48     m_ownTextureId = 0;
49 
50 #ifdef DEBUG_COUNT
51     ClassTracker::instance()->increment("TileTexture");
52 #endif
53 }
54 
~TileTexture()55 TileTexture::~TileTexture()
56 {
57 #ifdef DEBUG_COUNT
58     ClassTracker::instance()->decrement("TileTexture");
59 #endif
60 }
61 
requireGLTexture()62 void TileTexture::requireGLTexture()
63 {
64     if (!m_ownTextureId)
65         m_ownTextureId = GLUtils::createTileGLTexture(m_size.width(), m_size.height());
66 }
67 
discardGLTexture()68 void TileTexture::discardGLTexture()
69 {
70     if (m_ownTextureId)
71         GLUtils::deleteTexture(&m_ownTextureId);
72 
73     if (m_owner) {
74         // clear both Tile->Texture and Texture->Tile links
75         m_owner->removeTexture(this);
76         release(m_owner);
77     }
78 }
79 
acquire(TextureOwner * owner)80 bool TileTexture::acquire(TextureOwner* owner)
81 {
82     if (m_owner == owner)
83         return true;
84 
85     return setOwner(owner);
86 }
87 
setOwner(TextureOwner * owner)88 bool TileTexture::setOwner(TextureOwner* owner)
89 {
90     bool proceed = true;
91     if (m_owner && m_owner != owner)
92         proceed = m_owner->removeTexture(this);
93 
94     if (proceed) {
95         m_owner = owner;
96         return true;
97     }
98 
99     return false;
100 }
101 
release(TextureOwner * owner)102 bool TileTexture::release(TextureOwner* owner)
103 {
104     ALOGV("texture %p releasing tile %p, m_owner %p", this, owner, m_owner);
105     if (m_owner != owner)
106         return false;
107 
108     m_owner = 0;
109     return true;
110 }
111 
transferComplete()112 void TileTexture::transferComplete()
113 {
114     if (m_owner) {
115         Tile* owner = static_cast<Tile*>(m_owner);
116         owner->backTextureTransfer();
117     } else
118         ALOGE("ERROR: owner missing after transfer of texture %p", this);
119 }
120 
drawGL(bool isLayer,const SkRect & rect,float opacity,const TransformationMatrix * transform,bool forceBlending,bool usePointSampling,const FloatRect & fillPortion)121 void TileTexture::drawGL(bool isLayer, const SkRect& rect, float opacity,
122                          const TransformationMatrix* transform,
123                          bool forceBlending, bool usePointSampling,
124                          const FloatRect& fillPortion)
125 {
126     ShaderProgram* shader = TilesManager::instance()->shader();
127 
128     if (isLayer && !transform) {
129         ALOGE("ERROR: Missing tranform for layers!");
130         return;
131     }
132 
133     // For base layer, we just follow the forceBlending, otherwise, blending is
134     // always turned on.
135     // TODO: Don't blend tiles if they are fully opaque.
136     bool useBlending = forceBlending || isLayer;
137     DrawQuadData commonData(isLayer ? LayerQuad : BaseQuad, transform, &rect,
138                             opacity, useBlending, fillPortion);
139     if (isPureColor()) {
140         PureColorQuadData data(commonData, pureColor());
141         shader->drawQuad(&data);
142     } else {
143         GLint filter = usePointSampling ? GL_NEAREST : GL_LINEAR;
144         TextureQuadData data(commonData, m_ownTextureId, GL_TEXTURE_2D, filter);
145         shader->drawQuad(&data);
146     }
147 }
148 
149 } // namespace WebCore
150