Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(248)

Side by Side Diff: cc/tiled_layer_impl.cc

Issue 12774006: cc: Chromify Layer and LayerImpl classes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: MoreAndroidCompilings Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/tiled_layer_impl.h ('k') | cc/tiled_layer_impl_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/tiled_layer_impl.h" 5 #include "cc/tiled_layer_impl.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/stringprintf.h" 8 #include "base/stringprintf.h"
9 #include "cc/append_quads_data.h" 9 #include "cc/append_quads_data.h"
10 #include "cc/checkerboard_draw_quad.h" 10 #include "cc/checkerboard_draw_quad.h"
11 #include "cc/debug_border_draw_quad.h" 11 #include "cc/debug_border_draw_quad.h"
12 #include "cc/debug_colors.h" 12 #include "cc/debug_colors.h"
13 #include "cc/layer_tiling_data.h" 13 #include "cc/layer_tiling_data.h"
14 #include "cc/math_util.h" 14 #include "cc/math_util.h"
15 #include "cc/quad_sink.h" 15 #include "cc/quad_sink.h"
16 #include "cc/solid_color_draw_quad.h" 16 #include "cc/solid_color_draw_quad.h"
17 #include "cc/tile_draw_quad.h" 17 #include "cc/tile_draw_quad.h"
18 #include "third_party/khronos/GLES2/gl2.h" 18 #include "third_party/khronos/GLES2/gl2.h"
19 #include "third_party/skia/include/core/SkColor.h" 19 #include "third_party/skia/include/core/SkColor.h"
20 #include "ui/gfx/quad_f.h" 20 #include "ui/gfx/quad_f.h"
21 21
22 namespace cc { 22 namespace cc {
23 23
24 // Temporary diagnostic. 24 // Temporary diagnostic.
25 static bool safeToDeleteDrawableTile = false; 25 static bool safeToDeleteDrawableTile = false;
26 26
27 class DrawableTile : public LayerTilingData::Tile { 27 class DrawableTile : public LayerTilingData::Tile {
28 public: 28 public:
29 static scoped_ptr<DrawableTile> create() { return make_scoped_ptr(new Drawab leTile()); } 29 static scoped_ptr<DrawableTile> Create() { return make_scoped_ptr(new Drawab leTile()); }
30 30
31 virtual ~DrawableTile() { CHECK(safeToDeleteDrawableTile); } 31 virtual ~DrawableTile() { CHECK(safeToDeleteDrawableTile); }
32 32
33 ResourceProvider::ResourceId resourceId() const { return m_resourceId; } 33 ResourceProvider::ResourceId resourceId() const { return m_resourceId; }
34 void setResourceId(ResourceProvider::ResourceId resourceId) { m_resourceId = resourceId; } 34 void setResourceId(ResourceProvider::ResourceId resourceId) { m_resourceId = resourceId; }
35 bool contentsSwizzled() { return m_contentsSwizzled; } 35 bool contentsSwizzled() { return m_contentsSwizzled; }
36 void setContentsSwizzled(bool contentsSwizzled) { m_contentsSwizzled = conte ntsSwizzled; } 36 void setContentsSwizzled(bool contentsSwizzled) { m_contentsSwizzled = conte ntsSwizzled; }
37 37
38 private: 38 private:
39 DrawableTile() 39 DrawableTile()
(...skipping 13 matching lines...) Expand all
53 } 53 }
54 54
55 TiledLayerImpl::~TiledLayerImpl() 55 TiledLayerImpl::~TiledLayerImpl()
56 { 56 {
57 safeToDeleteDrawableTile = true; 57 safeToDeleteDrawableTile = true;
58 if (m_tiler) 58 if (m_tiler)
59 m_tiler->reset(); 59 m_tiler->reset();
60 safeToDeleteDrawableTile = false; 60 safeToDeleteDrawableTile = false;
61 } 61 }
62 62
63 ResourceProvider::ResourceId TiledLayerImpl::contentsResourceId() const 63 ResourceProvider::ResourceId TiledLayerImpl::ContentsResourceId() const
64 { 64 {
65 // This function is only valid for single texture layers, e.g. masks. 65 // This function is only valid for single texture layers, e.g. masks.
66 DCHECK(m_tiler); 66 DCHECK(m_tiler);
67 DCHECK(m_tiler->numTilesX() == 1); 67 DCHECK(m_tiler->numTilesX() == 1);
68 DCHECK(m_tiler->numTilesY() == 1); 68 DCHECK(m_tiler->numTilesY() == 1);
69 69
70 DrawableTile* tile = tileAt(0, 0); 70 DrawableTile* tile = tileAt(0, 0);
71 ResourceProvider::ResourceId resourceId = tile ? tile->resourceId() : 0; 71 ResourceProvider::ResourceId resourceId = tile ? tile->resourceId() : 0;
72 return resourceId; 72 return resourceId;
73 } 73 }
74 74
75 void TiledLayerImpl::dumpLayerProperties(std::string* str, int indent) const 75 void TiledLayerImpl::DumpLayerProperties(std::string* str, int indent) const
76 { 76 {
77 str->append(indentString(indent)); 77 str->append(IndentString(indent));
78 base::StringAppendF(str, "skipsDraw: %d\n", (!m_tiler || m_skipsDraw)); 78 base::StringAppendF(str, "skipsDraw: %d\n", (!m_tiler || m_skipsDraw));
79 LayerImpl::dumpLayerProperties(str, indent); 79 LayerImpl::DumpLayerProperties(str, indent);
80 } 80 }
81 81
82 bool TiledLayerImpl::hasTileAt(int i, int j) const 82 bool TiledLayerImpl::hasTileAt(int i, int j) const
83 { 83 {
84 return m_tiler->tileAt(i, j); 84 return m_tiler->tileAt(i, j);
85 } 85 }
86 86
87 bool TiledLayerImpl::hasResourceIdForTileAt(int i, int j) const 87 bool TiledLayerImpl::hasResourceIdForTileAt(int i, int j) const
88 { 88 {
89 return hasTileAt(i, j) && tileAt(i, j)->resourceId(); 89 return hasTileAt(i, j) && tileAt(i, j)->resourceId();
90 } 90 }
91 91
92 DrawableTile* TiledLayerImpl::tileAt(int i, int j) const 92 DrawableTile* TiledLayerImpl::tileAt(int i, int j) const
93 { 93 {
94 return static_cast<DrawableTile*>(m_tiler->tileAt(i, j)); 94 return static_cast<DrawableTile*>(m_tiler->tileAt(i, j));
95 } 95 }
96 96
97 DrawableTile* TiledLayerImpl::createTile(int i, int j) 97 DrawableTile* TiledLayerImpl::createTile(int i, int j)
98 { 98 {
99 scoped_ptr<DrawableTile> tile(DrawableTile::create()); 99 scoped_ptr<DrawableTile> tile(DrawableTile::Create());
100 DrawableTile* addedTile = tile.get(); 100 DrawableTile* addedTile = tile.get();
101 m_tiler->addTile(tile.PassAs<LayerTilingData::Tile>(), i, j); 101 m_tiler->addTile(tile.PassAs<LayerTilingData::Tile>(), i, j);
102 102
103 // Temporary diagnostic checks. 103 // Temporary diagnostic checks.
104 CHECK(addedTile); 104 CHECK(addedTile);
105 CHECK(tileAt(i, j)); 105 CHECK(tileAt(i, j));
106 106
107 return addedTile; 107 return addedTile;
108 } 108 }
109 109
110 void TiledLayerImpl::getDebugBorderProperties(SkColor* color, float* width) cons t 110 void TiledLayerImpl::GetDebugBorderProperties(SkColor* color, float* width) cons t
111 { 111 {
112 *color = DebugColors::TiledContentLayerBorderColor(); 112 *color = DebugColors::TiledContentLayerBorderColor();
113 *width = DebugColors::TiledContentLayerBorderWidth(layerTreeImpl()); 113 *width = DebugColors::TiledContentLayerBorderWidth(layer_tree_impl());
114 } 114 }
115 115
116 scoped_ptr<LayerImpl> TiledLayerImpl::createLayerImpl(LayerTreeImpl* treeImpl) 116 scoped_ptr<LayerImpl> TiledLayerImpl::CreateLayerImpl(LayerTreeImpl* treeImpl)
117 { 117 {
118 return TiledLayerImpl::create(treeImpl, id()).PassAs<LayerImpl>(); 118 return TiledLayerImpl::Create(treeImpl, id()).PassAs<LayerImpl>();
119 } 119 }
120 120
121 void TiledLayerImpl::pushPropertiesTo(LayerImpl* layer) 121 void TiledLayerImpl::PushPropertiesTo(LayerImpl* layer)
122 { 122 {
123 LayerImpl::pushPropertiesTo(layer); 123 LayerImpl::PushPropertiesTo(layer);
124 124
125 TiledLayerImpl* tiledLayer = static_cast<TiledLayerImpl*>(layer); 125 TiledLayerImpl* tiledLayer = static_cast<TiledLayerImpl*>(layer);
126 126
127 tiledLayer->setSkipsDraw(m_skipsDraw); 127 tiledLayer->setSkipsDraw(m_skipsDraw);
128 tiledLayer->setTilingData(*m_tiler); 128 tiledLayer->setTilingData(*m_tiler);
129 129
130 for (LayerTilingData::TileMap::const_iterator iter = m_tiler->tiles().begin( ); iter != m_tiler->tiles().end(); ++iter) { 130 for (LayerTilingData::TileMap::const_iterator iter = m_tiler->tiles().begin( ); iter != m_tiler->tiles().end(); ++iter) {
131 int i = iter->first.first; 131 int i = iter->first.first;
132 int j = iter->first.second; 132 int j = iter->first.second;
133 DrawableTile* tile = static_cast<DrawableTile*>(iter->second); 133 DrawableTile* tile = static_cast<DrawableTile*>(iter->second);
134 134
135 tiledLayer->pushTileProperties(i, j, tile->resourceId(), tile->opaqueRec t(), tile->contentsSwizzled()); 135 tiledLayer->pushTileProperties(i, j, tile->resourceId(), tile->opaqueRec t(), tile->contentsSwizzled());
136 } 136 }
137 } 137 }
138 138
139 void TiledLayerImpl::appendQuads(QuadSink& quadSink, AppendQuadsData& appendQuad sData) 139 void TiledLayerImpl::AppendQuads(QuadSink* quadSink, AppendQuadsData* appendQuad sData)
140 { 140 {
141 const gfx::Rect& contentRect = visibleContentRect(); 141 const gfx::Rect& contentRect = visible_content_rect();
142 142
143 if (!m_tiler || m_tiler->hasEmptyBounds() || contentRect.IsEmpty()) 143 if (!m_tiler || m_tiler->hasEmptyBounds() || contentRect.IsEmpty())
144 return; 144 return;
145 145
146 SharedQuadState* sharedQuadState = quadSink.useSharedQuadState(createSharedQ uadState()); 146 SharedQuadState* sharedQuadState = quadSink->useSharedQuadState(CreateShared QuadState());
147 appendDebugBorderQuad(quadSink, sharedQuadState, appendQuadsData); 147 AppendDebugBorderQuad(quadSink, sharedQuadState, appendQuadsData);
148 148
149 int left, top, right, bottom; 149 int left, top, right, bottom;
150 m_tiler->contentRectToTileIndices(contentRect, left, top, right, bottom); 150 m_tiler->contentRectToTileIndices(contentRect, left, top, right, bottom);
151 151
152 if (showDebugBorders()) { 152 if (ShowDebugBorders()) {
153 for (int j = top; j <= bottom; ++j) { 153 for (int j = top; j <= bottom; ++j) {
154 for (int i = left; i <= right; ++i) { 154 for (int i = left; i <= right; ++i) {
155 DrawableTile* tile = tileAt(i, j); 155 DrawableTile* tile = tileAt(i, j);
156 gfx::Rect tileRect = m_tiler->tileBounds(i, j); 156 gfx::Rect tileRect = m_tiler->tileBounds(i, j);
157 SkColor borderColor; 157 SkColor borderColor;
158 float borderWidth; 158 float borderWidth;
159 159
160 if (m_skipsDraw || !tile || !tile->resourceId()) { 160 if (m_skipsDraw || !tile || !tile->resourceId()) {
161 borderColor = DebugColors::MissingTileBorderColor(); 161 borderColor = DebugColors::MissingTileBorderColor();
162 borderWidth = DebugColors::MissingTileBorderWidth(layerTreeI mpl()); 162 borderWidth = DebugColors::MissingTileBorderWidth(layer_tree _impl());
163 } else { 163 } else {
164 borderColor = DebugColors::HighResTileBorderColor(); 164 borderColor = DebugColors::HighResTileBorderColor();
165 borderWidth = DebugColors::HighResTileBorderWidth(layerTreeI mpl()); 165 borderWidth = DebugColors::HighResTileBorderWidth(layer_tree _impl());
166 } 166 }
167 scoped_ptr<DebugBorderDrawQuad> debugBorderQuad = DebugBorderDra wQuad::Create(); 167 scoped_ptr<DebugBorderDrawQuad> debugBorderQuad = DebugBorderDra wQuad::Create();
168 debugBorderQuad->SetNew(sharedQuadState, tileRect, borderColor, borderWidth); 168 debugBorderQuad->SetNew(sharedQuadState, tileRect, borderColor, borderWidth);
169 quadSink.append(debugBorderQuad.PassAs<DrawQuad>(), appendQuadsD ata); 169 quadSink->append(debugBorderQuad.PassAs<DrawQuad>(), appendQuads Data);
170 } 170 }
171 } 171 }
172 } 172 }
173 173
174 if (m_skipsDraw) 174 if (m_skipsDraw)
175 return; 175 return;
176 176
177 for (int j = top; j <= bottom; ++j) { 177 for (int j = top; j <= bottom; ++j) {
178 for (int i = left; i <= right; ++i) { 178 for (int i = left; i <= right; ++i) {
179 DrawableTile* tile = tileAt(i, j); 179 DrawableTile* tile = tileAt(i, j);
180 gfx::Rect tileRect = m_tiler->tileBounds(i, j); 180 gfx::Rect tileRect = m_tiler->tileBounds(i, j);
181 gfx::Rect displayRect = tileRect; 181 gfx::Rect displayRect = tileRect;
182 tileRect.Intersect(contentRect); 182 tileRect.Intersect(contentRect);
183 183
184 // Skip empty tiles. 184 // Skip empty tiles.
185 if (tileRect.IsEmpty()) 185 if (tileRect.IsEmpty())
186 continue; 186 continue;
187 187
188 if (!tile || !tile->resourceId()) { 188 if (!tile || !tile->resourceId()) {
189 if (drawCheckerboardForMissingTiles()) { 189 if (DrawCheckerboardForMissingTiles()) {
190 SkColor checkerColor; 190 SkColor checkerColor;
191 if (showDebugBorders()) 191 if (ShowDebugBorders())
192 checkerColor = tile ? DebugColors::InvalidatedTileChecke rboardColor() : DebugColors::EvictedTileCheckerboardColor(); 192 checkerColor = tile ? DebugColors::InvalidatedTileChecke rboardColor() : DebugColors::EvictedTileCheckerboardColor();
193 else 193 else
194 checkerColor = DebugColors::DefaultCheckerboardColor(); 194 checkerColor = DebugColors::DefaultCheckerboardColor();
195 195
196 scoped_ptr<CheckerboardDrawQuad> checkerboardQuad = Checkerb oardDrawQuad::Create(); 196 scoped_ptr<CheckerboardDrawQuad> checkerboardQuad = Checkerb oardDrawQuad::Create();
197 checkerboardQuad->SetNew(sharedQuadState, tileRect, checkerC olor); 197 checkerboardQuad->SetNew(sharedQuadState, tileRect, checkerC olor);
198 if (quadSink.append(checkerboardQuad.PassAs<DrawQuad>(), app endQuadsData)) 198 if (quadSink->append(checkerboardQuad.PassAs<DrawQuad>(), ap pendQuadsData))
199 appendQuadsData.numMissingTiles++; 199 appendQuadsData->numMissingTiles++;
200 } else { 200 } else {
201 scoped_ptr<SolidColorDrawQuad> solidColorQuad = SolidColorDr awQuad::Create(); 201 scoped_ptr<SolidColorDrawQuad> solidColorQuad = SolidColorDr awQuad::Create();
202 solidColorQuad->SetNew(sharedQuadState, tileRect, background Color()); 202 solidColorQuad->SetNew(sharedQuadState, tileRect, background _color());
203 if (quadSink.append(solidColorQuad.PassAs<DrawQuad>(), appen dQuadsData)) 203 if (quadSink->append(solidColorQuad.PassAs<DrawQuad>(), appe ndQuadsData))
204 appendQuadsData.numMissingTiles++; 204 appendQuadsData->numMissingTiles++;
205 } 205 }
206 continue; 206 continue;
207 } 207 }
208 208
209 gfx::Rect tileOpaqueRect = contentsOpaque() ? tileRect : gfx::Inters ectRects(tile->opaqueRect(), contentRect); 209 gfx::Rect tileOpaqueRect = contents_opaque() ? tileRect : gfx::Inter sectRects(tile->opaqueRect(), contentRect);
210 210
211 // Keep track of how the top left has moved, so the texture can be 211 // Keep track of how the top left has moved, so the texture can be
212 // offset the same amount. 212 // offset the same amount.
213 gfx::Vector2d displayOffset = tileRect.origin() - displayRect.origin (); 213 gfx::Vector2d displayOffset = tileRect.origin() - displayRect.origin ();
214 gfx::Vector2d textureOffset = m_tiler->textureOffset(i, j) + display Offset; 214 gfx::Vector2d textureOffset = m_tiler->textureOffset(i, j) + display Offset;
215 gfx::RectF texCoordRect = gfx::RectF(tileRect.size()) + textureOffse t; 215 gfx::RectF texCoordRect = gfx::RectF(tileRect.size()) + textureOffse t;
216 216
217 float tileWidth = static_cast<float>(m_tiler->tileSize().width()); 217 float tileWidth = static_cast<float>(m_tiler->tileSize().width());
218 float tileHeight = static_cast<float>(m_tiler->tileSize().height()); 218 float tileHeight = static_cast<float>(m_tiler->tileSize().height());
219 gfx::Size textureSize(tileWidth, tileHeight); 219 gfx::Size textureSize(tileWidth, tileHeight);
220 220
221 scoped_ptr<TileDrawQuad> quad = TileDrawQuad::Create(); 221 scoped_ptr<TileDrawQuad> quad = TileDrawQuad::Create();
222 quad->SetNew(sharedQuadState, tileRect, tileOpaqueRect, tile->resour ceId(), texCoordRect, textureSize, tile->contentsSwizzled()); 222 quad->SetNew(sharedQuadState, tileRect, tileOpaqueRect, tile->resour ceId(), texCoordRect, textureSize, tile->contentsSwizzled());
223 quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData); 223 quadSink->append(quad.PassAs<DrawQuad>(), appendQuadsData);
224 } 224 }
225 } 225 }
226 } 226 }
227 227
228 void TiledLayerImpl::setTilingData(const LayerTilingData& tiler) 228 void TiledLayerImpl::setTilingData(const LayerTilingData& tiler)
229 { 229 {
230 safeToDeleteDrawableTile = true; 230 safeToDeleteDrawableTile = true;
231 231
232 if (m_tiler) 232 if (m_tiler)
233 m_tiler->reset(); 233 m_tiler->reset();
(...skipping 17 matching lines...) Expand all
251 void TiledLayerImpl::pushInvalidTile(int i, int j) 251 void TiledLayerImpl::pushInvalidTile(int i, int j)
252 { 252 {
253 DrawableTile* tile = tileAt(i, j); 253 DrawableTile* tile = tileAt(i, j);
254 if (!tile) 254 if (!tile)
255 tile = createTile(i, j); 255 tile = createTile(i, j);
256 tile->setResourceId(0); 256 tile->setResourceId(0);
257 tile->setOpaqueRect(gfx::Rect()); 257 tile->setOpaqueRect(gfx::Rect());
258 tile->setContentsSwizzled(false); 258 tile->setContentsSwizzled(false);
259 } 259 }
260 260
261 Region TiledLayerImpl::visibleContentOpaqueRegion() const 261 Region TiledLayerImpl::VisibleContentOpaqueRegion() const
262 { 262 {
263 if (m_skipsDraw) 263 if (m_skipsDraw)
264 return Region(); 264 return Region();
265 if (contentsOpaque()) 265 if (contents_opaque())
266 return visibleContentRect(); 266 return visible_content_rect();
267 return m_tiler->opaqueRegionInContentRect(visibleContentRect()); 267 return m_tiler->opaqueRegionInContentRect(visible_content_rect());
268 } 268 }
269 269
270 void TiledLayerImpl::didLoseOutputSurface() 270 void TiledLayerImpl::DidLoseOutputSurface()
271 { 271 {
272 safeToDeleteDrawableTile = true; 272 safeToDeleteDrawableTile = true;
273 // Temporary diagnostic check. 273 // Temporary diagnostic check.
274 CHECK(m_tiler); 274 CHECK(m_tiler);
275 m_tiler->reset(); 275 m_tiler->reset();
276 safeToDeleteDrawableTile = false; 276 safeToDeleteDrawableTile = false;
277 } 277 }
278 278
279 const char* TiledLayerImpl::layerTypeAsString() const 279 const char* TiledLayerImpl::LayerTypeAsString() const
280 { 280 {
281 return "ContentLayer"; 281 return "ContentLayer";
282 } 282 }
283 283
284 } // namespace cc 284 } // namespace cc
OLDNEW
« no previous file with comments | « cc/tiled_layer_impl.h ('k') | cc/tiled_layer_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698