Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 using namespace std; | 22 using namespace std; |
| 23 | 23 |
| 24 namespace cc { | 24 namespace cc { |
| 25 | 25 |
| 26 // Temporary diagnostic. | |
| 27 static bool safeToDeleteDrawableTile = false; | |
| 28 | |
| 26 class DrawableTile : public LayerTilingData::Tile { | 29 class DrawableTile : public LayerTilingData::Tile { |
| 27 public: | 30 public: |
| 28 static scoped_ptr<DrawableTile> create() { return make_scoped_ptr(new Drawab leTile()); } | 31 static scoped_ptr<DrawableTile> create() { return make_scoped_ptr(new Drawab leTile()); } |
| 29 | 32 |
| 33 virtual ~DrawableTile() { CHECK(safeToDeleteDrawableTile); } | |
| 34 | |
| 30 ResourceProvider::ResourceId resourceId() const { return m_resourceId; } | 35 ResourceProvider::ResourceId resourceId() const { return m_resourceId; } |
| 31 void setResourceId(ResourceProvider::ResourceId resourceId) { m_resourceId = resourceId; } | 36 void setResourceId(ResourceProvider::ResourceId resourceId) { m_resourceId = resourceId; } |
| 32 bool contentsSwizzled() { return m_contentsSwizzled; } | 37 bool contentsSwizzled() { return m_contentsSwizzled; } |
| 33 void setContentsSwizzled(bool contentsSwizzled) { m_contentsSwizzled = conte ntsSwizzled; } | 38 void setContentsSwizzled(bool contentsSwizzled) { m_contentsSwizzled = conte ntsSwizzled; } |
| 34 | 39 |
| 35 private: | 40 private: |
| 36 DrawableTile() | 41 DrawableTile() |
| 37 : m_resourceId(0) | 42 : m_resourceId(0) |
| 38 , m_contentsSwizzled(false) { } | 43 , m_contentsSwizzled(false) { } |
| 39 | 44 |
| 40 ResourceProvider::ResourceId m_resourceId; | 45 ResourceProvider::ResourceId m_resourceId; |
| 41 bool m_contentsSwizzled; | 46 bool m_contentsSwizzled; |
| 42 | 47 |
| 43 DISALLOW_COPY_AND_ASSIGN(DrawableTile); | 48 DISALLOW_COPY_AND_ASSIGN(DrawableTile); |
| 44 }; | 49 }; |
| 45 | 50 |
| 46 TiledLayerImpl::TiledLayerImpl(int id) | 51 TiledLayerImpl::TiledLayerImpl(int id) |
| 47 : LayerImpl(id) | 52 : LayerImpl(id) |
| 48 , m_skipsDraw(true) | 53 , m_skipsDraw(true) |
| 49 { | 54 { |
| 50 } | 55 } |
| 51 | 56 |
| 52 TiledLayerImpl::~TiledLayerImpl() | 57 TiledLayerImpl::~TiledLayerImpl() |
| 53 { | 58 { |
| 59 safeToDeleteDrawableTile = true; | |
| 60 if (m_tiler) | |
| 61 m_tiler->reset(); | |
| 62 safeToDeleteDrawableTile = false; | |
| 54 } | 63 } |
| 55 | 64 |
| 56 ResourceProvider::ResourceId TiledLayerImpl::contentsResourceId() const | 65 ResourceProvider::ResourceId TiledLayerImpl::contentsResourceId() const |
| 57 { | 66 { |
| 58 // This function is only valid for single texture layers, e.g. masks. | 67 // This function is only valid for single texture layers, e.g. masks. |
| 59 DCHECK(m_tiler); | 68 DCHECK(m_tiler); |
| 60 DCHECK(m_tiler->numTilesX() == 1); | 69 DCHECK(m_tiler->numTilesX() == 1); |
| 61 DCHECK(m_tiler->numTilesY() == 1); | 70 DCHECK(m_tiler->numTilesY() == 1); |
| 62 | 71 |
| 63 DrawableTile* tile = tileAt(0, 0); | 72 DrawableTile* tile = tileAt(0, 0); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 85 DrawableTile* TiledLayerImpl::tileAt(int i, int j) const | 94 DrawableTile* TiledLayerImpl::tileAt(int i, int j) const |
| 86 { | 95 { |
| 87 return static_cast<DrawableTile*>(m_tiler->tileAt(i, j)); | 96 return static_cast<DrawableTile*>(m_tiler->tileAt(i, j)); |
| 88 } | 97 } |
| 89 | 98 |
| 90 DrawableTile* TiledLayerImpl::createTile(int i, int j) | 99 DrawableTile* TiledLayerImpl::createTile(int i, int j) |
| 91 { | 100 { |
| 92 scoped_ptr<DrawableTile> tile(DrawableTile::create()); | 101 scoped_ptr<DrawableTile> tile(DrawableTile::create()); |
| 93 DrawableTile* addedTile = tile.get(); | 102 DrawableTile* addedTile = tile.get(); |
| 94 m_tiler->addTile(tile.PassAs<LayerTilingData::Tile>(), i, j); | 103 m_tiler->addTile(tile.PassAs<LayerTilingData::Tile>(), i, j); |
| 104 | |
| 105 // Temporary diagnostic checks. | |
| 106 CHECK(addedTile); | |
|
enne (OOO)
2012/12/04 00:57:02
I've added these checks in the past and never gott
| |
| 107 CHECK(tileAt(i, j)); | |
| 108 | |
| 95 return addedTile; | 109 return addedTile; |
| 96 } | 110 } |
| 97 | 111 |
| 98 void TiledLayerImpl::getDebugBorderProperties(SkColor* color, float* width) cons t | 112 void TiledLayerImpl::getDebugBorderProperties(SkColor* color, float* width) cons t |
| 99 { | 113 { |
| 100 *color = DebugColors::TiledContentLayerBorderColor(); | 114 *color = DebugColors::TiledContentLayerBorderColor(); |
| 101 *width = DebugColors::TiledContentLayerBorderWidth(layerTreeHostImpl()); | 115 *width = DebugColors::TiledContentLayerBorderWidth(layerTreeHostImpl()); |
| 102 } | 116 } |
| 103 | 117 |
| 104 void TiledLayerImpl::appendQuads(QuadSink& quadSink, AppendQuadsData& appendQuad sData) | 118 void TiledLayerImpl::appendQuads(QuadSink& quadSink, AppendQuadsData& appendQuad sData) |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 193 | 207 |
| 194 scoped_ptr<TileDrawQuad> quad = TileDrawQuad::Create(); | 208 scoped_ptr<TileDrawQuad> quad = TileDrawQuad::Create(); |
| 195 quad->SetNew(sharedQuadState, tileRect, tileOpaqueRect, tile->resour ceId(), texCoordRect, textureSize, tile->contentsSwizzled(), leftEdgeAA, topEdge AA, rightEdgeAA, bottomEdgeAA); | 209 quad->SetNew(sharedQuadState, tileRect, tileOpaqueRect, tile->resour ceId(), texCoordRect, textureSize, tile->contentsSwizzled(), leftEdgeAA, topEdge AA, rightEdgeAA, bottomEdgeAA); |
| 196 quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData); | 210 quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData); |
| 197 } | 211 } |
| 198 } | 212 } |
| 199 } | 213 } |
| 200 | 214 |
| 201 void TiledLayerImpl::setTilingData(const LayerTilingData& tiler) | 215 void TiledLayerImpl::setTilingData(const LayerTilingData& tiler) |
| 202 { | 216 { |
| 217 safeToDeleteDrawableTile = true; | |
| 218 | |
| 203 if (m_tiler) | 219 if (m_tiler) |
| 204 m_tiler->reset(); | 220 m_tiler->reset(); |
| 205 else | 221 else |
| 206 m_tiler = LayerTilingData::create(tiler.tileSize(), tiler.hasBorderTexel s() ? LayerTilingData::HasBorderTexels : LayerTilingData::NoBorderTexels); | 222 m_tiler = LayerTilingData::create(tiler.tileSize(), tiler.hasBorderTexel s() ? LayerTilingData::HasBorderTexels : LayerTilingData::NoBorderTexels); |
| 207 *m_tiler = tiler; | 223 *m_tiler = tiler; |
| 224 | |
| 225 safeToDeleteDrawableTile = false; | |
| 208 } | 226 } |
| 209 | 227 |
| 210 void TiledLayerImpl::pushTileProperties(int i, int j, ResourceProvider::Resource Id resourceId, const gfx::Rect& opaqueRect, bool contentsSwizzled) | 228 void TiledLayerImpl::pushTileProperties(int i, int j, ResourceProvider::Resource Id resourceId, const gfx::Rect& opaqueRect, bool contentsSwizzled) |
| 211 { | 229 { |
| 212 DrawableTile* tile = tileAt(i, j); | 230 DrawableTile* tile = tileAt(i, j); |
| 213 if (!tile) | 231 if (!tile) |
| 214 tile = createTile(i, j); | 232 tile = createTile(i, j); |
| 215 tile->setResourceId(resourceId); | 233 tile->setResourceId(resourceId); |
| 216 tile->setOpaqueRect(opaqueRect); | 234 tile->setOpaqueRect(opaqueRect); |
| 217 tile->setContentsSwizzled(contentsSwizzled); | 235 tile->setContentsSwizzled(contentsSwizzled); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 231 { | 249 { |
| 232 if (m_skipsDraw) | 250 if (m_skipsDraw) |
| 233 return Region(); | 251 return Region(); |
| 234 if (contentsOpaque()) | 252 if (contentsOpaque()) |
| 235 return visibleContentRect(); | 253 return visibleContentRect(); |
| 236 return m_tiler->opaqueRegionInContentRect(visibleContentRect()); | 254 return m_tiler->opaqueRegionInContentRect(visibleContentRect()); |
| 237 } | 255 } |
| 238 | 256 |
| 239 void TiledLayerImpl::didLoseContext() | 257 void TiledLayerImpl::didLoseContext() |
| 240 { | 258 { |
| 259 safeToDeleteDrawableTile = true; | |
| 260 // Temporary diagnostic check. | |
| 261 CHECK(m_tiler); | |
| 241 m_tiler->reset(); | 262 m_tiler->reset(); |
| 263 safeToDeleteDrawableTile = false; | |
| 242 } | 264 } |
| 243 | 265 |
| 244 const char* TiledLayerImpl::layerTypeAsString() const | 266 const char* TiledLayerImpl::layerTypeAsString() const |
| 245 { | 267 { |
| 246 return "ContentLayer"; | 268 return "ContentLayer"; |
| 247 } | 269 } |
| 248 | 270 |
| 249 } // namespace cc | 271 } // namespace cc |
| OLD | NEW |