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 RGBA_8888, gfx::ColorSpace()); |
|
danakj
2017/05/01 22:57:32
do you want best_render_buffer_format() instead of
sohan
2017/05/03 11:06:34
Acknowledged.
| |
| 101 resources_.push_back(std::move(resource)); | 103 resources_.push_back(std::move(resource)); |
| 102 } | 104 } |
| 103 | 105 |
| 104 void HeadsUpDisplayLayerImpl::ReleaseUnmatchedSizeResources( | 106 void HeadsUpDisplayLayerImpl::ReleaseUnmatchedSizeResources( |
| 105 ResourceProvider* resource_provider) { | 107 ResourceProvider* resource_provider) { |
| 106 base::EraseIf(resources_, | 108 base::EraseIf(resources_, |
| 107 [this](const std::unique_ptr<ScopedResource>& resource) { | 109 [this](const std::unique_ptr<ScopedResource>& resource) { |
| 108 return internal_content_bounds_ != resource->size(); | 110 return internal_content_bounds_ != resource->size(); |
| 109 }); | 111 }); |
| 110 } | 112 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 150 render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>(); | 152 render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>(); |
| 151 quad->SetNew(shared_quad_state, quad_rect, opaque_rect, visible_quad_rect, | 153 quad->SetNew(shared_quad_state, quad_rect, opaque_rect, visible_quad_rect, |
| 152 resources_.back()->id(), premultiplied_alpha, uv_top_left, | 154 resources_.back()->id(), premultiplied_alpha, uv_top_left, |
| 153 uv_bottom_right, SK_ColorTRANSPARENT, vertex_opacity, flipped, | 155 uv_bottom_right, SK_ColorTRANSPARENT, vertex_opacity, flipped, |
| 154 nearest_neighbor, false); | 156 nearest_neighbor, false); |
| 155 ValidateQuadResources(quad); | 157 ValidateQuadResources(quad); |
| 156 } | 158 } |
| 157 | 159 |
| 158 void HeadsUpDisplayLayerImpl::UpdateHudTexture( | 160 void HeadsUpDisplayLayerImpl::UpdateHudTexture( |
| 159 DrawMode draw_mode, | 161 DrawMode draw_mode, |
| 160 ResourceProvider* resource_provider) { | 162 ResourceProvider* resource_provider, |
| 163 ContextProvider* context_provider) { | |
|
danakj
2017/05/01 22:57:32
What happens with --disable-gpu where the context
sohan
2017/05/03 11:06:34
I hope we do not want the SW raster path anymore,
danakj
2017/05/03 14:44:51
That would mean you can't have a HUD when using so
sohan
2017/05/03 14:50:30
OK, so we keep the old SW raster code path too?
danakj
2017/05/03 14:52:08
Yes, we need it when there is no GPU.
sohan
2017/05/04 12:03:57
Done.
| |
| 161 if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE || !resources_.back()->id()) | 164 if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE || !resources_.back()->id()) |
| 162 return; | 165 return; |
| 163 | 166 |
| 164 SkISize canvas_size; | 167 ContextProvider::ScopedContext scoped_context(context_provider); |
| 165 if (hud_surface_) | 168 gpu::gles2::GLES2Interface* gl = scoped_context.ContextGL(); |
| 166 canvas_size = hud_surface_->getCanvas()->getBaseLayerSize(); | 169 DCHECK(gl); |
| 167 else | 170 ScopedGpuRaster gpu_raster(context_provider); |
| 168 canvas_size.set(0, 0); | 171 ResourceProvider::ScopedWriteLockGL lock(resource_provider, |
| 172 resources_.back()->id(), false); | |
|
danakj
2017/05/01 22:57:32
Can you comment that you pass false here because y
sohan
2017/05/03 11:06:34
Done.
| |
| 173 gfx::Rect raster_rect(internal_content_bounds_); | |
|
danakj
2017/05/01 22:57:32
you could remove this var and go directly to the S
sohan
2017/05/03 11:06:35
Done.
| |
| 174 SkIRect raster_bounds = gfx::RectToSkIRect(raster_rect); | |
| 169 | 175 |
| 170 if (canvas_size.width() != internal_content_bounds_.width() || | 176 { |
| 171 canvas_size.height() != internal_content_bounds_.height() || | 177 TRACE_EVENT0("cc", "CreateHudCanvas"); |
| 172 !hud_surface_) { | 178 if (hud_surface_) { |
| 173 TRACE_EVENT0("cc", "ResizeHudCanvas"); | 179 hud_surface_->prepareForExternalIO(); |
|
danakj
2017/05/01 22:57:32
Do you need this since this is the single owner of
sohan
2017/05/03 11:06:35
as we remove the surface handling based on your co
| |
| 174 | 180 hud_surface_.reset(); |
| 175 hud_surface_ = SkSurface::MakeRasterN32Premul( | 181 } |
| 176 internal_content_bounds_.width(), internal_content_bounds_.height()); | 182 ResourceProvider::ScopedSkSurfaceProvider scoped_surface( |
| 183 context_provider, &lock, false, false, false, 0); | |
|
danakj
2017/05/01 22:57:32
again comment to explain the false and give these
sohan
2017/05/03 11:06:35
Done.
| |
| 184 hud_surface_ = scoped_surface.sk_sp_surface(); | |
|
danakj
2017/05/01 22:57:32
why do you keep the surface alive for gpu raster?
sohan
2017/05/03 11:06:35
Done.
| |
| 177 } | 185 } |
| 178 | 186 |
| 179 UpdateHudContents(); | 187 UpdateHudContents(); |
| 180 | 188 |
| 181 { | 189 { |
| 182 TRACE_EVENT0("cc", "DrawHudContents"); | 190 TRACE_EVENT0("cc", "DrawHudContents"); |
| 183 hud_surface_->getCanvas()->clear(SkColorSetARGB(0, 0, 0, 0)); | 191 hud_surface_->getCanvas()->clear(SkColorSetARGB(0, 0, 0, 0)); |
| 184 hud_surface_->getCanvas()->save(); | 192 hud_surface_->getCanvas()->save(); |
| 193 hud_surface_->getCanvas()->translate(-raster_rect.x(), -raster_rect.y()); | |
|
danakj
2017/05/01 22:57:32
can you point me how would x and y be not 0 here?
sohan
2017/05/03 11:06:35
Yes, this was not needed, i tried to use the same
| |
| 194 hud_surface_->getCanvas()->clipRect(SkRect::MakeFromIRect(raster_bounds)); | |
|
danakj
2017/05/01 22:57:32
how come the clip?
sohan
2017/05/03 11:06:35
Same as above.
| |
| 185 hud_surface_->getCanvas()->scale(internal_contents_scale_, | 195 hud_surface_->getCanvas()->scale(internal_contents_scale_, |
| 186 internal_contents_scale_); | 196 internal_contents_scale_); |
| 187 | 197 |
| 188 DrawHudContents(hud_surface_->getCanvas()); | 198 DrawHudContents(hud_surface_->getCanvas()); |
| 189 | 199 |
| 190 hud_surface_->getCanvas()->restore(); | 200 hud_surface_->getCanvas()->restore(); |
| 191 } | 201 } |
| 192 | 202 |
| 193 TRACE_EVENT0("cc", "UploadHudTexture"); | 203 TRACE_EVENT0("cc", "UploadHudTexture"); |
| 194 SkPixmap pixmap; | 204 |
| 195 hud_surface_->peekPixels(&pixmap); | 205 const uint64_t fence = gl->InsertFenceSyncCHROMIUM(); |
| 196 DCHECK(pixmap.addr()); | 206 |
| 197 DCHECK(pixmap.info().colorType() == kN32_SkColorType); | 207 gl->OrderingBarrierCHROMIUM(); |
| 198 resource_provider->CopyToResource(resources_.back()->id(), | 208 |
| 199 static_cast<const uint8_t*>(pixmap.addr()), | 209 gpu::SyncToken sync_token; |
| 200 internal_content_bounds_); | 210 gl->GenUnverifiedSyncTokenCHROMIUM(fence, sync_token.GetData()); |
|
danakj
2017/05/01 22:57:33
This stuff is more heavy then you need if !async_w
sohan
2017/05/03 11:06:34
I am using GenSyncToken in latest PS, i hope this
| |
| 201 resource_provider->GenerateSyncTokenForResource(resources_.back()->id()); | 211 lock.set_sync_token(sync_token); |
| 212 lock.set_synchronized(true); | |
| 202 } | 213 } |
| 203 | 214 |
| 204 void HeadsUpDisplayLayerImpl::ReleaseResources() { | 215 void HeadsUpDisplayLayerImpl::ReleaseResources() { |
| 205 resources_.clear(); | 216 resources_.clear(); |
| 206 } | 217 } |
| 207 | 218 |
| 208 gfx::Rect HeadsUpDisplayLayerImpl::GetEnclosingRectInTargetSpace() const { | 219 gfx::Rect HeadsUpDisplayLayerImpl::GetEnclosingRectInTargetSpace() const { |
| 209 DCHECK_GT(internal_contents_scale_, 0.f); | 220 DCHECK_GT(internal_contents_scale_, 0.f); |
| 210 return GetScaledEnclosingRectInTargetSpace(internal_contents_scale_); | 221 return GetScaledEnclosingRectInTargetSpace(internal_contents_scale_); |
| 211 } | 222 } |
| (...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 794 return "cc::HeadsUpDisplayLayerImpl"; | 805 return "cc::HeadsUpDisplayLayerImpl"; |
| 795 } | 806 } |
| 796 | 807 |
| 797 void HeadsUpDisplayLayerImpl::AsValueInto( | 808 void HeadsUpDisplayLayerImpl::AsValueInto( |
| 798 base::trace_event::TracedValue* dict) const { | 809 base::trace_event::TracedValue* dict) const { |
| 799 LayerImpl::AsValueInto(dict); | 810 LayerImpl::AsValueInto(dict); |
| 800 dict->SetString("layer_name", "Heads Up Display Layer"); | 811 dict->SetString("layer_name", "Heads Up Display Layer"); |
| 801 } | 812 } |
| 802 | 813 |
| 803 } // namespace cc | 814 } // namespace cc |
| OLD | NEW |