OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "CCHeadsUpDisplayLayerImpl.h" | 7 #include "CCHeadsUpDisplayLayerImpl.h" |
8 | 8 |
9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
10 #include "ui/gfx/point.h" | 10 #include "ui/gfx/point.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 swizzleMatrix.fMat[0 + 5 * 2] = 1; | 33 swizzleMatrix.fMat[0 + 5 * 2] = 1; |
34 swizzleMatrix.fMat[1 + 5 * 1] = 1; | 34 swizzleMatrix.fMat[1 + 5 * 1] = 1; |
35 swizzleMatrix.fMat[2 + 5 * 0] = 1; | 35 swizzleMatrix.fMat[2 + 5 * 0] = 1; |
36 swizzleMatrix.fMat[3 + 5 * 3] = 1; | 36 swizzleMatrix.fMat[3 + 5 * 3] = 1; |
37 | 37 |
38 SkPaint paint; | 38 SkPaint paint; |
39 paint.setColorFilter(new SkColorMatrixFilter(swizzleMatrix))->unref(); | 39 paint.setColorFilter(new SkColorMatrixFilter(swizzleMatrix))->unref(); |
40 return paint; | 40 return paint; |
41 } | 41 } |
42 | 42 |
43 CCHeadsUpDisplayLayerImpl::CCHeadsUpDisplayLayerImpl(int id) | 43 HeadsUpDisplayLayerImpl::HeadsUpDisplayLayerImpl(int id) |
44 : CCLayerImpl(id) | 44 : LayerImpl(id) |
45 { | 45 { |
46 } | 46 } |
47 | 47 |
48 CCHeadsUpDisplayLayerImpl::~CCHeadsUpDisplayLayerImpl() | 48 HeadsUpDisplayLayerImpl::~HeadsUpDisplayLayerImpl() |
49 { | 49 { |
50 } | 50 } |
51 | 51 |
52 void CCHeadsUpDisplayLayerImpl::setFontAtlas(scoped_ptr<CCFontAtlas> fontAtlas) | 52 void HeadsUpDisplayLayerImpl::setFontAtlas(scoped_ptr<FontAtlas> fontAtlas) |
53 { | 53 { |
54 m_fontAtlas = fontAtlas.Pass(); | 54 m_fontAtlas = fontAtlas.Pass(); |
55 } | 55 } |
56 | 56 |
57 void CCHeadsUpDisplayLayerImpl::willDraw(CCResourceProvider* resourceProvider) | 57 void HeadsUpDisplayLayerImpl::willDraw(ResourceProvider* resourceProvider) |
58 { | 58 { |
59 CCLayerImpl::willDraw(resourceProvider); | 59 LayerImpl::willDraw(resourceProvider); |
60 | 60 |
61 if (!m_hudTexture) | 61 if (!m_hudTexture) |
62 m_hudTexture = CCScopedTexture::create(resourceProvider); | 62 m_hudTexture = ScopedTexture::create(resourceProvider); |
63 | 63 |
64 // FIXME: Scale the HUD by deviceScale to make it more friendly under high D
PI. | 64 // FIXME: Scale the HUD by deviceScale to make it more friendly under high D
PI. |
65 | 65 |
66 if (m_hudTexture->size() != bounds()) | 66 if (m_hudTexture->size() != bounds()) |
67 m_hudTexture->free(); | 67 m_hudTexture->free(); |
68 | 68 |
69 if (!m_hudTexture->id()) | 69 if (!m_hudTexture->id()) |
70 m_hudTexture->allocate(CCRenderer::ImplPool, bounds(), GraphicsContext3D
::RGBA, CCResourceProvider::TextureUsageAny); | 70 m_hudTexture->allocate(Renderer::ImplPool, bounds(), GraphicsContext3D::
RGBA, ResourceProvider::TextureUsageAny); |
71 } | 71 } |
72 | 72 |
73 void CCHeadsUpDisplayLayerImpl::appendQuads(CCQuadSink& quadSink, CCAppendQuadsD
ata& appendQuadsData) | 73 void HeadsUpDisplayLayerImpl::appendQuads(QuadSink& quadSink, AppendQuadsData& a
ppendQuadsData) |
74 { | 74 { |
75 if (!m_hudTexture->id()) | 75 if (!m_hudTexture->id()) |
76 return; | 76 return; |
77 | 77 |
78 CCSharedQuadState* sharedQuadState = quadSink.useSharedQuadState(createShare
dQuadState()); | 78 SharedQuadState* sharedQuadState = quadSink.useSharedQuadState(createSharedQ
uadState()); |
79 | 79 |
80 IntRect quadRect(IntPoint(), bounds()); | 80 IntRect quadRect(IntPoint(), bounds()); |
81 bool premultipliedAlpha = true; | 81 bool premultipliedAlpha = true; |
82 FloatRect uvRect(0, 0, 1, 1); | 82 FloatRect uvRect(0, 0, 1, 1); |
83 bool flipped = false; | 83 bool flipped = false; |
84 quadSink.append(CCTextureDrawQuad::create(sharedQuadState, quadRect, m_hudTe
xture->id(), premultipliedAlpha, uvRect, flipped).PassAs<CCDrawQuad>(), appendQu
adsData); | 84 quadSink.append(TextureDrawQuad::create(sharedQuadState, quadRect, m_hudText
ure->id(), premultipliedAlpha, uvRect, flipped).PassAs<DrawQuad>(), appendQuadsD
ata); |
85 } | 85 } |
86 | 86 |
87 void CCHeadsUpDisplayLayerImpl::updateHudTexture(CCResourceProvider* resourcePro
vider) | 87 void HeadsUpDisplayLayerImpl::updateHudTexture(ResourceProvider* resourceProvide
r) |
88 { | 88 { |
89 if (!m_hudTexture->id()) | 89 if (!m_hudTexture->id()) |
90 return; | 90 return; |
91 | 91 |
92 SkISize canvasSize; | 92 SkISize canvasSize; |
93 if (m_hudCanvas) | 93 if (m_hudCanvas) |
94 canvasSize = m_hudCanvas->getDeviceSize(); | 94 canvasSize = m_hudCanvas->getDeviceSize(); |
95 else | 95 else |
96 canvasSize.set(0, 0); | 96 canvasSize.set(0, 0); |
97 | 97 |
98 if (canvasSize.fWidth != bounds().width() || canvasSize.fHeight != bounds().
height() || !m_hudCanvas) | 98 if (canvasSize.fWidth != bounds().width() || canvasSize.fHeight != bounds().
height() || !m_hudCanvas) |
99 m_hudCanvas = make_scoped_ptr(skia::CreateBitmapCanvas(bounds().width(),
bounds().height(), false /* opaque */)); | 99 m_hudCanvas = make_scoped_ptr(skia::CreateBitmapCanvas(bounds().width(),
bounds().height(), false /* opaque */)); |
100 | 100 |
101 m_hudCanvas->clear(SkColorSetARGB(0, 0, 0, 0)); | 101 m_hudCanvas->clear(SkColorSetARGB(0, 0, 0, 0)); |
102 drawHudContents(m_hudCanvas.get()); | 102 drawHudContents(m_hudCanvas.get()); |
103 | 103 |
104 const SkBitmap* bitmap = &m_hudCanvas->getDevice()->accessBitmap(false); | 104 const SkBitmap* bitmap = &m_hudCanvas->getDevice()->accessBitmap(false); |
105 SkAutoLockPixels locker(*bitmap); | 105 SkAutoLockPixels locker(*bitmap); |
106 | 106 |
107 IntRect layerRect(IntPoint(), bounds()); | 107 IntRect layerRect(IntPoint(), bounds()); |
108 ASSERT(bitmap->config() == SkBitmap::kARGB_8888_Config); | 108 ASSERT(bitmap->config() == SkBitmap::kARGB_8888_Config); |
109 resourceProvider->upload(m_hudTexture->id(), static_cast<const uint8_t*>(bit
map->getPixels()), layerRect, layerRect, IntSize()); | 109 resourceProvider->upload(m_hudTexture->id(), static_cast<const uint8_t*>(bit
map->getPixels()), layerRect, layerRect, IntSize()); |
110 } | 110 } |
111 | 111 |
112 void CCHeadsUpDisplayLayerImpl::didDraw(CCResourceProvider* resourceProvider) | 112 void HeadsUpDisplayLayerImpl::didDraw(ResourceProvider* resourceProvider) |
113 { | 113 { |
114 CCLayerImpl::didDraw(resourceProvider); | 114 LayerImpl::didDraw(resourceProvider); |
115 | 115 |
116 if (!m_hudTexture->id()) | 116 if (!m_hudTexture->id()) |
117 return; | 117 return; |
118 | 118 |
119 // FIXME: the following assert will not be true when sending resources to a | 119 // FIXME: the following assert will not be true when sending resources to a |
120 // parent compositor. We will probably need to hold on to m_hudTexture for | 120 // parent compositor. We will probably need to hold on to m_hudTexture for |
121 // longer, and have several HUD textures in the pipeline. | 121 // longer, and have several HUD textures in the pipeline. |
122 ASSERT(!resourceProvider->inUseByConsumer(m_hudTexture->id())); | 122 ASSERT(!resourceProvider->inUseByConsumer(m_hudTexture->id())); |
123 } | 123 } |
124 | 124 |
125 void CCHeadsUpDisplayLayerImpl::didLoseContext() | 125 void HeadsUpDisplayLayerImpl::didLoseContext() |
126 { | 126 { |
127 m_hudTexture.reset(); | 127 m_hudTexture.reset(); |
128 } | 128 } |
129 | 129 |
130 bool CCHeadsUpDisplayLayerImpl::layerIsAlwaysDamaged() const | 130 bool HeadsUpDisplayLayerImpl::layerIsAlwaysDamaged() const |
131 { | 131 { |
132 return true; | 132 return true; |
133 } | 133 } |
134 | 134 |
135 void CCHeadsUpDisplayLayerImpl::drawHudContents(SkCanvas* canvas) | 135 void HeadsUpDisplayLayerImpl::drawHudContents(SkCanvas* canvas) |
136 { | 136 { |
137 const CCLayerTreeSettings& settings = layerTreeHostImpl()->settings(); | 137 const LayerTreeSettings& settings = layerTreeHostImpl()->settings(); |
138 | 138 |
139 if (settings.showPlatformLayerTree) { | 139 if (settings.showPlatformLayerTree) { |
140 SkPaint paint = createPaint(); | 140 SkPaint paint = createPaint(); |
141 paint.setColor(SkColorSetARGB(192, 0, 0, 0)); | 141 paint.setColor(SkColorSetARGB(192, 0, 0, 0)); |
142 canvas->drawRect(SkRect::MakeXYWH(0, 0, bounds().width(), bounds().heigh
t()), paint); | 142 canvas->drawRect(SkRect::MakeXYWH(0, 0, bounds().width(), bounds().heigh
t()), paint); |
143 } | 143 } |
144 | 144 |
145 int fpsCounterHeight = 40; | 145 int fpsCounterHeight = 40; |
146 int fpsCounterTop = 2; | 146 int fpsCounterTop = 2; |
147 int platformLayerTreeTop; | 147 int platformLayerTreeTop; |
148 | 148 |
149 if (settings.showFPSCounter) | 149 if (settings.showFPSCounter) |
150 platformLayerTreeTop = fpsCounterTop + fpsCounterHeight; | 150 platformLayerTreeTop = fpsCounterTop + fpsCounterHeight; |
151 else | 151 else |
152 platformLayerTreeTop = 0; | 152 platformLayerTreeTop = 0; |
153 | 153 |
154 if (settings.showFPSCounter) | 154 if (settings.showFPSCounter) |
155 drawFPSCounter(canvas, layerTreeHostImpl()->fpsCounter(), fpsCounterTop,
fpsCounterHeight); | 155 drawFPSCounter(canvas, layerTreeHostImpl()->fpsCounter(), fpsCounterTop,
fpsCounterHeight); |
156 | 156 |
157 if (settings.showPlatformLayerTree && m_fontAtlas.get()) { | 157 if (settings.showPlatformLayerTree && m_fontAtlas.get()) { |
158 std::string layerTree = layerTreeHostImpl()->layerTreeAsText(); | 158 std::string layerTree = layerTreeHostImpl()->layerTreeAsText(); |
159 m_fontAtlas->drawText(canvas, createPaint(), layerTree, gfx::Point(2, pl
atformLayerTreeTop), bounds()); | 159 m_fontAtlas->drawText(canvas, createPaint(), layerTree, gfx::Point(2, pl
atformLayerTreeTop), bounds()); |
160 } | 160 } |
161 | 161 |
162 if (settings.showDebugRects()) | 162 if (settings.showDebugRects()) |
163 drawDebugRects(canvas, layerTreeHostImpl()->debugRectHistory()); | 163 drawDebugRects(canvas, layerTreeHostImpl()->debugRectHistory()); |
164 } | 164 } |
165 | 165 |
166 void CCHeadsUpDisplayLayerImpl::drawFPSCounter(SkCanvas* canvas, CCFrameRateCoun
ter* fpsCounter, int top, int height) | 166 void HeadsUpDisplayLayerImpl::drawFPSCounter(SkCanvas* canvas, FrameRateCounter*
fpsCounter, int top, int height) |
167 { | 167 { |
168 float textWidth = 170; // so text fits on linux. | 168 float textWidth = 170; // so text fits on linux. |
169 float graphWidth = fpsCounter->timeStampHistorySize(); | 169 float graphWidth = fpsCounter->timeStampHistorySize(); |
170 | 170 |
171 // Draw the FPS text. | 171 // Draw the FPS text. |
172 drawFPSCounterText(canvas, fpsCounter, top, textWidth, height); | 172 drawFPSCounterText(canvas, fpsCounter, top, textWidth, height); |
173 | 173 |
174 // Draw FPS graph. | 174 // Draw FPS graph. |
175 const double loFPS = 0; | 175 const double loFPS = 0; |
176 const double hiFPS = 80; | 176 const double hiFPS = 80; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 path.lineTo(cur); | 212 path.lineTo(cur); |
213 x += 1; | 213 x += 1; |
214 } | 214 } |
215 paint.setColor(SK_ColorRED); | 215 paint.setColor(SK_ColorRED); |
216 paint.setStyle(SkPaint::kStroke_Style); | 216 paint.setStyle(SkPaint::kStroke_Style); |
217 paint.setStrokeWidth(1); | 217 paint.setStrokeWidth(1); |
218 paint.setAntiAlias(true); | 218 paint.setAntiAlias(true); |
219 canvas->drawPath(path, paint); | 219 canvas->drawPath(path, paint); |
220 } | 220 } |
221 | 221 |
222 void CCHeadsUpDisplayLayerImpl::drawFPSCounterText(SkCanvas* canvas, CCFrameRate
Counter* fpsCounter, int top, int width, int height) | 222 void HeadsUpDisplayLayerImpl::drawFPSCounterText(SkCanvas* canvas, FrameRateCoun
ter* fpsCounter, int top, int width, int height) |
223 { | 223 { |
224 double averageFPS, stdDeviation; | 224 double averageFPS, stdDeviation; |
225 fpsCounter->getAverageFPSAndStandardDeviation(averageFPS, stdDeviation); | 225 fpsCounter->getAverageFPSAndStandardDeviation(averageFPS, stdDeviation); |
226 | 226 |
227 // Draw background. | 227 // Draw background. |
228 SkPaint paint = createPaint(); | 228 SkPaint paint = createPaint(); |
229 paint.setColor(SK_ColorBLACK); | 229 paint.setColor(SK_ColorBLACK); |
230 canvas->drawRect(SkRect::MakeXYWH(2, top, width, height), paint); | 230 canvas->drawRect(SkRect::MakeXYWH(2, top, width, height), paint); |
231 | 231 |
232 // Draw FPS text. | 232 // Draw FPS text. |
233 if (m_fontAtlas.get()) | 233 if (m_fontAtlas.get()) |
234 m_fontAtlas->drawText(canvas, createPaint(), base::StringPrintf("FPS: %4
.1f +/- %3.1f", averageFPS, stdDeviation), gfx::Point(10, height / 3), IntSize(w
idth, height)); | 234 m_fontAtlas->drawText(canvas, createPaint(), base::StringPrintf("FPS: %4
.1f +/- %3.1f", averageFPS, stdDeviation), gfx::Point(10, height / 3), IntSize(w
idth, height)); |
235 } | 235 } |
236 | 236 |
237 void CCHeadsUpDisplayLayerImpl::drawDebugRects(SkCanvas* canvas, CCDebugRectHist
ory* debugRectHistory) | 237 void HeadsUpDisplayLayerImpl::drawDebugRects(SkCanvas* canvas, DebugRectHistory*
debugRectHistory) |
238 { | 238 { |
239 const Vector<CCDebugRect>& debugRects = debugRectHistory->debugRects(); | 239 const Vector<DebugRect>& debugRects = debugRectHistory->debugRects(); |
240 | 240 |
241 for (size_t i = 0; i < debugRects.size(); ++i) { | 241 for (size_t i = 0; i < debugRects.size(); ++i) { |
242 SkColor strokeColor = 0; | 242 SkColor strokeColor = 0; |
243 SkColor fillColor = 0; | 243 SkColor fillColor = 0; |
244 | 244 |
245 switch (debugRects[i].type) { | 245 switch (debugRects[i].type) { |
246 case PaintRectType: | 246 case PaintRectType: |
247 // Paint rects in red | 247 // Paint rects in red |
248 strokeColor = SkColorSetARGB(255, 255, 0, 0); | 248 strokeColor = SkColorSetARGB(255, 255, 0, 0); |
249 fillColor = SkColorSetARGB(30, 255, 0, 0); | 249 fillColor = SkColorSetARGB(30, 255, 0, 0); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 paint.setColor(fillColor); | 281 paint.setColor(fillColor); |
282 canvas->drawRect(skRect, paint); | 282 canvas->drawRect(skRect, paint); |
283 | 283 |
284 paint.setColor(strokeColor); | 284 paint.setColor(strokeColor); |
285 paint.setStyle(SkPaint::kStroke_Style); | 285 paint.setStyle(SkPaint::kStroke_Style); |
286 paint.setStrokeWidth(2); | 286 paint.setStrokeWidth(2); |
287 canvas->drawRect(skRect, paint); | 287 canvas->drawRect(skRect, paint); |
288 } | 288 } |
289 } | 289 } |
290 | 290 |
291 const char* CCHeadsUpDisplayLayerImpl::layerTypeAsString() const | 291 const char* HeadsUpDisplayLayerImpl::layerTypeAsString() const |
292 { | 292 { |
293 return "HeadsUpDisplayLayer"; | 293 return "HeadsUpDisplayLayer"; |
294 } | 294 } |
295 | 295 |
296 } | 296 } |
OLD | NEW |