| 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/layer_tiling_data.h" | 13 #include "cc/layer_tiling_data.h" |
| 13 #include "cc/math_util.h" | 14 #include "cc/math_util.h" |
| 14 #include "cc/quad_sink.h" | 15 #include "cc/quad_sink.h" |
| 15 #include "cc/solid_color_draw_quad.h" | 16 #include "cc/solid_color_draw_quad.h" |
| 16 #include "cc/tile_draw_quad.h" | 17 #include "cc/tile_draw_quad.h" |
| 17 #include "third_party/khronos/GLES2/gl2.h" | 18 #include "third_party/khronos/GLES2/gl2.h" |
| 18 #include "third_party/skia/include/core/SkColor.h" | 19 #include "third_party/skia/include/core/SkColor.h" |
| 19 #include "ui/gfx/quad_f.h" | 20 #include "ui/gfx/quad_f.h" |
| 20 | 21 |
| 21 using namespace std; | 22 using namespace std; |
| 22 using WebKit::WebTransformationMatrix; | 23 using WebKit::WebTransformationMatrix; |
| 23 | 24 |
| 24 namespace cc { | 25 namespace cc { |
| 25 | 26 |
| 26 static const int debugTileBorderWidth = 1; | 27 // Non-debug checkerboards are grey. |
| 27 static const int debugTileBorderAlpha = 100; | 28 const SkColor kTileCheckerboardColor = SkColorSetRGB(241, 241, 241); |
| 28 static const int debugTileBorderColorRed = 80; | |
| 29 static const int debugTileBorderColorGreen = 200; | |
| 30 static const int debugTileBorderColorBlue = 200; | |
| 31 static const int debugTileBorderMissingTileColorRed = 255; | |
| 32 static const int debugTileBorderMissingTileColorGreen = 0; | |
| 33 static const int debugTileBorderMissingTileColorBlue = 0; | |
| 34 | |
| 35 static const int defaultCheckerboardColorRed = 241; | |
| 36 static const int defaultCheckerboardColorGreen = 241; | |
| 37 static const int defaultCheckerboardColorBlue = 241; | |
| 38 static const int debugTileEvictedCheckerboardColorRed = 255; | |
| 39 static const int debugTileEvictedCheckerboardColorGreen = 200; | |
| 40 static const int debugTileEvictedCheckerboardColorBlue = 200; | |
| 41 static const int debugTileInvalidatedCheckerboardColorRed = 128; | |
| 42 static const int debugTileInvalidatedCheckerboardColorGreen = 200; | |
| 43 static const int debugTileInvalidatedCheckerboardColorBlue = 245; | |
| 44 | 29 |
| 45 class DrawableTile : public LayerTilingData::Tile { | 30 class DrawableTile : public LayerTilingData::Tile { |
| 46 public: | 31 public: |
| 47 static scoped_ptr<DrawableTile> create() { return make_scoped_ptr(new Drawab
leTile()); } | 32 static scoped_ptr<DrawableTile> create() { return make_scoped_ptr(new Drawab
leTile()); } |
| 48 | 33 |
| 49 ResourceProvider::ResourceId resourceId() const { return m_resourceId; } | 34 ResourceProvider::ResourceId resourceId() const { return m_resourceId; } |
| 50 void setResourceId(ResourceProvider::ResourceId resourceId) { m_resourceId =
resourceId; } | 35 void setResourceId(ResourceProvider::ResourceId resourceId) { m_resourceId =
resourceId; } |
| 51 bool contentsSwizzled() { return m_contentsSwizzled; } | 36 bool contentsSwizzled() { return m_contentsSwizzled; } |
| 52 void setContentsSwizzled(bool contentsSwizzled) { m_contentsSwizzled = conte
ntsSwizzled; } | 37 void setContentsSwizzled(bool contentsSwizzled) { m_contentsSwizzled = conte
ntsSwizzled; } |
| 53 | 38 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 DrawableTile* TiledLayerImpl::createTile(int i, int j) | 94 DrawableTile* TiledLayerImpl::createTile(int i, int j) |
| 110 { | 95 { |
| 111 scoped_ptr<DrawableTile> tile(DrawableTile::create()); | 96 scoped_ptr<DrawableTile> tile(DrawableTile::create()); |
| 112 DrawableTile* addedTile = tile.get(); | 97 DrawableTile* addedTile = tile.get(); |
| 113 m_tiler->addTile(tile.PassAs<LayerTilingData::Tile>(), i, j); | 98 m_tiler->addTile(tile.PassAs<LayerTilingData::Tile>(), i, j); |
| 114 return addedTile; | 99 return addedTile; |
| 115 } | 100 } |
| 116 | 101 |
| 117 void TiledLayerImpl::getDebugBorderProperties(SkColor* color, float* width) cons
t | 102 void TiledLayerImpl::getDebugBorderProperties(SkColor* color, float* width) cons
t |
| 118 { | 103 { |
| 119 // Tiled content layers are orange. | 104 *color = DebugColors::kTiledContentLayerBorderColor(); |
| 120 *color = SkColorSetARGBInline(128, 255, 128, 0); | 105 *width = DebugColors::kTiledContentLayerBorderWidth(layerTreeHostImpl()); |
| 121 *width = 2; | |
| 122 } | 106 } |
| 123 | 107 |
| 124 void TiledLayerImpl::appendQuads(QuadSink& quadSink, AppendQuadsData& appendQuad
sData) | 108 void TiledLayerImpl::appendQuads(QuadSink& quadSink, AppendQuadsData& appendQuad
sData) |
| 125 { | 109 { |
| 126 const gfx::Rect& contentRect = visibleContentRect(); | 110 const gfx::Rect& contentRect = visibleContentRect(); |
| 127 | 111 |
| 128 if (!m_tiler || m_tiler->hasEmptyBounds() || contentRect.IsEmpty()) | 112 if (!m_tiler || m_tiler->hasEmptyBounds() || contentRect.IsEmpty()) |
| 129 return; | 113 return; |
| 130 | 114 |
| 131 SharedQuadState* sharedQuadState = quadSink.useSharedQuadState(createSharedQ
uadState()); | 115 SharedQuadState* sharedQuadState = quadSink.useSharedQuadState(createSharedQ
uadState()); |
| 132 appendDebugBorderQuad(quadSink, sharedQuadState, appendQuadsData); | 116 appendDebugBorderQuad(quadSink, sharedQuadState, appendQuadsData); |
| 133 | 117 |
| 134 int left, top, right, bottom; | 118 int left, top, right, bottom; |
| 135 m_tiler->contentRectToTileIndices(contentRect, left, top, right, bottom); | 119 m_tiler->contentRectToTileIndices(contentRect, left, top, right, bottom); |
| 136 | 120 |
| 137 if (showDebugBorders()) { | 121 if (showDebugBorders()) { |
| 138 for (int j = top; j <= bottom; ++j) { | 122 for (int j = top; j <= bottom; ++j) { |
| 139 for (int i = left; i <= right; ++i) { | 123 for (int i = left; i <= right; ++i) { |
| 140 DrawableTile* tile = tileAt(i, j); | 124 DrawableTile* tile = tileAt(i, j); |
| 141 gfx::Rect tileRect = m_tiler->tileBounds(i, j); | 125 gfx::Rect tileRect = m_tiler->tileBounds(i, j); |
| 142 SkColor borderColor; | 126 SkColor borderColor; |
| 127 float borderWidth; |
| 143 | 128 |
| 144 if (m_skipsDraw || !tile || !tile->resourceId()) | 129 if (m_skipsDraw || !tile || !tile->resourceId()) { |
| 145 borderColor = SkColorSetARGB(debugTileBorderAlpha, debugTile
BorderMissingTileColorRed, debugTileBorderMissingTileColorGreen, debugTileBorder
MissingTileColorBlue); | 130 borderColor = DebugColors::kMissingTileBorderColor(); |
| 146 else | 131 borderWidth = DebugColors::kMissingTileBorderWidth(layerTree
HostImpl()); |
| 147 borderColor = SkColorSetARGB(debugTileBorderAlpha, debugTile
BorderColorRed, debugTileBorderColorGreen, debugTileBorderColorBlue); | 132 } else { |
| 148 quadSink.append(DebugBorderDrawQuad::create(sharedQuadState, til
eRect, borderColor, debugTileBorderWidth).PassAs<DrawQuad>(), appendQuadsData); | 133 borderColor = DebugColors::kTileBorderColor(); |
| 134 borderWidth = DebugColors::kTileBorderWidth(layerTreeHostImp
l()); |
| 135 } |
| 136 quadSink.append(DebugBorderDrawQuad::create(sharedQuadState, til
eRect, borderColor, borderWidth).PassAs<DrawQuad>(), appendQuadsData); |
| 149 } | 137 } |
| 150 } | 138 } |
| 151 } | 139 } |
| 152 | 140 |
| 153 if (m_skipsDraw) | 141 if (m_skipsDraw) |
| 154 return; | 142 return; |
| 155 | 143 |
| 156 for (int j = top; j <= bottom; ++j) { | 144 for (int j = top; j <= bottom; ++j) { |
| 157 for (int i = left; i <= right; ++i) { | 145 for (int i = left; i <= right; ++i) { |
| 158 DrawableTile* tile = tileAt(i, j); | 146 DrawableTile* tile = tileAt(i, j); |
| 159 gfx::Rect tileRect = m_tiler->tileBounds(i, j); | 147 gfx::Rect tileRect = m_tiler->tileBounds(i, j); |
| 160 gfx::Rect displayRect = tileRect; | 148 gfx::Rect displayRect = tileRect; |
| 161 tileRect.Intersect(contentRect); | 149 tileRect.Intersect(contentRect); |
| 162 | 150 |
| 163 // Skip empty tiles. | 151 // Skip empty tiles. |
| 164 if (tileRect.IsEmpty()) | 152 if (tileRect.IsEmpty()) |
| 165 continue; | 153 continue; |
| 166 | 154 |
| 167 if (!tile || !tile->resourceId()) { | 155 if (!tile || !tile->resourceId()) { |
| 168 if (drawCheckerboardForMissingTiles()) { | 156 if (drawCheckerboardForMissingTiles()) { |
| 169 SkColor defaultColor = SkColorSetRGB(defaultCheckerboardColo
rRed, defaultCheckerboardColorGreen, defaultCheckerboardColorBlue); | |
| 170 SkColor evictedColor = SkColorSetRGB(debugTileEvictedChecker
boardColorRed, debugTileEvictedCheckerboardColorGreen, debugTileEvictedCheckerbo
ardColorBlue); | |
| 171 SkColor invalidatedColor = SkColorSetRGB(debugTileInvalidate
dCheckerboardColorRed, debugTileEvictedCheckerboardColorGreen, debugTileEvictedC
heckerboardColorBlue); | |
| 172 | |
| 173 SkColor checkerColor; | 157 SkColor checkerColor; |
| 174 if (showDebugBorders()) | 158 if (showDebugBorders()) |
| 175 checkerColor = tile ? invalidatedColor : evictedColor; | 159 checkerColor = tile ? DebugColors::kInvalidatedTileCheck
erboardColor() : DebugColors::kEvictedTileCheckerboardColor(); |
| 176 else | 160 else |
| 177 checkerColor = defaultColor; | 161 checkerColor = kTileCheckerboardColor; |
| 178 | 162 |
| 179 appendQuadsData.hadMissingTiles |= quadSink.append(Checkerbo
ardDrawQuad::create(sharedQuadState, tileRect, checkerColor).PassAs<DrawQuad>(),
appendQuadsData); | 163 appendQuadsData.hadMissingTiles |= quadSink.append(Checkerbo
ardDrawQuad::create(sharedQuadState, tileRect, checkerColor).PassAs<DrawQuad>(),
appendQuadsData); |
| 180 } else | 164 } else |
| 181 appendQuadsData.hadMissingTiles |= quadSink.append(SolidColo
rDrawQuad::create(sharedQuadState, tileRect, backgroundColor()).PassAs<DrawQuad>
(), appendQuadsData); | 165 appendQuadsData.hadMissingTiles |= quadSink.append(SolidColo
rDrawQuad::create(sharedQuadState, tileRect, backgroundColor()).PassAs<DrawQuad>
(), appendQuadsData); |
| 182 continue; | 166 continue; |
| 183 } | 167 } |
| 184 | 168 |
| 185 gfx::Rect tileOpaqueRect = tile->opaqueRect(); | 169 gfx::Rect tileOpaqueRect = tile->opaqueRect(); |
| 186 tileOpaqueRect.Intersect(contentRect); | 170 tileOpaqueRect.Intersect(contentRect); |
| 187 | 171 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 { | 234 { |
| 251 m_tiler->reset(); | 235 m_tiler->reset(); |
| 252 } | 236 } |
| 253 | 237 |
| 254 const char* TiledLayerImpl::layerTypeAsString() const | 238 const char* TiledLayerImpl::layerTypeAsString() const |
| 255 { | 239 { |
| 256 return "ContentLayer"; | 240 return "ContentLayer"; |
| 257 } | 241 } |
| 258 | 242 |
| 259 } // namespace cc | 243 } // namespace cc |
| OLD | NEW |