Commit 123a218d authored by kylechar's avatar kylechar Committed by Commit Bot

Add SharedBitmapReporter interface.

VideoResourceUpdater currently uses LayerTreeFrameSink as the interface
through which to notify the display compositor about shared bitmaps.
This doesn't work UseSurfaceLayerForVideo where there is no
LayerTreeFrameSink.

Pull the two required functions out of LayerTreeFrameSink and into
SharedBitmapReporter. LayerTreeFrameSink has SharedBitmapReporter as a
subclass and doesn't implement the functions so nothing changes with
regards to it. VideoResourceUpdater now takes a SharedBitmapReporter
instead of a LayerTreeFrameSink.

An implementation of SharedBitmapReporter that calls into
mojom::CompositorFrameSinkPtr can be added trivially to support
UseSurfaceLayerInVideo after this patch.

Bug: 807840
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: I9a5a07140f8aa1614d1b647f3af1dd5d7aab2cd2
Reviewed-on: https://chromium-review.googlesource.com/1053054
Commit-Queue: kylechar <kylechar@chromium.org>
Reviewed-by: default avatardanakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#558011}
parent 381d19a1
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "cc/layers/video_frame_provider_client_impl.h" #include "cc/layers/video_frame_provider_client_impl.h"
#include "cc/resources/resource_provider.h" #include "cc/resources/resource_provider.h"
#include "cc/trees/layer_tree_frame_sink.h"
#include "cc/trees/layer_tree_impl.h" #include "cc/trees/layer_tree_impl.h"
#include "cc/trees/occlusion.h" #include "cc/trees/occlusion.h"
#include "cc/trees/task_runner_provider.h" #include "cc/trees/task_runner_provider.h"
......
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
#include "cc/base/math_util.h" #include "cc/base/math_util.h"
#include "cc/paint/skia_paint_canvas.h" #include "cc/paint/skia_paint_canvas.h"
#include "cc/resources/layer_tree_resource_provider.h" #include "cc/resources/layer_tree_resource_provider.h"
#include "cc/trees/layer_tree_frame_sink.h"
#include "components/viz/common/gpu/context_provider.h" #include "components/viz/common/gpu/context_provider.h"
#include "components/viz/common/gpu/texture_allocation.h" #include "components/viz/common/gpu/texture_allocation.h"
#include "components/viz/common/quads/render_pass.h" #include "components/viz/common/quads/render_pass.h"
...@@ -31,6 +30,7 @@ ...@@ -31,6 +30,7 @@
#include "components/viz/common/quads/yuv_video_draw_quad.h" #include "components/viz/common/quads/yuv_video_draw_quad.h"
#include "components/viz/common/resources/bitmap_allocation.h" #include "components/viz/common/resources/bitmap_allocation.h"
#include "components/viz/common/resources/resource_sizes.h" #include "components/viz/common/resources/resource_sizes.h"
#include "components/viz/common/resources/shared_bitmap_reporter.h"
#include "gpu/GLES2/gl2extchromium.h" #include "gpu/GLES2/gl2extchromium.h"
#include "gpu/command_buffer/client/context_support.h" #include "gpu/command_buffer/client/context_support.h"
#include "gpu/command_buffer/client/gles2_interface.h" #include "gpu/command_buffer/client/gles2_interface.h"
...@@ -252,14 +252,14 @@ class VideoResourceUpdater::SoftwarePlaneResource ...@@ -252,14 +252,14 @@ class VideoResourceUpdater::SoftwarePlaneResource
public: public:
SoftwarePlaneResource(uint32_t plane_resource_id, SoftwarePlaneResource(uint32_t plane_resource_id,
const gfx::Size& size, const gfx::Size& size,
LayerTreeFrameSink* layer_tree_frame_sink) viz::SharedBitmapReporter* shared_bitmap_reporter)
: PlaneResource(plane_resource_id, : PlaneResource(plane_resource_id,
size, size,
viz::ResourceFormat::RGBA_8888, viz::ResourceFormat::RGBA_8888,
/*is_software=*/true), /*is_software=*/true),
layer_tree_frame_sink_(layer_tree_frame_sink), shared_bitmap_reporter_(shared_bitmap_reporter),
shared_bitmap_id_(viz::SharedBitmap::GenerateId()) { shared_bitmap_id_(viz::SharedBitmap::GenerateId()) {
DCHECK(layer_tree_frame_sink_); DCHECK(shared_bitmap_reporter_);
// Allocate SharedMemory and notify display compositor of the allocation. // Allocate SharedMemory and notify display compositor of the allocation.
shared_memory_ = viz::bitmap_allocation::AllocateMappedBitmap( shared_memory_ = viz::bitmap_allocation::AllocateMappedBitmap(
...@@ -268,11 +268,11 @@ class VideoResourceUpdater::SoftwarePlaneResource ...@@ -268,11 +268,11 @@ class VideoResourceUpdater::SoftwarePlaneResource
viz::bitmap_allocation::DuplicateAndCloseMappedBitmap( viz::bitmap_allocation::DuplicateAndCloseMappedBitmap(
shared_memory_.get(), resource_size(), shared_memory_.get(), resource_size(),
viz::ResourceFormat::RGBA_8888); viz::ResourceFormat::RGBA_8888);
layer_tree_frame_sink_->DidAllocateSharedBitmap(std::move(handle), shared_bitmap_reporter_->DidAllocateSharedBitmap(std::move(handle),
shared_bitmap_id_); shared_bitmap_id_);
} }
~SoftwarePlaneResource() override { ~SoftwarePlaneResource() override {
layer_tree_frame_sink_->DidDeleteSharedBitmap(shared_bitmap_id_); shared_bitmap_reporter_->DidDeleteSharedBitmap(shared_bitmap_id_);
} }
const viz::SharedBitmapId& shared_bitmap_id() const { const viz::SharedBitmapId& shared_bitmap_id() const {
...@@ -286,7 +286,7 @@ class VideoResourceUpdater::SoftwarePlaneResource ...@@ -286,7 +286,7 @@ class VideoResourceUpdater::SoftwarePlaneResource
} }
private: private:
LayerTreeFrameSink* const layer_tree_frame_sink_; viz::SharedBitmapReporter* const shared_bitmap_reporter_;
const viz::SharedBitmapId shared_bitmap_id_; const viz::SharedBitmapId shared_bitmap_id_;
std::unique_ptr<base::SharedMemory> shared_memory_; std::unique_ptr<base::SharedMemory> shared_memory_;
...@@ -340,20 +340,20 @@ VideoResourceUpdater::PlaneResource::AsHardware() { ...@@ -340,20 +340,20 @@ VideoResourceUpdater::PlaneResource::AsHardware() {
VideoResourceUpdater::VideoResourceUpdater( VideoResourceUpdater::VideoResourceUpdater(
viz::ContextProvider* context_provider, viz::ContextProvider* context_provider,
LayerTreeFrameSink* layer_tree_frame_sink, viz::SharedBitmapReporter* shared_bitmap_reporter,
LayerTreeResourceProvider* resource_provider, LayerTreeResourceProvider* resource_provider,
bool use_stream_video_draw_quad, bool use_stream_video_draw_quad,
bool use_gpu_memory_buffer_resources, bool use_gpu_memory_buffer_resources,
bool use_r16_texture) bool use_r16_texture)
: context_provider_(context_provider), : context_provider_(context_provider),
layer_tree_frame_sink_(layer_tree_frame_sink), shared_bitmap_reporter_(shared_bitmap_reporter),
resource_provider_(resource_provider), resource_provider_(resource_provider),
use_stream_video_draw_quad_(use_stream_video_draw_quad), use_stream_video_draw_quad_(use_stream_video_draw_quad),
use_gpu_memory_buffer_resources_(use_gpu_memory_buffer_resources), use_gpu_memory_buffer_resources_(use_gpu_memory_buffer_resources),
use_r16_texture_(use_r16_texture), use_r16_texture_(use_r16_texture),
tracing_id_(g_next_video_resource_updater_id.GetNext()), tracing_id_(g_next_video_resource_updater_id.GetNext()),
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
DCHECK(context_provider_ || layer_tree_frame_sink_); DCHECK(context_provider_ || shared_bitmap_reporter_);
base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(
this, "cc::VideoResourceUpdater", base::ThreadTaskRunnerHandle::Get()); this, "cc::VideoResourceUpdater", base::ThreadTaskRunnerHandle::Get());
...@@ -608,7 +608,7 @@ VideoResourceUpdater::PlaneResource* VideoResourceUpdater::AllocateResource( ...@@ -608,7 +608,7 @@ VideoResourceUpdater::PlaneResource* VideoResourceUpdater::AllocateResource(
DCHECK_EQ(format, viz::ResourceFormat::RGBA_8888); DCHECK_EQ(format, viz::ResourceFormat::RGBA_8888);
all_resources_.push_back(std::make_unique<SoftwarePlaneResource>( all_resources_.push_back(std::make_unique<SoftwarePlaneResource>(
plane_resource_id, plane_size, layer_tree_frame_sink_)); plane_resource_id, plane_size, shared_bitmap_reporter_));
} else { } else {
// Video textures get composited into the display frame, the GPU doesn't // Video textures get composited into the display frame, the GPU doesn't
// draw to them directly. // draw to them directly.
......
...@@ -38,10 +38,10 @@ class Transform; ...@@ -38,10 +38,10 @@ class Transform;
namespace viz { namespace viz {
class ContextProvider; class ContextProvider;
class RenderPass; class RenderPass;
class SharedBitmapReporter;
} }
namespace cc { namespace cc {
class LayerTreeFrameSink;
class LayerTreeResourceProvider; class LayerTreeResourceProvider;
// Specifies what type of data is contained in the mailboxes, as well as how // Specifies what type of data is contained in the mailboxes, as well as how
...@@ -79,13 +79,10 @@ class CC_EXPORT VideoResourceUpdater ...@@ -79,13 +79,10 @@ class CC_EXPORT VideoResourceUpdater
: public base::trace_event::MemoryDumpProvider { : public base::trace_event::MemoryDumpProvider {
public: public:
// For GPU compositing |context_provider| should be provided and for software // For GPU compositing |context_provider| should be provided and for software
// compositing |layer_tree_frame_sink| should be provided. If there is a // compositing |shared_bitmap_reporter| should be provided. If there is a
// non-null |context_provider| we assume GPU compositing. // non-null |context_provider| we assume GPU compositing.
// TODO(kylechar): Don't use LayerTreeFrameSink for the software compositing
// path. The UseSurfaceLayerForVideo path isn't compatible with this. We can
// maybe use mojom::CompositorFrameSink instead.
VideoResourceUpdater(viz::ContextProvider* context_provider, VideoResourceUpdater(viz::ContextProvider* context_provider,
LayerTreeFrameSink* layer_tree_frame_sink, viz::SharedBitmapReporter* shared_bitmap_reporter,
LayerTreeResourceProvider* resource_provider, LayerTreeResourceProvider* resource_provider,
bool use_stream_video_draw_quad, bool use_stream_video_draw_quad,
bool use_gpu_memory_buffer_resources, bool use_gpu_memory_buffer_resources,
...@@ -184,7 +181,7 @@ class CC_EXPORT VideoResourceUpdater ...@@ -184,7 +181,7 @@ class CC_EXPORT VideoResourceUpdater
base::trace_event::ProcessMemoryDump* pmd) override; base::trace_event::ProcessMemoryDump* pmd) override;
viz::ContextProvider* const context_provider_; viz::ContextProvider* const context_provider_;
LayerTreeFrameSink* const layer_tree_frame_sink_; viz::SharedBitmapReporter* const shared_bitmap_reporter_;
LayerTreeResourceProvider* const resource_provider_; LayerTreeResourceProvider* const resource_provider_;
const bool use_stream_video_draw_quad_; const bool use_stream_video_draw_quad_;
const bool use_gpu_memory_buffer_resources_; const bool use_gpu_memory_buffer_resources_;
......
...@@ -17,10 +17,9 @@ ...@@ -17,10 +17,9 @@
#include "components/viz/common/gpu/context_lost_observer.h" #include "components/viz/common/gpu/context_lost_observer.h"
#include "components/viz/common/gpu/context_provider.h" #include "components/viz/common/gpu/context_provider.h"
#include "components/viz/common/gpu/raster_context_provider.h" #include "components/viz/common/gpu/raster_context_provider.h"
#include "components/viz/common/quads/shared_bitmap.h"
#include "components/viz/common/resources/returned_resource.h" #include "components/viz/common/resources/returned_resource.h"
#include "components/viz/common/resources/shared_bitmap_reporter.h"
#include "gpu/command_buffer/common/texture_in_use_response.h" #include "gpu/command_buffer/common/texture_in_use_response.h"
#include "mojo/public/cpp/system/buffer.h"
#include "ui/gfx/color_space.h" #include "ui/gfx/color_space.h"
namespace gpu { namespace gpu {
...@@ -43,7 +42,8 @@ class LayerTreeHostImpl; ...@@ -43,7 +42,8 @@ class LayerTreeHostImpl;
// If a context_provider() is present, frames should be submitted with // If a context_provider() is present, frames should be submitted with
// OpenGL resources (created with the context_provider()). If not, then // OpenGL resources (created with the context_provider()). If not, then
// SharedMemory resources should be used. // SharedMemory resources should be used.
class CC_EXPORT LayerTreeFrameSink : public viz::ContextLostObserver { class CC_EXPORT LayerTreeFrameSink : public viz::SharedBitmapReporter,
public viz::ContextLostObserver {
public: public:
struct Capabilities { struct Capabilities {
Capabilities() = default; Capabilities() = default;
...@@ -133,13 +133,10 @@ class CC_EXPORT LayerTreeFrameSink : public viz::ContextLostObserver { ...@@ -133,13 +133,10 @@ class CC_EXPORT LayerTreeFrameSink : public viz::ContextLostObserver {
// the client did not lead to a CompositorFrame submission. // the client did not lead to a CompositorFrame submission.
virtual void DidNotProduceFrame(const viz::BeginFrameAck& ack) = 0; virtual void DidNotProduceFrame(const viz::BeginFrameAck& ack) = 0;
// Associates a SharedBitmapId with a shared buffer handle. // viz::SharedBitmapReporter implementation.
virtual void DidAllocateSharedBitmap(mojo::ScopedSharedBufferHandle buffer, void DidAllocateSharedBitmap(mojo::ScopedSharedBufferHandle buffer,
const viz::SharedBitmapId& id) = 0; const viz::SharedBitmapId& id) override = 0;
void DidDeleteSharedBitmap(const viz::SharedBitmapId& id) override = 0;
// Disassociates a SharedBitmapId previously passed to
// DidAllocateSharedBitmap.
virtual void DidDeleteSharedBitmap(const viz::SharedBitmapId& id) = 0;
protected: protected:
class ContextLostForwarder; class ContextLostForwarder;
......
...@@ -122,6 +122,8 @@ viz_component("common") { ...@@ -122,6 +122,8 @@ viz_component("common") {
"resources/resource_type.h", "resources/resource_type.h",
"resources/returned_resource.h", "resources/returned_resource.h",
"resources/shared_bitmap_manager.h", "resources/shared_bitmap_manager.h",
"resources/shared_bitmap_reporter.cc",
"resources/shared_bitmap_reporter.h",
"resources/single_release_callback.cc", "resources/single_release_callback.cc",
"resources/single_release_callback.h", "resources/single_release_callback.h",
"resources/transferable_resource.cc", "resources/transferable_resource.cc",
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/viz/common/resources/shared_bitmap_reporter.h"
namespace viz {
SharedBitmapReporter::~SharedBitmapReporter() = default;
} // namespace viz
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_VIZ_COMMON_RESOURCES_SHARED_BITMAP_REPORTER_H_
#define COMPONENTS_VIZ_COMMON_RESOURCES_SHARED_BITMAP_REPORTER_H_
#include "components/viz/common/quads/shared_bitmap.h"
#include "components/viz/common/viz_common_export.h"
#include "mojo/public/cpp/system/buffer.h"
namespace viz {
// Used by clients to notify the display compositor about SharedMemory allocated
// for shared bitmaps.
// TODO(kylechar): This should be //components/viz/client but because of deps
// issues that isn't possible. Fix and move there.
class VIZ_COMMON_EXPORT SharedBitmapReporter {
public:
// Associates a SharedBitmapId with a shared buffer handle.
virtual void DidAllocateSharedBitmap(mojo::ScopedSharedBufferHandle buffer,
const SharedBitmapId& id) = 0;
// Disassociates a SharedBitmapId previously passed to
// DidAllocateSharedBitmap.
virtual void DidDeleteSharedBitmap(const SharedBitmapId& id) = 0;
protected:
virtual ~SharedBitmapReporter();
};
} // namespace viz
#endif // COMPONENTS_VIZ_COMMON_RESOURCES_SHARED_BITMAP_REPORTER_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment