Chromium Code Reviews| 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 "cc/layers/heads_up_display_layer_impl.h" | 5 #include "cc/layers/heads_up_display_layer_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/numerics/safe_conversions.h" | 13 #include "base/numerics/safe_conversions.h" |
| 14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 16 #include "base/trace_event/trace_event.h" | 16 #include "base/trace_event/trace_event.h" |
| 17 #include "base/trace_event/trace_event_argument.h" | 17 #include "base/trace_event/trace_event_argument.h" |
| 18 #include "cc/debug/debug_colors.h" | 18 #include "cc/debug/debug_colors.h" |
| 19 #include "cc/output/begin_frame_args.h" | 19 #include "cc/output/begin_frame_args.h" |
| 20 #include "cc/quads/texture_draw_quad.h" | 20 #include "cc/quads/texture_draw_quad.h" |
| 21 #include "cc/raster/scoped_gpu_raster.h" | |
| 21 #include "cc/resources/memory_history.h" | 22 #include "cc/resources/memory_history.h" |
| 22 #include "cc/trees/frame_rate_counter.h" | 23 #include "cc/trees/frame_rate_counter.h" |
| 23 #include "cc/trees/layer_tree_host_impl.h" | 24 #include "cc/trees/layer_tree_host_impl.h" |
| 24 #include "cc/trees/layer_tree_impl.h" | 25 #include "cc/trees/layer_tree_impl.h" |
| 26 #include "gpu/command_buffer/client/gles2_interface.h" | |
| 25 #include "skia/ext/platform_canvas.h" | 27 #include "skia/ext/platform_canvas.h" |
| 26 #include "third_party/skia/include/core/SkCanvas.h" | 28 #include "third_party/skia/include/core/SkCanvas.h" |
| 27 #include "third_party/skia/include/core/SkPaint.h" | 29 #include "third_party/skia/include/core/SkPaint.h" |
| 28 #include "third_party/skia/include/core/SkPath.h" | 30 #include "third_party/skia/include/core/SkPath.h" |
| 29 #include "third_party/skia/include/core/SkTypeface.h" | 31 #include "third_party/skia/include/core/SkTypeface.h" |
| 30 #include "third_party/skia/include/effects/SkColorMatrixFilter.h" | 32 #include "third_party/skia/include/effects/SkColorMatrixFilter.h" |
| 31 #include "third_party/skia/include/effects/SkGradientShader.h" | 33 #include "third_party/skia/include/effects/SkGradientShader.h" |
| 32 #include "ui/gfx/geometry/point.h" | 34 #include "ui/gfx/geometry/point.h" |
| 33 #include "ui/gfx/geometry/size.h" | 35 #include "ui/gfx/geometry/size.h" |
| 34 #include "ui/gfx/geometry/size_conversions.h" | 36 #include "ui/gfx/geometry/size_conversions.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 void HeadsUpDisplayLayerImpl::AcquireResource( | 90 void HeadsUpDisplayLayerImpl::AcquireResource( |
| 89 ResourceProvider* resource_provider) { | 91 ResourceProvider* resource_provider) { |
| 90 for (auto& resource : resources_) { | 92 for (auto& resource : resources_) { |
| 91 if (!resource_provider->InUseByConsumer(resource->id())) { | 93 if (!resource_provider->InUseByConsumer(resource->id())) { |
| 92 resource.swap(resources_.back()); | 94 resource.swap(resources_.back()); |
| 93 return; | 95 return; |
| 94 } | 96 } |
| 95 } | 97 } |
| 96 | 98 |
| 97 auto resource = base::MakeUnique<ScopedResource>(resource_provider); | 99 auto resource = base::MakeUnique<ScopedResource>(resource_provider); |
| 98 resource->Allocate( | 100 resource->Allocate(internal_content_bounds_, |
| 99 internal_content_bounds_, ResourceProvider::TEXTURE_HINT_IMMUTABLE, | 101 ResourceProvider::TEXTURE_HINT_IMMUTABLE_FRAMEBUFFER, |
| 100 resource_provider->best_texture_format(), gfx::ColorSpace()); | 102 resource_provider->best_render_buffer_format(), |
| 103 gfx::ColorSpace()); | |
| 101 resources_.push_back(std::move(resource)); | 104 resources_.push_back(std::move(resource)); |
| 102 } | 105 } |
| 103 | 106 |
| 104 void HeadsUpDisplayLayerImpl::ReleaseUnmatchedSizeResources( | 107 void HeadsUpDisplayLayerImpl::ReleaseUnmatchedSizeResources( |
| 105 ResourceProvider* resource_provider) { | 108 ResourceProvider* resource_provider) { |
| 106 base::EraseIf(resources_, | 109 base::EraseIf(resources_, |
| 107 [this](const std::unique_ptr<ScopedResource>& resource) { | 110 [this](const std::unique_ptr<ScopedResource>& resource) { |
| 108 return internal_content_bounds_ != resource->size(); | 111 return internal_content_bounds_ != resource->size(); |
| 109 }); | 112 }); |
| 110 } | 113 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 150 render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>(); | 153 render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>(); |
| 151 quad->SetNew(shared_quad_state, quad_rect, opaque_rect, visible_quad_rect, | 154 quad->SetNew(shared_quad_state, quad_rect, opaque_rect, visible_quad_rect, |
| 152 resources_.back()->id(), premultiplied_alpha, uv_top_left, | 155 resources_.back()->id(), premultiplied_alpha, uv_top_left, |
| 153 uv_bottom_right, SK_ColorTRANSPARENT, vertex_opacity, flipped, | 156 uv_bottom_right, SK_ColorTRANSPARENT, vertex_opacity, flipped, |
| 154 nearest_neighbor, false); | 157 nearest_neighbor, false); |
| 155 ValidateQuadResources(quad); | 158 ValidateQuadResources(quad); |
| 156 } | 159 } |
| 157 | 160 |
| 158 void HeadsUpDisplayLayerImpl::UpdateHudTexture( | 161 void HeadsUpDisplayLayerImpl::UpdateHudTexture( |
| 159 DrawMode draw_mode, | 162 DrawMode draw_mode, |
| 160 ResourceProvider* resource_provider) { | 163 ResourceProvider* resource_provider, |
| 164 ContextProvider* context_provider) { | |
| 161 if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE || !resources_.back()->id()) | 165 if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE || !resources_.back()->id()) |
| 162 return; | 166 return; |
| 163 | 167 |
| 164 SkISize canvas_size; | 168 if (context_provider) { |
| 165 if (hud_surface_) | 169 gpu::gles2::GLES2Interface* gl = context_provider->ContextGL(); |
| 166 canvas_size = hud_surface_->getCanvas()->getBaseLayerSize(); | 170 DCHECK(gl); |
| 167 else | 171 ScopedGpuRaster gpu_raster(context_provider); |
| 168 canvas_size.set(0, 0); | 172 bool using_worker_context = false; |
| 173 ResourceProvider::ScopedWriteLockGL lock( | |
| 174 resource_provider, resources_.back()->id(), using_worker_context); | |
| 169 | 175 |
| 170 if (canvas_size.width() != internal_content_bounds_.width() || | 176 TRACE_EVENT_BEGIN0("cc", "CreateHudCanvas"); |
| 171 canvas_size.height() != internal_content_bounds_.height() || | 177 bool use_distance_field_text = false; |
| 172 !hud_surface_) { | 178 bool can_use_lcd_text = false; |
| 173 TRACE_EVENT0("cc", "ResizeHudCanvas"); | 179 int msaa_sample_count = 0; |
| 180 ResourceProvider::ScopedSkSurfaceProvider scoped_surface( | |
| 181 context_provider, &lock, using_worker_context, use_distance_field_text, | |
| 182 can_use_lcd_text, msaa_sample_count); | |
| 183 SkCanvas* gpu_raster_canvas = scoped_surface.sk_surface()->getCanvas(); | |
| 184 TRACE_EVENT_END0("cc", "CreateHudCanvas"); | |
| 174 | 185 |
| 175 hud_surface_ = SkSurface::MakeRasterN32Premul( | 186 UpdateHudContents(); |
| 176 internal_content_bounds_.width(), internal_content_bounds_.height()); | |
| 177 } | |
| 178 | 187 |
| 179 UpdateHudContents(); | 188 DrawHudContents(gpu_raster_canvas); |
| 180 | 189 |
| 181 { | 190 TRACE_EVENT_BEGIN0("cc", "UploadHudTexture"); |
| 182 TRACE_EVENT0("cc", "DrawHudContents"); | 191 const uint64_t fence = gl->InsertFenceSyncCHROMIUM(); |
| 183 hud_surface_->getCanvas()->clear(SkColorSetARGB(0, 0, 0, 0)); | 192 gl->OrderingBarrierCHROMIUM(); |
| 184 hud_surface_->getCanvas()->save(); | 193 gpu::SyncToken sync_token; |
| 185 hud_surface_->getCanvas()->scale(internal_contents_scale_, | 194 gl->GenSyncTokenCHROMIUM(fence, sync_token.GetData()); |
| 186 internal_contents_scale_); | 195 lock.set_sync_token(sync_token); |
| 196 lock.set_synchronized(true); | |
|
ericrk
2017/06/07 20:50:18
Don't worry about it for this change, but I wonder
| |
| 197 TRACE_EVENT_END0("cc", "UploadHudTexture"); | |
| 198 } else { | |
| 199 SkISize canvas_size; | |
| 200 if (hud_surface_) | |
| 201 canvas_size = hud_surface_->getCanvas()->getBaseLayerSize(); | |
| 202 else | |
| 203 canvas_size.set(0, 0); | |
| 204 | |
| 205 if (canvas_size.width() != internal_content_bounds_.width() || | |
| 206 canvas_size.height() != internal_content_bounds_.height() || | |
| 207 !hud_surface_) { | |
| 208 TRACE_EVENT0("cc", "ResizeHudCanvas"); | |
| 209 | |
| 210 hud_surface_ = SkSurface::MakeRasterN32Premul( | |
| 211 internal_content_bounds_.width(), internal_content_bounds_.height()); | |
| 212 } | |
| 213 | |
| 214 UpdateHudContents(); | |
| 187 | 215 |
| 188 DrawHudContents(hud_surface_->getCanvas()); | 216 DrawHudContents(hud_surface_->getCanvas()); |
| 189 | 217 |
| 190 hud_surface_->getCanvas()->restore(); | 218 TRACE_EVENT0("cc", "UploadHudTexture"); |
| 219 SkPixmap pixmap; | |
| 220 hud_surface_->peekPixels(&pixmap); | |
| 221 DCHECK(pixmap.addr()); | |
| 222 DCHECK(pixmap.info().colorType() == kN32_SkColorType); | |
| 223 resource_provider->CopyToResource( | |
| 224 resources_.back()->id(), static_cast<const uint8_t*>(pixmap.addr()), | |
| 225 internal_content_bounds_); | |
| 226 resource_provider->GenerateSyncTokenForResource(resources_.back()->id()); | |
| 191 } | 227 } |
| 192 | |
| 193 TRACE_EVENT0("cc", "UploadHudTexture"); | |
| 194 SkPixmap pixmap; | |
| 195 hud_surface_->peekPixels(&pixmap); | |
| 196 DCHECK(pixmap.addr()); | |
| 197 DCHECK(pixmap.info().colorType() == kN32_SkColorType); | |
| 198 resource_provider->CopyToResource(resources_.back()->id(), | |
| 199 static_cast<const uint8_t*>(pixmap.addr()), | |
| 200 internal_content_bounds_); | |
| 201 resource_provider->GenerateSyncTokenForResource(resources_.back()->id()); | |
| 202 } | 228 } |
| 203 | 229 |
| 204 void HeadsUpDisplayLayerImpl::ReleaseResources() { | 230 void HeadsUpDisplayLayerImpl::ReleaseResources() { |
| 205 resources_.clear(); | 231 resources_.clear(); |
| 206 } | 232 } |
| 207 | 233 |
| 208 gfx::Rect HeadsUpDisplayLayerImpl::GetEnclosingRectInTargetSpace() const { | 234 gfx::Rect HeadsUpDisplayLayerImpl::GetEnclosingRectInTargetSpace() const { |
| 209 DCHECK_GT(internal_contents_scale_, 0.f); | 235 DCHECK_GT(internal_contents_scale_, 0.f); |
| 210 return GetScaledEnclosingRectInTargetSpace(internal_contents_scale_); | 236 return GetScaledEnclosingRectInTargetSpace(internal_contents_scale_); |
| 211 } | 237 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 251 } | 277 } |
| 252 } | 278 } |
| 253 | 279 |
| 254 fps_graph_.UpdateUpperBound(); | 280 fps_graph_.UpdateUpperBound(); |
| 255 paint_time_graph_.UpdateUpperBound(); | 281 paint_time_graph_.UpdateUpperBound(); |
| 256 } | 282 } |
| 257 | 283 |
| 258 void HeadsUpDisplayLayerImpl::DrawHudContents(SkCanvas* canvas) { | 284 void HeadsUpDisplayLayerImpl::DrawHudContents(SkCanvas* canvas) { |
| 259 const LayerTreeDebugState& debug_state = layer_tree_impl()->debug_state(); | 285 const LayerTreeDebugState& debug_state = layer_tree_impl()->debug_state(); |
| 260 | 286 |
| 287 TRACE_EVENT0("cc", "DrawHudContents"); | |
| 288 canvas->clear(SkColorSetARGB(0, 0, 0, 0)); | |
| 289 canvas->save(); | |
| 290 canvas->scale(internal_contents_scale_, internal_contents_scale_); | |
| 291 | |
| 261 if (debug_state.ShowHudRects()) { | 292 if (debug_state.ShowHudRects()) { |
| 262 DrawDebugRects(canvas, layer_tree_impl()->debug_rect_history()); | 293 DrawDebugRects(canvas, layer_tree_impl()->debug_rect_history()); |
| 263 if (IsAnimatingHUDContents()) { | 294 if (IsAnimatingHUDContents()) { |
| 264 layer_tree_impl()->SetNeedsRedraw(); | 295 layer_tree_impl()->SetNeedsRedraw(); |
| 265 } | 296 } |
| 266 } | 297 } |
| 267 | 298 |
| 268 if (!debug_state.show_fps_counter) | 299 if (!debug_state.show_fps_counter) { |
| 300 canvas->restore(); | |
| 269 return; | 301 return; |
| 302 } | |
| 270 | 303 |
| 271 SkRect area = | 304 SkRect area = |
| 272 DrawFPSDisplay(canvas, layer_tree_impl()->frame_rate_counter(), 0, 0); | 305 DrawFPSDisplay(canvas, layer_tree_impl()->frame_rate_counter(), 0, 0); |
| 273 area = DrawGpuRasterizationStatus(canvas, 0, area.bottom(), | 306 area = DrawGpuRasterizationStatus(canvas, 0, area.bottom(), |
| 274 SkMaxScalar(area.width(), 150)); | 307 SkMaxScalar(area.width(), 150)); |
| 275 | 308 |
| 276 if (debug_state.ShowMemoryStats() && memory_entry_.total_bytes_used) | 309 if (debug_state.ShowMemoryStats() && memory_entry_.total_bytes_used) |
| 277 DrawMemoryDisplay(canvas, 0, area.bottom(), SkMaxScalar(area.width(), 150)); | 310 DrawMemoryDisplay(canvas, 0, area.bottom(), SkMaxScalar(area.width(), 150)); |
| 311 | |
| 312 canvas->restore(); | |
| 278 } | 313 } |
| 279 int HeadsUpDisplayLayerImpl::MeasureText(SkPaint* paint, | 314 int HeadsUpDisplayLayerImpl::MeasureText(SkPaint* paint, |
| 280 const std::string& text, | 315 const std::string& text, |
| 281 int size) const { | 316 int size) const { |
| 282 DCHECK(typeface_.get()); | 317 DCHECK(typeface_.get()); |
| 283 const bool anti_alias = paint->isAntiAlias(); | 318 const bool anti_alias = paint->isAntiAlias(); |
| 284 paint->setAntiAlias(true); | 319 paint->setAntiAlias(true); |
| 285 paint->setTextSize(size); | 320 paint->setTextSize(size); |
| 286 paint->setTypeface(typeface_); | 321 paint->setTypeface(typeface_); |
| 287 SkScalar text_width = paint->measureText(text.c_str(), text.length()); | 322 SkScalar text_width = paint->measureText(text.c_str(), text.length()); |
| (...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 790 return "cc::HeadsUpDisplayLayerImpl"; | 825 return "cc::HeadsUpDisplayLayerImpl"; |
| 791 } | 826 } |
| 792 | 827 |
| 793 void HeadsUpDisplayLayerImpl::AsValueInto( | 828 void HeadsUpDisplayLayerImpl::AsValueInto( |
| 794 base::trace_event::TracedValue* dict) const { | 829 base::trace_event::TracedValue* dict) const { |
| 795 LayerImpl::AsValueInto(dict); | 830 LayerImpl::AsValueInto(dict); |
| 796 dict->SetString("layer_name", "Heads Up Display Layer"); | 831 dict->SetString("layer_name", "Heads Up Display Layer"); |
| 797 } | 832 } |
| 798 | 833 |
| 799 } // namespace cc | 834 } // namespace cc |
| OLD | NEW |