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 context_provider->DetachFromThread(); |
| 166 canvas_size = hud_surface_->getCanvas()->getBaseLayerSize(); | 170 std::unique_ptr<ContextCacheController::ScopedBusy> busy = |
|
ericrk
2017/06/06 20:22:25
I wouldn't expect to need this DetachFromThread or
sohan
2017/06/07 13:31:11
Done.
Yes, this was a little over engineering in
| |
| 167 else | 171 context_provider->CacheController()->ClientBecameBusy(); |
| 168 canvas_size.set(0, 0); | 172 gpu::gles2::GLES2Interface* gl = context_provider->ContextGL(); |
| 173 DCHECK(gl); | |
| 174 ScopedGpuRaster gpu_raster(context_provider); | |
| 175 bool using_worker_context = false; | |
| 176 ResourceProvider::ScopedWriteLockGL lock( | |
| 177 resource_provider, resources_.back()->id(), using_worker_context); | |
| 169 | 178 |
| 170 if (canvas_size.width() != internal_content_bounds_.width() || | 179 TRACE_EVENT_BEGIN0("cc", "CreateHudCanvas"); |
| 171 canvas_size.height() != internal_content_bounds_.height() || | 180 bool use_distance_field_text = false; |
| 172 !hud_surface_) { | 181 bool can_use_lcd_text = false; |
| 173 TRACE_EVENT0("cc", "ResizeHudCanvas"); | 182 int msaa_sample_count = 0; |
| 183 ResourceProvider::ScopedSkSurfaceProvider scoped_surface( | |
| 184 context_provider, &lock, using_worker_context, use_distance_field_text, | |
| 185 can_use_lcd_text, msaa_sample_count); | |
| 186 SkCanvas* gpu_raster_canvas = scoped_surface.sk_surface()->getCanvas(); | |
| 187 TRACE_EVENT_END0("cc", "CreateHudCanvas"); | |
| 174 | 188 |
| 175 hud_surface_ = SkSurface::MakeRasterN32Premul( | 189 UpdateHudContents(); |
| 176 internal_content_bounds_.width(), internal_content_bounds_.height()); | 190 |
| 191 TRACE_EVENT_BEGIN0("cc", "DrawHudContents"); | |
| 192 gpu_raster_canvas->clear(SkColorSetARGB(0, 0, 0, 0)); | |
|
ericrk
2017/06/06 20:22:25
Can we just move the Trace, clear, save, scale, an
sohan
2017/06/07 13:31:11
Done.
Thanks, this does make the code look better
| |
| 193 gpu_raster_canvas->save(); | |
| 194 gpu_raster_canvas->scale(internal_contents_scale_, | |
| 195 internal_contents_scale_); | |
| 196 DrawHudContents(gpu_raster_canvas); | |
| 197 gpu_raster_canvas->restore(); | |
| 198 TRACE_EVENT_END0("cc", "DrawHudContents"); | |
| 199 | |
| 200 TRACE_EVENT_BEGIN0("cc", "UploadHudTexture"); | |
| 201 const uint64_t fence = gl->InsertFenceSyncCHROMIUM(); | |
| 202 gl->OrderingBarrierCHROMIUM(); | |
| 203 gpu::SyncToken sync_token; | |
| 204 gl->GenSyncTokenCHROMIUM(fence, sync_token.GetData()); | |
| 205 lock.set_sync_token(sync_token); | |
| 206 lock.set_synchronized(true); | |
| 207 TRACE_EVENT_END0("cc", "UploadHudTexture"); | |
| 208 | |
| 209 context_provider->CacheController()->ClientBecameNotBusy(std::move(busy)); | |
| 210 context_provider->DetachFromThread(); | |
|
ericrk
2017/06/06 20:22:25
See comment above - Drop these lines if possible..
sohan
2017/06/07 13:31:11
Done.
| |
| 211 } else { | |
| 212 SkISize canvas_size; | |
| 213 if (hud_surface_) | |
| 214 canvas_size = hud_surface_->getCanvas()->getBaseLayerSize(); | |
| 215 else | |
| 216 canvas_size.set(0, 0); | |
| 217 | |
| 218 if (canvas_size.width() != internal_content_bounds_.width() || | |
| 219 canvas_size.height() != internal_content_bounds_.height() || | |
| 220 !hud_surface_) { | |
| 221 TRACE_EVENT0("cc", "ResizeHudCanvas"); | |
| 222 | |
| 223 hud_surface_ = SkSurface::MakeRasterN32Premul( | |
| 224 internal_content_bounds_.width(), internal_content_bounds_.height()); | |
| 225 } | |
| 226 | |
| 227 UpdateHudContents(); | |
| 228 | |
| 229 { | |
| 230 TRACE_EVENT0("cc", "DrawHudContents"); | |
| 231 hud_surface_->getCanvas()->clear(SkColorSetARGB(0, 0, 0, 0)); | |
| 232 hud_surface_->getCanvas()->save(); | |
| 233 hud_surface_->getCanvas()->scale(internal_contents_scale_, | |
| 234 internal_contents_scale_); | |
| 235 | |
| 236 DrawHudContents(hud_surface_->getCanvas()); | |
| 237 | |
| 238 hud_surface_->getCanvas()->restore(); | |
| 239 } | |
| 240 | |
| 241 TRACE_EVENT0("cc", "UploadHudTexture"); | |
| 242 SkPixmap pixmap; | |
| 243 hud_surface_->peekPixels(&pixmap); | |
| 244 DCHECK(pixmap.addr()); | |
| 245 DCHECK(pixmap.info().colorType() == kN32_SkColorType); | |
| 246 resource_provider->CopyToResource( | |
| 247 resources_.back()->id(), static_cast<const uint8_t*>(pixmap.addr()), | |
| 248 internal_content_bounds_); | |
| 249 resource_provider->GenerateSyncTokenForResource(resources_.back()->id()); | |
| 177 } | 250 } |
| 178 | |
| 179 UpdateHudContents(); | |
| 180 | |
| 181 { | |
| 182 TRACE_EVENT0("cc", "DrawHudContents"); | |
| 183 hud_surface_->getCanvas()->clear(SkColorSetARGB(0, 0, 0, 0)); | |
| 184 hud_surface_->getCanvas()->save(); | |
| 185 hud_surface_->getCanvas()->scale(internal_contents_scale_, | |
| 186 internal_contents_scale_); | |
| 187 | |
| 188 DrawHudContents(hud_surface_->getCanvas()); | |
| 189 | |
| 190 hud_surface_->getCanvas()->restore(); | |
| 191 } | |
| 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 } | 251 } |
| 203 | 252 |
| 204 void HeadsUpDisplayLayerImpl::ReleaseResources() { | 253 void HeadsUpDisplayLayerImpl::ReleaseResources() { |
| 205 resources_.clear(); | 254 resources_.clear(); |
| 206 } | 255 } |
| 207 | 256 |
| 208 gfx::Rect HeadsUpDisplayLayerImpl::GetEnclosingRectInTargetSpace() const { | 257 gfx::Rect HeadsUpDisplayLayerImpl::GetEnclosingRectInTargetSpace() const { |
| 209 DCHECK_GT(internal_contents_scale_, 0.f); | 258 DCHECK_GT(internal_contents_scale_, 0.f); |
| 210 return GetScaledEnclosingRectInTargetSpace(internal_contents_scale_); | 259 return GetScaledEnclosingRectInTargetSpace(internal_contents_scale_); |
| 211 } | 260 } |
| (...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 790 return "cc::HeadsUpDisplayLayerImpl"; | 839 return "cc::HeadsUpDisplayLayerImpl"; |
| 791 } | 840 } |
| 792 | 841 |
| 793 void HeadsUpDisplayLayerImpl::AsValueInto( | 842 void HeadsUpDisplayLayerImpl::AsValueInto( |
| 794 base::trace_event::TracedValue* dict) const { | 843 base::trace_event::TracedValue* dict) const { |
| 795 LayerImpl::AsValueInto(dict); | 844 LayerImpl::AsValueInto(dict); |
| 796 dict->SetString("layer_name", "Heads Up Display Layer"); | 845 dict->SetString("layer_name", "Heads Up Display Layer"); |
| 797 } | 846 } |
| 798 | 847 |
| 799 } // namespace cc | 848 } // namespace cc |
| OLD | NEW |