Move cc::VideoResourceUpdater to media.
This class is used by the media (and blink) code directly to produce
video resources for submission to the viz display compositor.
cc::VideoLayerImpl also uses it for this, but is deprecated and
eventually cc won't use this class at all. So we move it out of cc/ to
the media/ component.
Also satisfies a TODO and moves the SharedBitmapReporter from
viz/common/ to viz/client/ as it is a part of the client library,
and expand on the class comment to explain how to use it more.
[email protected]
TBR=kbr
Bug: 722935
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:win_optional_gpu_tests_rel;master.tryserver.blink:linux_trusty_blink_rel;master.tryserver.chromium.linux:linux_layout_tests_slimming_paint_v2
Change-Id: I5505b56c5fde79df0fe199dc14323fab07c3d292
Reviewed-on: https://chromium-review.googlesource.com/1073788
Commit-Queue: danakj <[email protected]>
Reviewed-by: Ken Rockot <[email protected]>
Reviewed-by: Jeremy Roman <[email protected]>
Reviewed-by: Dale Curtis <[email protected]>
Reviewed-by: Avi Drissman <[email protected]>
Cr-Commit-Position: refs/heads/master@{#562514}
diff --git a/cc/BUILD.gn b/cc/BUILD.gn
index f74b3c0..e5b7356 100644
--- a/cc/BUILD.gn
+++ b/cc/BUILD.gn
@@ -195,8 +195,6 @@
"resources/ui_resource_manager.h",
"resources/ui_resource_request.cc",
"resources/ui_resource_request.h",
- "resources/video_resource_updater.cc",
- "resources/video_resource_updater.h",
"scheduler/begin_frame_tracker.cc",
"scheduler/begin_frame_tracker.h",
"scheduler/commit_earlyout_reason.h",
@@ -372,10 +370,9 @@
"//gpu/ipc:gl_in_process_context",
"//gpu/skia_bindings:skia_bindings",
"//gpu/vulkan:buildflags",
- "//media",
+ "//media", # For VideoLayerImpl.
"//mojo/public/cpp/bindings:struct_traits",
"//services/metrics/public/cpp:ukm_builders",
- "//third_party/libyuv",
"//ui/events:events_base",
"//ui/gfx",
"//ui/gfx/geometry",
@@ -639,7 +636,6 @@
"raster/task_graph_work_queue_unittest.cc",
"raster/texture_compressor_etc1_unittest.cc",
"resources/resource_pool_unittest.cc",
- "resources/video_resource_updater_unittest.cc",
"scheduler/compositor_timing_history_unittest.cc",
"scheduler/scheduler_state_machine_unittest.cc",
"scheduler/scheduler_unittest.cc",
diff --git a/cc/layers/video_layer_impl.cc b/cc/layers/video_layer_impl.cc
index c4f013da..3e41407 100644
--- a/cc/layers/video_layer_impl.cc
+++ b/cc/layers/video_layer_impl.cc
@@ -20,6 +20,7 @@
#include "components/viz/common/quads/yuv_video_draw_quad.h"
#include "components/viz/common/resources/single_release_callback.h"
#include "media/base/video_frame.h"
+#include "media/renderers/video_resource_updater.h"
#include "ui/gfx/color_space.h"
namespace cc {
@@ -103,7 +104,7 @@
if (!updater_) {
const LayerTreeSettings& settings = layer_tree_impl()->settings();
- updater_ = std::make_unique<VideoResourceUpdater>(
+ updater_ = std::make_unique<media::VideoResourceUpdater>(
layer_tree_impl()->context_provider(),
layer_tree_impl()->layer_tree_frame_sink(),
layer_tree_impl()->resource_provider(),
diff --git a/cc/layers/video_layer_impl.h b/cc/layers/video_layer_impl.h
index b350a4f..4b3646b 100644
--- a/cc/layers/video_layer_impl.h
+++ b/cc/layers/video_layer_impl.h
@@ -10,12 +10,12 @@
#include "base/macros.h"
#include "cc/cc_export.h"
#include "cc/layers/layer_impl.h"
-#include "cc/resources/video_resource_updater.h"
#include "components/viz/common/resources/release_callback.h"
#include "media/base/video_rotation.h"
namespace media {
class VideoFrame;
+class VideoResourceUpdater;
}
namespace cc {
@@ -62,7 +62,7 @@
media::VideoRotation video_rotation_;
- std::unique_ptr<VideoResourceUpdater> updater_;
+ std::unique_ptr<media::VideoResourceUpdater> updater_;
DISALLOW_COPY_AND_ASSIGN(VideoLayerImpl);
};
diff --git a/cc/resources/video_resource_updater.cc b/cc/resources/video_resource_updater.cc
deleted file mode 100644
index ff48cb0..0000000
--- a/cc/resources/video_resource_updater.cc
+++ /dev/null
@@ -1,1155 +0,0 @@
-// Copyright 2013 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 "cc/resources/video_resource_updater.h"
-
-#include <stddef.h>
-#include <stdint.h>
-
-#include <algorithm>
-#include <string>
-
-#include "base/atomic_sequence_num.h"
-#include "base/bind.h"
-#include "base/bit_cast.h"
-#include "base/memory/shared_memory.h"
-#include "base/strings/stringprintf.h"
-#include "base/threading/thread_task_runner_handle.h"
-#include "base/trace_event/memory_dump_manager.h"
-#include "base/trace_event/process_memory_dump.h"
-#include "base/trace_event/trace_event.h"
-#include "cc/base/math_util.h"
-#include "cc/paint/skia_paint_canvas.h"
-#include "components/viz/client/client_resource_provider.h"
-#include "components/viz/common/gpu/context_provider.h"
-#include "components/viz/common/gpu/texture_allocation.h"
-#include "components/viz/common/quads/render_pass.h"
-#include "components/viz/common/quads/stream_video_draw_quad.h"
-#include "components/viz/common/quads/texture_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/resource_sizes.h"
-#include "components/viz/common/resources/shared_bitmap_reporter.h"
-#include "gpu/GLES2/gl2extchromium.h"
-#include "gpu/command_buffer/client/context_support.h"
-#include "gpu/command_buffer/client/gles2_interface.h"
-#include "media/base/video_frame.h"
-#include "media/renderers/paint_canvas_video_renderer.h"
-#include "media/video/half_float_maker.h"
-#include "third_party/khronos/GLES2/gl2.h"
-#include "third_party/khronos/GLES2/gl2ext.h"
-#include "third_party/libyuv/include/libyuv.h"
-#include "third_party/skia/include/core/SkCanvas.h"
-#include "ui/gfx/geometry/size_conversions.h"
-#include "ui/gfx/skia_util.h"
-#include "ui/gl/gl_enums.h"
-#include "ui/gl/trace_util.h"
-
-namespace cc {
-namespace {
-
-// Generates process-unique IDs to use for tracing video resources.
-base::AtomicSequenceNumber g_next_video_resource_updater_id;
-
-VideoFrameResourceType ExternalResourceTypeForHardwarePlanes(
- media::VideoPixelFormat format,
- GLuint target,
- int num_textures,
- gfx::BufferFormat* buffer_format,
- bool use_stream_video_draw_quad) {
- *buffer_format = gfx::BufferFormat::RGBA_8888;
- switch (format) {
- case media::PIXEL_FORMAT_ARGB:
- case media::PIXEL_FORMAT_XRGB:
- case media::PIXEL_FORMAT_RGB32:
- case media::PIXEL_FORMAT_UYVY:
- switch (target) {
- case GL_TEXTURE_EXTERNAL_OES:
- if (use_stream_video_draw_quad)
- return VideoFrameResourceType::STREAM_TEXTURE;
- FALLTHROUGH;
- case GL_TEXTURE_2D:
- return (format == media::PIXEL_FORMAT_XRGB)
- ? VideoFrameResourceType::RGB
- : VideoFrameResourceType::RGBA_PREMULTIPLIED;
- case GL_TEXTURE_RECTANGLE_ARB:
- return VideoFrameResourceType::RGB;
- default:
- NOTREACHED();
- break;
- }
- break;
- case media::PIXEL_FORMAT_I420:
- return VideoFrameResourceType::YUV;
- case media::PIXEL_FORMAT_NV12:
- DCHECK(target == GL_TEXTURE_EXTERNAL_OES || target == GL_TEXTURE_2D ||
- target == GL_TEXTURE_RECTANGLE_ARB)
- << "Unsupported target " << gl::GLEnums::GetStringEnum(target);
- // Single plane textures can be sampled as RGB.
- if (num_textures > 1)
- return VideoFrameResourceType::YUV;
-
- *buffer_format = gfx::BufferFormat::YUV_420_BIPLANAR;
- return VideoFrameResourceType::RGB;
- case media::PIXEL_FORMAT_YV12:
- case media::PIXEL_FORMAT_I422:
- case media::PIXEL_FORMAT_I444:
- case media::PIXEL_FORMAT_I420A:
- case media::PIXEL_FORMAT_NV21:
- case media::PIXEL_FORMAT_YUY2:
- case media::PIXEL_FORMAT_RGB24:
- case media::PIXEL_FORMAT_MJPEG:
- case media::PIXEL_FORMAT_MT21:
- case media::PIXEL_FORMAT_YUV420P9:
- case media::PIXEL_FORMAT_YUV422P9:
- case media::PIXEL_FORMAT_YUV444P9:
- case media::PIXEL_FORMAT_YUV420P10:
- case media::PIXEL_FORMAT_YUV422P10:
- case media::PIXEL_FORMAT_YUV444P10:
- case media::PIXEL_FORMAT_YUV420P12:
- case media::PIXEL_FORMAT_YUV422P12:
- case media::PIXEL_FORMAT_YUV444P12:
- case media::PIXEL_FORMAT_Y16:
- case media::PIXEL_FORMAT_UNKNOWN:
- break;
- }
- return VideoFrameResourceType::NONE;
-}
-
-class SyncTokenClientImpl : public media::VideoFrame::SyncTokenClient {
- public:
- SyncTokenClientImpl(gpu::gles2::GLES2Interface* gl, gpu::SyncToken sync_token)
- : gl_(gl), sync_token_(sync_token) {}
- ~SyncTokenClientImpl() override = default;
-
- void GenerateSyncToken(gpu::SyncToken* sync_token) override {
- if (sync_token_.HasData()) {
- *sync_token = sync_token_;
- } else {
- gl_->GenSyncTokenCHROMIUM(sync_token->GetData());
- }
- }
-
- void WaitSyncToken(const gpu::SyncToken& sync_token) override {
- if (sync_token.HasData()) {
- gl_->WaitSyncTokenCHROMIUM(sync_token.GetConstData());
- if (sync_token_.HasData() && sync_token_ != sync_token) {
- gl_->WaitSyncTokenCHROMIUM(sync_token_.GetConstData());
- sync_token_.Clear();
- }
- }
- }
-
- private:
- gpu::gles2::GLES2Interface* gl_;
- gpu::SyncToken sync_token_;
- DISALLOW_COPY_AND_ASSIGN(SyncTokenClientImpl);
-};
-
-// Sync tokens passed downstream to the compositor can be unverified.
-void GenerateCompositorSyncToken(gpu::gles2::GLES2Interface* gl,
- gpu::SyncToken* sync_token) {
- gl->GenUnverifiedSyncTokenCHROMIUM(sync_token->GetData());
-}
-
-// For frames that we receive in software format, determine the dimensions of
-// each plane in the frame.
-gfx::Size SoftwarePlaneDimension(media::VideoFrame* input_frame,
- bool software_compositor,
- size_t plane_index) {
- gfx::Size coded_size = input_frame->coded_size();
- if (software_compositor)
- return coded_size;
-
- int plane_width = media::VideoFrame::Columns(
- plane_index, input_frame->format(), coded_size.width());
- int plane_height = media::VideoFrame::Rows(plane_index, input_frame->format(),
- coded_size.height());
- return gfx::Size(plane_width, plane_height);
-}
-
-} // namespace
-
-VideoFrameExternalResources::VideoFrameExternalResources() = default;
-VideoFrameExternalResources::~VideoFrameExternalResources() = default;
-
-VideoFrameExternalResources::VideoFrameExternalResources(
- VideoFrameExternalResources&& other) = default;
-VideoFrameExternalResources& VideoFrameExternalResources::operator=(
- VideoFrameExternalResources&& other) = default;
-
-// Resource for a video plane allocated and owned by VideoResourceUpdater. There
-// can be multiple plane resources for each video frame, depending on the
-// format. These will be reused when possible.
-class VideoResourceUpdater::PlaneResource {
- public:
- PlaneResource(uint32_t plane_resource_id,
- const gfx::Size& resource_size,
- viz::ResourceFormat resource_format,
- bool is_software)
- : plane_resource_id_(plane_resource_id),
- resource_size_(resource_size),
- resource_format_(resource_format),
- is_software_(is_software) {}
- virtual ~PlaneResource() = default;
-
- // Casts |this| to SoftwarePlaneResource for software compositing.
- SoftwarePlaneResource* AsSoftware();
-
- // Casts |this| to HardwarePlaneResource for GPU compositing.
- HardwarePlaneResource* AsHardware();
-
- // Returns true if this resource matches the unique identifiers of another
- // VideoFrame resource.
- bool Matches(int unique_frame_id, size_t plane_index) {
- return has_unique_frame_id_and_plane_index_ &&
- unique_frame_id_ == unique_frame_id && plane_index_ == plane_index;
- }
-
- // Sets the unique identifiers for this resource, may only be called when
- // there is a single reference to the resource (i.e. |ref_count_| == 1).
- void SetUniqueId(int unique_frame_id, size_t plane_index) {
- DCHECK_EQ(ref_count_, 1);
- plane_index_ = plane_index;
- unique_frame_id_ = unique_frame_id;
- has_unique_frame_id_and_plane_index_ = true;
- }
-
- // Accessors for resource identifiers provided at construction time.
- uint32_t plane_resource_id() const { return plane_resource_id_; }
- const gfx::Size& resource_size() const { return resource_size_; }
- viz::ResourceFormat resource_format() const { return resource_format_; }
-
- // Various methods for managing references. See |ref_count_| for details.
- void add_ref() { ++ref_count_; }
- void remove_ref() { --ref_count_; }
- void clear_refs() { ref_count_ = 0; }
- bool has_refs() const { return ref_count_ != 0; }
-
- private:
- const uint32_t plane_resource_id_;
- const gfx::Size resource_size_;
- const viz::ResourceFormat resource_format_;
- const bool is_software_;
-
- // The number of times this resource has been imported vs number of times this
- // resource has returned.
- int ref_count_ = 0;
-
- // These two members are used for identifying the data stored in this
- // resource; they uniquely identify a media::VideoFrame plane.
- int unique_frame_id_ = 0;
- size_t plane_index_ = 0u;
- // Indicates if the above two members have been set or not.
- bool has_unique_frame_id_and_plane_index_ = false;
-
- DISALLOW_COPY_AND_ASSIGN(PlaneResource);
-};
-
-class VideoResourceUpdater::SoftwarePlaneResource
- : public VideoResourceUpdater::PlaneResource {
- public:
- SoftwarePlaneResource(uint32_t plane_resource_id,
- const gfx::Size& size,
- viz::SharedBitmapReporter* shared_bitmap_reporter)
- : PlaneResource(plane_resource_id,
- size,
- viz::ResourceFormat::RGBA_8888,
- /*is_software=*/true),
- shared_bitmap_reporter_(shared_bitmap_reporter),
- shared_bitmap_id_(viz::SharedBitmap::GenerateId()) {
- DCHECK(shared_bitmap_reporter_);
-
- // Allocate SharedMemory and notify display compositor of the allocation.
- shared_memory_ = viz::bitmap_allocation::AllocateMappedBitmap(
- resource_size(), viz::ResourceFormat::RGBA_8888);
- mojo::ScopedSharedBufferHandle handle =
- viz::bitmap_allocation::DuplicateAndCloseMappedBitmap(
- shared_memory_.get(), resource_size(),
- viz::ResourceFormat::RGBA_8888);
- shared_bitmap_reporter_->DidAllocateSharedBitmap(std::move(handle),
- shared_bitmap_id_);
- }
- ~SoftwarePlaneResource() override {
- shared_bitmap_reporter_->DidDeleteSharedBitmap(shared_bitmap_id_);
- }
-
- const viz::SharedBitmapId& shared_bitmap_id() const {
- return shared_bitmap_id_;
- }
- void* pixels() { return shared_memory_->memory(); }
-
- // Returns a memory dump GUID consistent across processes.
- base::UnguessableToken GetSharedMemoryGuid() const {
- return shared_memory_->mapped_id();
- }
-
- private:
- viz::SharedBitmapReporter* const shared_bitmap_reporter_;
- const viz::SharedBitmapId shared_bitmap_id_;
- std::unique_ptr<base::SharedMemory> shared_memory_;
-
- DISALLOW_COPY_AND_ASSIGN(SoftwarePlaneResource);
-};
-
-class VideoResourceUpdater::HardwarePlaneResource
- : public VideoResourceUpdater::PlaneResource {
- public:
- HardwarePlaneResource(uint32_t plane_resource_id,
- const gfx::Size& size,
- viz::ResourceFormat format,
- viz::ContextProvider* context_provider,
- viz::TextureAllocation allocation)
- : PlaneResource(plane_resource_id, size, format, /*is_software=*/false),
- context_provider_(context_provider),
- mailbox_(gpu::Mailbox::Generate()),
- allocation_(std::move(allocation)) {
- DCHECK(context_provider_);
- context_provider_->ContextGL()->ProduceTextureDirectCHROMIUM(
- allocation_.texture_id, mailbox_.name);
- }
- ~HardwarePlaneResource() override {
- context_provider_->ContextGL()->DeleteTextures(1, &allocation_.texture_id);
- }
-
- const gpu::Mailbox& mailbox() const { return mailbox_; }
- GLuint texture_id() const { return allocation_.texture_id; }
- GLenum texture_target() const { return allocation_.texture_target; }
- bool overlay_candidate() const { return allocation_.overlay_candidate; }
-
- private:
- viz::ContextProvider* const context_provider_;
- const gpu::Mailbox mailbox_;
- const viz::TextureAllocation allocation_;
-
- DISALLOW_COPY_AND_ASSIGN(HardwarePlaneResource);
-};
-
-VideoResourceUpdater::SoftwarePlaneResource*
-VideoResourceUpdater::PlaneResource::AsSoftware() {
- DCHECK(is_software_);
- return static_cast<SoftwarePlaneResource*>(this);
-}
-
-VideoResourceUpdater::HardwarePlaneResource*
-VideoResourceUpdater::PlaneResource::AsHardware() {
- DCHECK(!is_software_);
- return static_cast<HardwarePlaneResource*>(this);
-}
-
-VideoResourceUpdater::VideoResourceUpdater(
- viz::ContextProvider* context_provider,
- viz::SharedBitmapReporter* shared_bitmap_reporter,
- viz::ClientResourceProvider* resource_provider,
- bool use_stream_video_draw_quad,
- bool use_gpu_memory_buffer_resources,
- bool use_r16_texture,
- int max_resource_size)
- : context_provider_(context_provider),
- shared_bitmap_reporter_(shared_bitmap_reporter),
- resource_provider_(resource_provider),
- use_stream_video_draw_quad_(use_stream_video_draw_quad),
- use_gpu_memory_buffer_resources_(use_gpu_memory_buffer_resources),
- use_r16_texture_(use_r16_texture),
- max_resource_size_(max_resource_size),
- tracing_id_(g_next_video_resource_updater_id.GetNext()),
- weak_ptr_factory_(this) {
- DCHECK(context_provider_ || shared_bitmap_reporter_);
-
- base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(
- this, "cc::VideoResourceUpdater", base::ThreadTaskRunnerHandle::Get());
-}
-
-VideoResourceUpdater::~VideoResourceUpdater() {
- base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider(
- this);
-}
-
-void VideoResourceUpdater::ObtainFrameResources(
- scoped_refptr<media::VideoFrame> video_frame) {
- VideoFrameExternalResources external_resources =
- CreateExternalResourcesFromVideoFrame(video_frame);
- frame_resource_type_ = external_resources.type;
-
- if (external_resources.type == VideoFrameResourceType::YUV) {
- frame_resource_offset_ = external_resources.offset;
- frame_resource_multiplier_ = external_resources.multiplier;
- frame_bits_per_channel_ = external_resources.bits_per_channel;
- }
-
- DCHECK_EQ(external_resources.resources.size(),
- external_resources.release_callbacks.size());
- for (size_t i = 0; i < external_resources.resources.size(); ++i) {
- viz::ResourceId resource_id = resource_provider_->ImportResource(
- external_resources.resources[i],
- viz::SingleReleaseCallback::Create(
- std::move(external_resources.release_callbacks[i])));
- frame_resources_.push_back(
- {resource_id, external_resources.resources[i].size});
- }
- TRACE_EVENT_INSTANT1("media", "VideoResourceUpdater::ObtainFrameResources",
- TRACE_EVENT_SCOPE_THREAD, "Timestamp",
- video_frame->timestamp().InMicroseconds());
-}
-
-void VideoResourceUpdater::ReleaseFrameResources() {
- for (auto& frame_resource : frame_resources_)
- resource_provider_->RemoveImportedResource(frame_resource.id);
- frame_resources_.clear();
-}
-
-void VideoResourceUpdater::AppendQuads(viz::RenderPass* render_pass,
- scoped_refptr<media::VideoFrame> frame,
- gfx::Transform transform,
- gfx::Size rotated_size,
- gfx::Rect visible_layer_rect,
- gfx::Rect clip_rect,
- bool is_clipped,
- bool contents_opaque,
- float draw_opacity,
- int sorting_context_id,
- gfx::Rect visible_quad_rect) {
- DCHECK(frame.get());
-
- viz::SharedQuadState* shared_quad_state =
- render_pass->CreateAndAppendSharedQuadState();
- gfx::Rect rotated_size_rect(rotated_size);
- shared_quad_state->SetAll(
- transform, rotated_size_rect, visible_layer_rect, clip_rect, is_clipped,
- contents_opaque, draw_opacity, SkBlendMode::kSrcOver, sorting_context_id);
-
- gfx::Rect quad_rect(rotated_size);
- gfx::Rect visible_rect = frame->visible_rect();
- bool needs_blending = !contents_opaque;
- gfx::Size coded_size = frame->coded_size();
-
- const float tex_width_scale =
- static_cast<float>(visible_rect.width()) / coded_size.width();
- const float tex_height_scale =
- static_cast<float>(visible_rect.height()) / coded_size.height();
-
- switch (frame_resource_type_) {
- case VideoFrameResourceType::YUV: {
- const gfx::Size ya_tex_size = coded_size;
-
- int u_width = media::VideoFrame::Columns(
- media::VideoFrame::kUPlane, frame->format(), coded_size.width());
- int u_height = media::VideoFrame::Rows(
- media::VideoFrame::kUPlane, frame->format(), coded_size.height());
- gfx::Size uv_tex_size(u_width, u_height);
-
- if (frame->HasTextures()) {
- if (frame->format() == media::PIXEL_FORMAT_NV12) {
- DCHECK_EQ(2u, frame_resources_.size());
- } else {
- DCHECK_EQ(media::PIXEL_FORMAT_I420, frame->format());
- DCHECK_EQ(3u,
- frame_resources_.size()); // Alpha is not supported yet.
- }
- } else {
- DCHECK_GE(frame_resources_.size(), 3u);
- DCHECK(frame_resources_.size() <= 3 ||
- ya_tex_size == media::VideoFrame::PlaneSize(
- frame->format(), media::VideoFrame::kAPlane,
- coded_size));
- }
-
- // Compute the UV sub-sampling factor based on the ratio between
- // |ya_tex_size| and |uv_tex_size|.
- float uv_subsampling_factor_x =
- static_cast<float>(ya_tex_size.width()) / uv_tex_size.width();
- float uv_subsampling_factor_y =
- static_cast<float>(ya_tex_size.height()) / uv_tex_size.height();
- gfx::RectF ya_tex_coord_rect(visible_rect);
- gfx::RectF uv_tex_coord_rect(
- visible_rect.x() / uv_subsampling_factor_x,
- visible_rect.y() / uv_subsampling_factor_y,
- visible_rect.width() / uv_subsampling_factor_x,
- visible_rect.height() / uv_subsampling_factor_y);
-
- auto* yuv_video_quad =
- render_pass->CreateAndAppendDrawQuad<viz::YUVVideoDrawQuad>();
- yuv_video_quad->SetNew(
- shared_quad_state, quad_rect, visible_quad_rect, needs_blending,
- ya_tex_coord_rect, uv_tex_coord_rect, ya_tex_size, uv_tex_size,
- frame_resources_[0].id, frame_resources_[1].id,
- frame_resources_.size() > 2 ? frame_resources_[2].id
- : frame_resources_[1].id,
- frame_resources_.size() > 3 ? frame_resources_[3].id : 0,
- frame->ColorSpace(), frame_resource_offset_,
- frame_resource_multiplier_, frame_bits_per_channel_);
- yuv_video_quad->require_overlay =
- frame->metadata()->IsTrue(media::VideoFrameMetadata::REQUIRE_OVERLAY);
- yuv_video_quad->is_protected_video =
- frame->metadata()->IsTrue(media::VideoFrameMetadata::PROTECTED_VIDEO);
-
- for (viz::ResourceId resource_id : yuv_video_quad->resources) {
- resource_provider_->ValidateResource(resource_id);
- }
- break;
- }
- case VideoFrameResourceType::RGBA:
- case VideoFrameResourceType::RGBA_PREMULTIPLIED:
- case VideoFrameResourceType::RGB: {
- DCHECK_EQ(frame_resources_.size(), 1u);
- if (frame_resources_.size() < 1u)
- break;
- bool premultiplied_alpha =
- frame_resource_type_ == VideoFrameResourceType::RGBA_PREMULTIPLIED;
- gfx::PointF uv_top_left(0.f, 0.f);
- gfx::PointF uv_bottom_right(tex_width_scale, tex_height_scale);
- float opacity[] = {1.0f, 1.0f, 1.0f, 1.0f};
- bool flipped = false;
- bool nearest_neighbor = false;
- auto* texture_quad =
- render_pass->CreateAndAppendDrawQuad<viz::TextureDrawQuad>();
- texture_quad->SetNew(shared_quad_state, quad_rect, visible_quad_rect,
- needs_blending, frame_resources_[0].id,
- premultiplied_alpha, uv_top_left, uv_bottom_right,
- SK_ColorTRANSPARENT, opacity, flipped,
- nearest_neighbor, false);
- texture_quad->set_resource_size_in_pixels(coded_size);
- for (viz::ResourceId resource_id : texture_quad->resources) {
- resource_provider_->ValidateResource(resource_id);
- }
- break;
- }
- case VideoFrameResourceType::STREAM_TEXTURE: {
- DCHECK_EQ(frame_resources_.size(), 1u);
- if (frame_resources_.size() < 1u)
- break;
- gfx::Transform scale;
- scale.Scale(tex_width_scale, tex_height_scale);
- auto* stream_video_quad =
- render_pass->CreateAndAppendDrawQuad<viz::StreamVideoDrawQuad>();
- stream_video_quad->SetNew(shared_quad_state, quad_rect, visible_quad_rect,
- needs_blending, frame_resources_[0].id,
- frame_resources_[0].size_in_pixels, scale);
- for (viz::ResourceId resource_id : stream_video_quad->resources) {
- resource_provider_->ValidateResource(resource_id);
- }
- break;
- }
- case VideoFrameResourceType::NONE:
- NOTIMPLEMENTED();
- break;
- }
-}
-
-VideoFrameExternalResources
-VideoResourceUpdater::CreateExternalResourcesFromVideoFrame(
- scoped_refptr<media::VideoFrame> video_frame) {
- if (video_frame->format() == media::PIXEL_FORMAT_UNKNOWN)
- return VideoFrameExternalResources();
- DCHECK(video_frame->HasTextures() || video_frame->IsMappable());
- if (video_frame->HasTextures())
- return CreateForHardwarePlanes(std::move(video_frame));
- else
- return CreateForSoftwarePlanes(std::move(video_frame));
-}
-
-viz::ResourceFormat VideoResourceUpdater::YuvResourceFormat(
- int bits_per_channel) {
- DCHECK(context_provider_);
- const auto& caps = context_provider_->ContextCapabilities();
- if (caps.disable_one_component_textures)
- return viz::RGBA_8888;
- if (bits_per_channel <= 8)
- return caps.texture_rg ? viz::RED_8 : viz::LUMINANCE_8;
- if (use_r16_texture_ && caps.texture_norm16)
- return viz::R16_EXT;
- if (caps.texture_half_float_linear)
- return viz::LUMINANCE_F16;
- return viz::LUMINANCE_8;
-}
-
-VideoResourceUpdater::PlaneResource*
-VideoResourceUpdater::RecycleOrAllocateResource(
- const gfx::Size& resource_size,
- viz::ResourceFormat resource_format,
- const gfx::ColorSpace& color_space,
- int unique_id,
- int plane_index) {
- PlaneResource* recyclable_resource = nullptr;
- for (auto& resource : all_resources_) {
- // If the plane index is valid (positive, or 0, meaning all planes)
- // then we are allowed to return a referenced resource that already
- // contains the right frame data. It's safe to reuse it even if
- // resource_provider_ holds some references to it, because those
- // references are read-only.
- if (plane_index != -1 && resource->Matches(unique_id, plane_index)) {
- DCHECK(resource->resource_size() == resource_size);
- DCHECK(resource->resource_format() == resource_format);
- return resource.get();
- }
-
- // Otherwise check whether this is an unreferenced resource of the right
- // format that we can recycle. Remember it, but don't return immediately,
- // because we still want to find any reusable resources.
- const bool in_use = resource->has_refs();
-
- if (!in_use && resource->resource_size() == resource_size &&
- resource->resource_format() == resource_format) {
- recyclable_resource = resource.get();
- }
- }
-
- if (recyclable_resource)
- return recyclable_resource;
-
- // There was nothing available to reuse or recycle. Allocate a new resource.
- return AllocateResource(resource_size, resource_format, color_space);
-}
-
-VideoResourceUpdater::PlaneResource* VideoResourceUpdater::AllocateResource(
- const gfx::Size& plane_size,
- viz::ResourceFormat format,
- const gfx::ColorSpace& color_space) {
- const uint32_t plane_resource_id = next_plane_resource_id_++;
-
- if (software_compositor()) {
- DCHECK_EQ(format, viz::ResourceFormat::RGBA_8888);
-
- all_resources_.push_back(std::make_unique<SoftwarePlaneResource>(
- plane_resource_id, plane_size, shared_bitmap_reporter_));
- } else {
- // Video textures get composited into the display frame, the GPU doesn't
- // draw to them directly.
- constexpr bool kForFrameBufferAttachment = false;
-
- viz::TextureAllocation alloc = viz::TextureAllocation::MakeTextureId(
- context_provider_->ContextGL(),
- context_provider_->ContextCapabilities(), format,
- use_gpu_memory_buffer_resources_, kForFrameBufferAttachment);
- viz::TextureAllocation::AllocateStorage(
- context_provider_->ContextGL(),
- context_provider_->ContextCapabilities(), format, plane_size, alloc,
- color_space);
-
- all_resources_.push_back(std::make_unique<HardwarePlaneResource>(
- plane_resource_id, plane_size, format, context_provider_,
- std::move(alloc)));
- }
- return all_resources_.back().get();
-}
-
-void VideoResourceUpdater::CopyHardwarePlane(
- media::VideoFrame* video_frame,
- const gfx::ColorSpace& resource_color_space,
- const gpu::MailboxHolder& mailbox_holder,
- VideoFrameExternalResources* external_resources) {
- const gfx::Size output_plane_resource_size = video_frame->coded_size();
- // The copy needs to be a direct transfer of pixel data, so we use an RGBA8
- // target to avoid loss of precision or dropping any alpha component.
- constexpr viz::ResourceFormat copy_resource_format =
- viz::ResourceFormat::RGBA_8888;
-
- const int no_unique_id = 0;
- const int no_plane_index = -1; // Do not recycle referenced textures.
- PlaneResource* plane_resource = RecycleOrAllocateResource(
- output_plane_resource_size, copy_resource_format, resource_color_space,
- no_unique_id, no_plane_index);
- HardwarePlaneResource* hardware_resource = plane_resource->AsHardware();
- hardware_resource->add_ref();
-
- DCHECK_EQ(hardware_resource->texture_target(),
- static_cast<GLenum>(GL_TEXTURE_2D));
-
- gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL();
-
- gl->WaitSyncTokenCHROMIUM(mailbox_holder.sync_token.GetConstData());
- uint32_t src_texture_id =
- gl->CreateAndConsumeTextureCHROMIUM(mailbox_holder.mailbox.name);
- gl->CopySubTextureCHROMIUM(
- src_texture_id, 0, GL_TEXTURE_2D, hardware_resource->texture_id(), 0, 0,
- 0, 0, 0, output_plane_resource_size.width(),
- output_plane_resource_size.height(), false, false, false);
- gl->DeleteTextures(1, &src_texture_id);
-
- // Pass an empty sync token to force generation of a new sync token.
- SyncTokenClientImpl client(gl, gpu::SyncToken());
- gpu::SyncToken sync_token = video_frame->UpdateReleaseSyncToken(&client);
-
- auto transferable_resource = viz::TransferableResource::MakeGL(
- hardware_resource->mailbox(), GL_LINEAR, GL_TEXTURE_2D, sync_token);
- transferable_resource.color_space = resource_color_space;
- transferable_resource.format = copy_resource_format;
- transferable_resource.buffer_format = viz::BufferFormat(copy_resource_format);
- external_resources->resources.push_back(std::move(transferable_resource));
-
- external_resources->release_callbacks.push_back(base::BindOnce(
- &VideoResourceUpdater::RecycleResource, weak_ptr_factory_.GetWeakPtr(),
- hardware_resource->plane_resource_id()));
-}
-
-VideoFrameExternalResources VideoResourceUpdater::CreateForHardwarePlanes(
- scoped_refptr<media::VideoFrame> video_frame) {
- TRACE_EVENT0("cc", "VideoResourceUpdater::CreateForHardwarePlanes");
- DCHECK(video_frame->HasTextures());
- if (!context_provider_)
- return VideoFrameExternalResources();
-
- VideoFrameExternalResources external_resources;
- gfx::ColorSpace resource_color_space = video_frame->ColorSpace();
-
- bool copy_required =
- video_frame->metadata()->IsTrue(media::VideoFrameMetadata::COPY_REQUIRED);
-
- GLuint target = video_frame->mailbox_holder(0).texture_target;
- // If |copy_required| then we will copy into a GL_TEXTURE_2D target.
- if (copy_required)
- target = GL_TEXTURE_2D;
-
- gfx::BufferFormat buffer_format;
- external_resources.type = ExternalResourceTypeForHardwarePlanes(
- video_frame->format(), target, video_frame->NumTextures(), &buffer_format,
- use_stream_video_draw_quad_);
- if (external_resources.type == VideoFrameResourceType::NONE) {
- DLOG(ERROR) << "Unsupported Texture format"
- << media::VideoPixelFormatToString(video_frame->format());
- return external_resources;
- }
- if (external_resources.type == VideoFrameResourceType::RGB ||
- external_resources.type == VideoFrameResourceType::RGBA ||
- external_resources.type == VideoFrameResourceType::RGBA_PREMULTIPLIED) {
- resource_color_space = resource_color_space.GetAsFullRangeRGB();
- }
-
- const size_t num_textures = video_frame->NumTextures();
- for (size_t i = 0; i < num_textures; ++i) {
- const gpu::MailboxHolder& mailbox_holder = video_frame->mailbox_holder(i);
- if (mailbox_holder.mailbox.IsZero())
- break;
-
- if (copy_required) {
- CopyHardwarePlane(video_frame.get(), resource_color_space, mailbox_holder,
- &external_resources);
- } else {
- auto transfer_resource = viz::TransferableResource::MakeGLOverlay(
- mailbox_holder.mailbox, GL_LINEAR, mailbox_holder.texture_target,
- mailbox_holder.sync_token, video_frame->coded_size(),
- video_frame->metadata()->IsTrue(
- media::VideoFrameMetadata::ALLOW_OVERLAY));
- transfer_resource.color_space = resource_color_space;
- transfer_resource.read_lock_fences_enabled =
- video_frame->metadata()->IsTrue(
- media::VideoFrameMetadata::READ_LOCK_FENCES_ENABLED);
- transfer_resource.buffer_format = buffer_format;
-#if defined(OS_ANDROID)
- transfer_resource.is_backed_by_surface_texture =
- video_frame->metadata()->IsTrue(
- media::VideoFrameMetadata::TEXTURE_OWNER);
- transfer_resource.wants_promotion_hint = video_frame->metadata()->IsTrue(
- media::VideoFrameMetadata::WANTS_PROMOTION_HINT);
-#endif
- external_resources.resources.push_back(std::move(transfer_resource));
- external_resources.release_callbacks.push_back(
- base::BindOnce(&VideoResourceUpdater::ReturnTexture,
- weak_ptr_factory_.GetWeakPtr(), video_frame));
- }
- }
- return external_resources;
-}
-
-VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes(
- scoped_refptr<media::VideoFrame> video_frame) {
- TRACE_EVENT0("cc", "VideoResourceUpdater::CreateForSoftwarePlanes");
- const media::VideoPixelFormat input_frame_format = video_frame->format();
-
- size_t bits_per_channel = video_frame->BitDepth();
-
- // Only YUV and Y16 software video frames are supported.
- DCHECK(media::IsYuvPlanar(input_frame_format) ||
- input_frame_format == media::PIXEL_FORMAT_Y16);
-
- viz::ResourceFormat output_resource_format;
- gfx::ColorSpace output_color_space = video_frame->ColorSpace();
- if (input_frame_format == media::PIXEL_FORMAT_Y16) {
- // Unable to display directly as yuv planes so convert it to RGBA for
- // compositing.
- output_resource_format = viz::RGBA_8888;
- output_color_space = output_color_space.GetAsFullRangeRGB();
- } else if (!software_compositor()) {
- // Can be composited directly from yuv planes.
- output_resource_format = YuvResourceFormat(bits_per_channel);
- }
-
- // If GPU compositing is enabled, but the output resource format
- // returned by the resource provider is viz::RGBA_8888, then a GPU driver
- // bug workaround requires that YUV frames must be converted to RGB
- // before texture upload.
- bool texture_needs_rgb_conversion =
- !software_compositor() &&
- output_resource_format == viz::ResourceFormat::RGBA_8888;
-
- size_t output_plane_count = media::VideoFrame::NumPlanes(input_frame_format);
-
- // TODO(skaslev): If we're in software compositing mode, we do the YUV -> RGB
- // conversion here. That involves an extra copy of each frame to a bitmap.
- // Obviously, this is suboptimal and should be addressed once ubercompositor
- // starts shaping up.
- if (software_compositor() || texture_needs_rgb_conversion) {
- output_resource_format = viz::RGBA_8888;
- output_plane_count = 1;
- bits_per_channel = 8;
-
- // The YUV to RGB conversion will be performed when we convert
- // from single-channel textures to an RGBA texture via
- // ConvertVideoFrameToRGBPixels below.
- output_color_space = output_color_space.GetAsFullRangeRGB();
- }
-
- std::vector<gfx::Size> outplane_plane_sizes;
- outplane_plane_sizes.reserve(output_plane_count);
- for (size_t i = 0; i < output_plane_count; ++i) {
- outplane_plane_sizes.push_back(
- SoftwarePlaneDimension(video_frame.get(), software_compositor(), i));
- const gfx::Size& output_plane_resource_size = outplane_plane_sizes.back();
- if (output_plane_resource_size.IsEmpty() ||
- output_plane_resource_size.width() > max_resource_size_ ||
- output_plane_resource_size.height() > max_resource_size_) {
- // This output plane has invalid geometry so return an empty external
- // resources.
- return VideoFrameExternalResources();
- }
- }
-
- // Delete recycled resources that are the wrong format or wrong size.
- auto can_delete_resource_fn =
- [output_resource_format,
- &outplane_plane_sizes](const std::unique_ptr<PlaneResource>& resource) {
- // Resources that are still being used can't be deleted.
- if (resource->has_refs())
- return false;
-
- return resource->resource_format() != output_resource_format ||
- !base::ContainsValue(outplane_plane_sizes,
- resource->resource_size());
- };
- base::EraseIf(all_resources_, can_delete_resource_fn);
-
- // Recycle or allocate resources for each video plane.
- std::vector<PlaneResource*> plane_resources;
- plane_resources.reserve(output_plane_count);
- for (size_t i = 0; i < output_plane_count; ++i) {
- plane_resources.push_back(RecycleOrAllocateResource(
- outplane_plane_sizes[i], output_resource_format, output_color_space,
- video_frame->unique_id(), i));
- plane_resources.back()->add_ref();
- }
-
- VideoFrameExternalResources external_resources;
-
- external_resources.bits_per_channel = bits_per_channel;
-
- if (software_compositor() || texture_needs_rgb_conversion) {
- DCHECK_EQ(plane_resources.size(), 1u);
- PlaneResource* plane_resource = plane_resources[0];
- DCHECK_EQ(plane_resource->resource_format(), viz::RGBA_8888);
-
- if (!plane_resource->Matches(video_frame->unique_id(), 0)) {
- // We need to transfer data from |video_frame| to the plane resource.
- if (software_compositor()) {
- if (!video_renderer_)
- video_renderer_ = std::make_unique<media::PaintCanvasVideoRenderer>();
-
- SoftwarePlaneResource* software_resource = plane_resource->AsSoftware();
-
- // We know the format is RGBA_8888 from check above.
- SkImageInfo info = SkImageInfo::MakeN32Premul(
- gfx::SizeToSkISize(software_resource->resource_size()));
-
- SkBitmap sk_bitmap;
- sk_bitmap.installPixels(info, software_resource->pixels(),
- info.minRowBytes());
- SkiaPaintCanvas canvas(sk_bitmap);
-
- // This is software path, so canvas and video_frame are always backed
- // by software.
- video_renderer_->Copy(video_frame, &canvas, media::Context3D());
- } else {
- HardwarePlaneResource* hardware_resource = plane_resource->AsHardware();
- size_t bytes_per_row = viz::ResourceSizes::CheckedWidthInBytes<size_t>(
- video_frame->coded_size().width(), viz::ResourceFormat::RGBA_8888);
- size_t needed_size = bytes_per_row * video_frame->coded_size().height();
- if (upload_pixels_.size() < needed_size) {
- // Clear before resizing to avoid memcpy.
- upload_pixels_.clear();
- upload_pixels_.resize(needed_size);
- }
-
- media::PaintCanvasVideoRenderer::ConvertVideoFrameToRGBPixels(
- video_frame.get(), &upload_pixels_[0], bytes_per_row);
-
- // Copy pixels into texture.
- auto* gl = context_provider_->ContextGL();
- gl->BindTexture(hardware_resource->texture_target(),
- hardware_resource->texture_id());
- const gfx::Size& plane_size = hardware_resource->resource_size();
- gl->TexSubImage2D(
- hardware_resource->texture_target(), 0, 0, 0, plane_size.width(),
- plane_size.height(), GLDataFormat(viz::ResourceFormat::RGBA_8888),
- GLDataType(viz::ResourceFormat::RGBA_8888), &upload_pixels_[0]);
- }
- plane_resource->SetUniqueId(video_frame->unique_id(), 0);
- }
-
- viz::TransferableResource transferable_resource;
- if (software_compositor()) {
- SoftwarePlaneResource* software_resource = plane_resource->AsSoftware();
- external_resources.type = VideoFrameResourceType::RGBA_PREMULTIPLIED;
- transferable_resource = viz::TransferableResource::MakeSoftware(
- software_resource->shared_bitmap_id(),
- software_resource->resource_size(),
- plane_resource->resource_format());
- } else {
- HardwarePlaneResource* hardware_resource = plane_resource->AsHardware();
- external_resources.type = VideoFrameResourceType::RGBA;
- gpu::SyncToken sync_token;
- GenerateCompositorSyncToken(context_provider_->ContextGL(), &sync_token);
- transferable_resource = viz::TransferableResource::MakeGLOverlay(
- hardware_resource->mailbox(), GL_LINEAR,
- hardware_resource->texture_target(), sync_token,
- hardware_resource->resource_size(),
- hardware_resource->overlay_candidate());
- }
-
- transferable_resource.color_space = output_color_space;
- transferable_resource.format = viz::ResourceFormat::RGBA_8888;
- transferable_resource.buffer_format =
- viz::BufferFormat(viz::ResourceFormat::RGBA_8888);
- external_resources.resources.push_back(std::move(transferable_resource));
- external_resources.release_callbacks.push_back(base::BindOnce(
- &VideoResourceUpdater::RecycleResource, weak_ptr_factory_.GetWeakPtr(),
- plane_resource->plane_resource_id()));
-
- return external_resources;
- }
-
- const viz::ResourceFormat yuv_resource_format =
- YuvResourceFormat(bits_per_channel);
- DCHECK(yuv_resource_format == viz::LUMINANCE_F16 ||
- yuv_resource_format == viz::R16_EXT ||
- yuv_resource_format == viz::LUMINANCE_8 ||
- yuv_resource_format == viz::RED_8)
- << yuv_resource_format;
-
- std::unique_ptr<media::HalfFloatMaker> half_float_maker;
- if (yuv_resource_format == viz::LUMINANCE_F16) {
- half_float_maker =
- media::HalfFloatMaker::NewHalfFloatMaker(bits_per_channel);
- external_resources.offset = half_float_maker->Offset();
- external_resources.multiplier = half_float_maker->Multiplier();
- } else if (yuv_resource_format == viz::R16_EXT) {
- external_resources.multiplier = 65535.0f / ((1 << bits_per_channel) - 1);
- external_resources.offset = 0;
- }
-
- // We need to transfer data from |video_frame| to the plane resources.
- for (size_t i = 0; i < plane_resources.size(); ++i) {
- HardwarePlaneResource* plane_resource = plane_resources[i]->AsHardware();
-
- // Skip the transfer if this |video_frame|'s plane has been processed.
- if (plane_resource->Matches(video_frame->unique_id(), i))
- continue;
-
- const viz::ResourceFormat plane_resource_format =
- plane_resource->resource_format();
- DCHECK_EQ(plane_resource_format, yuv_resource_format);
-
- // TODO(hubbe): Move upload code to media/.
- // TODO(reveman): Can use GpuMemoryBuffers here to improve performance.
-
- // |video_stride_bytes| is the width of the |video_frame| we are uploading
- // (including non-frame data to fill in the stride).
- const int video_stride_bytes = video_frame->stride(i);
-
- // |resource_size_pixels| is the size of the destination resource.
- const gfx::Size resource_size_pixels = plane_resource->resource_size();
-
- const size_t bytes_per_row =
- viz::ResourceSizes::CheckedWidthInBytes<size_t>(
- resource_size_pixels.width(), plane_resource_format);
- // Use 4-byte row alignment (OpenGL default) for upload performance.
- // Assuming that GL_UNPACK_ALIGNMENT has not changed from default.
- const size_t upload_image_stride =
- MathUtil::CheckedRoundUp<size_t>(bytes_per_row, 4u);
-
- const size_t resource_bit_depth =
- static_cast<size_t>(viz::BitsPerPixel(plane_resource_format));
-
- // Data downshifting is needed if the resource bit depth is not enough.
- const bool needs_bit_downshifting = bits_per_channel > resource_bit_depth;
-
- // A copy to adjust strides is needed if those are different and both source
- // and destination have the same bit depth.
- const bool needs_stride_adaptation =
- (bits_per_channel == resource_bit_depth) &&
- (upload_image_stride != static_cast<size_t>(video_stride_bytes));
-
- // We need to convert the incoming data if we're transferring to half float,
- // if the need a bit downshift or if the strides need to be reconciled.
- const bool needs_conversion = plane_resource_format == viz::LUMINANCE_F16 ||
- needs_bit_downshifting ||
- needs_stride_adaptation;
-
- const uint8_t* pixels;
- if (!needs_conversion) {
- pixels = video_frame->data(i);
- } else {
- // Avoid malloc for each frame/plane if possible.
- const size_t needed_size =
- upload_image_stride * resource_size_pixels.height();
- if (upload_pixels_.size() < needed_size) {
- // Clear before resizing to avoid memcpy.
- upload_pixels_.clear();
- upload_pixels_.resize(needed_size);
- }
-
- if (plane_resource_format == viz::LUMINANCE_F16) {
- for (int row = 0; row < resource_size_pixels.height(); ++row) {
- uint16_t* dst = reinterpret_cast<uint16_t*>(
- &upload_pixels_[upload_image_stride * row]);
- const uint16_t* src = reinterpret_cast<uint16_t*>(
- video_frame->data(i) + (video_stride_bytes * row));
- half_float_maker->MakeHalfFloats(src, bytes_per_row / 2, dst);
- }
- } else if (needs_bit_downshifting) {
- DCHECK(plane_resource_format == viz::LUMINANCE_8 ||
- plane_resource_format == viz::RED_8);
- const int scale = 0x10000 >> (bits_per_channel - 8);
- libyuv::Convert16To8Plane(
- reinterpret_cast<uint16_t*>(video_frame->data(i)),
- video_stride_bytes / 2, upload_pixels_.data(), upload_image_stride,
- scale, bytes_per_row, resource_size_pixels.height());
- } else {
- // Make a copy to reconcile stride, size and format being equal.
- DCHECK(needs_stride_adaptation);
- DCHECK(plane_resource_format == viz::LUMINANCE_8 ||
- plane_resource_format == viz::RED_8);
- libyuv::CopyPlane(video_frame->data(i), video_stride_bytes,
- upload_pixels_.data(), upload_image_stride,
- resource_size_pixels.width(),
- resource_size_pixels.height());
- }
-
- pixels = &upload_pixels_[0];
- }
-
- // Copy pixels into texture. TexSubImage2D() is applicable because
- // |yuv_resource_format| is LUMINANCE_F16, R16_EXT, LUMINANCE_8 or RED_8.
- auto* gl = context_provider_->ContextGL();
- gl->BindTexture(plane_resource->texture_target(),
- plane_resource->texture_id());
- gl->TexSubImage2D(
- plane_resource->texture_target(), 0, 0, 0, resource_size_pixels.width(),
- resource_size_pixels.height(), GLDataFormat(plane_resource_format),
- GLDataType(plane_resource_format), pixels);
-
- plane_resource->SetUniqueId(video_frame->unique_id(), i);
- }
-
- // Set the sync token otherwise resource is assumed to be synchronized.
- gpu::SyncToken sync_token;
- GenerateCompositorSyncToken(context_provider_->ContextGL(), &sync_token);
-
- for (size_t i = 0; i < plane_resources.size(); ++i) {
- HardwarePlaneResource* plane_resource = plane_resources[i]->AsHardware();
- auto transferable_resource = viz::TransferableResource::MakeGLOverlay(
- plane_resource->mailbox(), GL_LINEAR, plane_resource->texture_target(),
- sync_token, plane_resource->resource_size(),
- plane_resource->overlay_candidate());
- transferable_resource.color_space = output_color_space;
- transferable_resource.format = output_resource_format;
- transferable_resource.buffer_format =
- viz::BufferFormat(output_resource_format);
- external_resources.resources.push_back(std::move(transferable_resource));
- external_resources.release_callbacks.push_back(base::BindOnce(
- &VideoResourceUpdater::RecycleResource, weak_ptr_factory_.GetWeakPtr(),
- plane_resource->plane_resource_id()));
- }
-
- external_resources.type = VideoFrameResourceType::YUV;
- return external_resources;
-}
-
-void VideoResourceUpdater::ReturnTexture(
- const scoped_refptr<media::VideoFrame>& video_frame,
- const gpu::SyncToken& sync_token,
- bool lost_resource) {
- // TODO(dshwang): Forward to the decoder as a lost resource.
- if (lost_resource)
- return;
-
- // The video frame will insert a wait on the previous release sync token.
- SyncTokenClientImpl client(context_provider_->ContextGL(), sync_token);
- video_frame->UpdateReleaseSyncToken(&client);
-}
-
-void VideoResourceUpdater::RecycleResource(uint32_t plane_resource_id,
- const gpu::SyncToken& sync_token,
- bool lost_resource) {
- auto matches_id_fn =
- [plane_resource_id](const std::unique_ptr<PlaneResource>& resource) {
- return resource->plane_resource_id() == plane_resource_id;
- };
- auto resource_it =
- std::find_if(all_resources_.begin(), all_resources_.end(), matches_id_fn);
- if (resource_it == all_resources_.end())
- return;
-
- if (context_provider_ && sync_token.HasData()) {
- context_provider_->ContextGL()->WaitSyncTokenCHROMIUM(
- sync_token.GetConstData());
- }
-
- if (lost_resource) {
- all_resources_.erase(resource_it);
- } else {
- (*resource_it)->remove_ref();
- }
-}
-
-bool VideoResourceUpdater::OnMemoryDump(
- const base::trace_event::MemoryDumpArgs& args,
- base::trace_event::ProcessMemoryDump* pmd) {
- for (auto& resource : all_resources_) {
- std::string dump_name =
- base::StringPrintf("cc/video_memory/updater_%d/resource_%d",
- tracing_id_, resource->plane_resource_id());
- base::trace_event::MemoryAllocatorDump* dump =
- pmd->CreateAllocatorDump(dump_name);
-
- const uint64_t total_bytes =
- viz::ResourceSizes::UncheckedSizeInBytesAligned<uint64_t>(
- resource->resource_size(), resource->resource_format());
- dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
- base::trace_event::MemoryAllocatorDump::kUnitsBytes,
- total_bytes);
-
- // The importance value assigned to the GUID here must be greater than the
- // importance value assigned elsewhere so that resource ownership is
- // attributed to VideoResourceUpdater.
- constexpr int kImportance = 2;
-
- // Resources are shared across processes and require a shared GUID to
- // prevent double counting the memory.
- if (software_compositor()) {
- base::UnguessableToken shm_guid =
- resource->AsSoftware()->GetSharedMemoryGuid();
- pmd->CreateSharedMemoryOwnershipEdge(dump->guid(), shm_guid, kImportance);
- } else {
- base::trace_event::MemoryAllocatorDumpGuid guid =
- gl::GetGLTextureClientGUIDForTracing(
- context_provider_->ContextSupport()->ShareGroupTracingGUID(),
- resource->AsHardware()->texture_id());
- pmd->CreateSharedGlobalAllocatorDump(guid);
- pmd->AddOwnershipEdge(dump->guid(), guid, kImportance);
- }
- }
-
- return true;
-}
-
-} // namespace cc
diff --git a/cc/resources/video_resource_updater.h b/cc/resources/video_resource_updater.h
deleted file mode 100644
index a7ee9074e..0000000
--- a/cc/resources/video_resource_updater.h
+++ /dev/null
@@ -1,220 +0,0 @@
-// Copyright 2013 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 CC_RESOURCES_VIDEO_RESOURCE_UPDATER_H_
-#define CC_RESOURCES_VIDEO_RESOURCE_UPDATER_H_
-
-#include <stddef.h>
-#include <stdint.h>
-
-#include <list>
-#include <memory>
-#include <vector>
-
-#include "base/macros.h"
-#include "base/memory/ref_counted.h"
-#include "base/memory/weak_ptr.h"
-#include "base/time/time.h"
-#include "base/trace_event/memory_dump_provider.h"
-#include "cc/cc_export.h"
-#include "components/viz/common/resources/release_callback.h"
-#include "components/viz/common/resources/resource_format.h"
-#include "components/viz/common/resources/resource_id.h"
-#include "components/viz/common/resources/transferable_resource.h"
-#include "ui/gfx/buffer_types.h"
-#include "ui/gfx/geometry/size.h"
-
-namespace media {
-class PaintCanvasVideoRenderer;
-class VideoFrame;
-}
-
-namespace gfx {
-class Rect;
-class Transform;
-} // namespace gfx
-
-namespace viz {
-class ClientResourceProvider;
-class ContextProvider;
-class RenderPass;
-class SharedBitmapReporter;
-}
-
-namespace cc {
-
-// Specifies what type of data is contained in the mailboxes, as well as how
-// many mailboxes will be present.
-enum class VideoFrameResourceType {
- NONE,
- YUV,
- RGB,
- RGBA_PREMULTIPLIED,
- RGBA,
- STREAM_TEXTURE,
-};
-
-class CC_EXPORT VideoFrameExternalResources {
- public:
- VideoFrameResourceType type = VideoFrameResourceType::NONE;
- std::vector<viz::TransferableResource> resources;
- std::vector<viz::ReleaseCallback> release_callbacks;
-
- // Used by hardware textures which do not return values in the 0-1 range.
- // After a lookup, subtract offset and multiply by multiplier.
- float offset = 0.f;
- float multiplier = 1.f;
- uint32_t bits_per_channel = 8;
-
- VideoFrameExternalResources();
- VideoFrameExternalResources(VideoFrameExternalResources&& other);
- VideoFrameExternalResources& operator=(VideoFrameExternalResources&& other);
- ~VideoFrameExternalResources();
-};
-
-// VideoResourceUpdater is used by the video system to produce frame content as
-// resources consumable by the compositor.
-class CC_EXPORT VideoResourceUpdater
- : public base::trace_event::MemoryDumpProvider {
- public:
- // For GPU compositing |context_provider| should be provided and for software
- // compositing |shared_bitmap_reporter| should be provided. If there is a
- // non-null |context_provider| we assume GPU compositing.
- VideoResourceUpdater(viz::ContextProvider* context_provider,
- viz::SharedBitmapReporter* shared_bitmap_reporter,
- viz::ClientResourceProvider* resource_provider,
- bool use_stream_video_draw_quad,
- bool use_gpu_memory_buffer_resources,
- bool use_r16_texture,
- int max_resource_size);
-
- ~VideoResourceUpdater() override;
-
- // For each CompositorFrame the following sequence is expected:
- // 1. ObtainFrameResources(): Import resources for the next video frame with
- // viz::ClientResourceProvider. This will reuse existing GPU or
- // SharedMemory buffers if possible, otherwise it will allocate new ones.
- // 2. AppendQuads(): Add DrawQuads to CompositorFrame for video.
- // 3. ReleaseFrameResources(): After the CompositorFrame has been submitted,
- // remove imported resources from viz::ClientResourceProvider.
- void ObtainFrameResources(scoped_refptr<media::VideoFrame> video_frame);
- void ReleaseFrameResources();
- void AppendQuads(viz::RenderPass* render_pass,
- scoped_refptr<media::VideoFrame> frame,
- gfx::Transform transform,
- gfx::Size rotated_size,
- gfx::Rect visible_layer_rect,
- gfx::Rect clip_rect,
- bool is_clipped,
- bool context_opaque,
- float draw_opacity,
- int sorting_context_id,
- gfx::Rect visible_quad_rect);
-
- // TODO(kylechar): This is only public for testing, make private.
- VideoFrameExternalResources CreateExternalResourcesFromVideoFrame(
- scoped_refptr<media::VideoFrame> video_frame);
-
- viz::ResourceFormat YuvResourceFormat(int bits_per_channel);
-
- private:
- class PlaneResource;
- class HardwarePlaneResource;
- class SoftwarePlaneResource;
-
- // A resource that will be embedded in a DrawQuad in the next CompositorFrame.
- // Each video plane will correspond to one FrameResource.
- struct FrameResource {
- viz::ResourceId id;
- gfx::Size size_in_pixels;
- };
-
- bool software_compositor() const { return context_provider_ == nullptr; }
-
- // Obtain a resource of the right format by either recycling an
- // unreferenced but appropriately formatted resource, or by
- // allocating a new resource.
- // Additionally, if the |unique_id| and |plane_index| match, then
- // it is assumed that the resource has the right data already and will only be
- // used for reading, and so is returned even if it is still referenced.
- // Passing -1 for |plane_index| avoids returning referenced
- // resources.
- PlaneResource* RecycleOrAllocateResource(const gfx::Size& resource_size,
- viz::ResourceFormat resource_format,
- const gfx::ColorSpace& color_space,
- int unique_id,
- int plane_index);
- PlaneResource* AllocateResource(const gfx::Size& plane_size,
- viz::ResourceFormat format,
- const gfx::ColorSpace& color_space);
-
- // Create a copy of a texture-backed source video frame in a new GL_TEXTURE_2D
- // texture. This is used when there are multiple GPU threads (Android WebView)
- // and the source video frame texture can't be used on the output GL context.
- // https://crbug.com/582170
- void CopyHardwarePlane(media::VideoFrame* video_frame,
- const gfx::ColorSpace& resource_color_space,
- const gpu::MailboxHolder& mailbox_holder,
- VideoFrameExternalResources* external_resources);
-
- // Get resources ready to be appended into DrawQuads. This is used for GPU
- // compositing most of the time, except for the cases mentioned in
- // CreateForSoftwarePlanes().
- VideoFrameExternalResources CreateForHardwarePlanes(
- scoped_refptr<media::VideoFrame> video_frame);
-
- // Get resources ready to be appended into DrawQuads. This is always used for
- // software compositing. This is also used for GPU compositing when the input
- // video frame has no textures.
- VideoFrameExternalResources CreateForSoftwarePlanes(
- scoped_refptr<media::VideoFrame> video_frame);
-
- void RecycleResource(uint32_t plane_resource_id,
- const gpu::SyncToken& sync_token,
- bool lost_resource);
- void ReturnTexture(const scoped_refptr<media::VideoFrame>& video_frame,
- const gpu::SyncToken& sync_token,
- bool lost_resource);
-
- // base::trace_event::MemoryDumpProvider implementation.
- bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args,
- base::trace_event::ProcessMemoryDump* pmd) override;
-
- viz::ContextProvider* const context_provider_;
- viz::SharedBitmapReporter* const shared_bitmap_reporter_;
- viz::ClientResourceProvider* const resource_provider_;
- const bool use_stream_video_draw_quad_;
- const bool use_gpu_memory_buffer_resources_;
- // TODO(crbug.com/759456): Remove after r16 is used without the flag.
- const bool use_r16_texture_;
- const int max_resource_size_;
- const int tracing_id_;
- std::unique_ptr<media::PaintCanvasVideoRenderer> video_renderer_;
- uint32_t next_plane_resource_id_ = 1;
-
- // Temporary pixel buffer when converting between formats.
- std::vector<uint8_t> upload_pixels_;
-
- VideoFrameResourceType frame_resource_type_;
-
- float frame_resource_offset_;
- float frame_resource_multiplier_;
- uint32_t frame_bits_per_channel_;
-
- // Resources that will be placed into quads by the next call to
- // AppendDrawQuads().
- std::vector<FrameResource> frame_resources_;
-
- // Resources allocated by VideoResourceUpdater. Used to recycle resources so
- // we can reduce the number of allocations and data transfers.
- std::vector<std::unique_ptr<PlaneResource>> all_resources_;
-
- base::WeakPtrFactory<VideoResourceUpdater> weak_ptr_factory_;
-
- DISALLOW_COPY_AND_ASSIGN(VideoResourceUpdater);
-};
-
-} // namespace cc
-
-#endif // CC_RESOURCES_VIDEO_RESOURCE_UPDATER_H_
diff --git a/cc/resources/video_resource_updater_unittest.cc b/cc/resources/video_resource_updater_unittest.cc
deleted file mode 100644
index 319d8a3..0000000
--- a/cc/resources/video_resource_updater_unittest.cc
+++ /dev/null
@@ -1,732 +0,0 @@
-// Copyright 2013 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 "cc/resources/video_resource_updater.h"
-
-#include <stddef.h>
-#include <stdint.h>
-
-#include "base/bind.h"
-#include "cc/test/fake_layer_tree_frame_sink.h"
-#include "cc/test/fake_output_surface_client.h"
-#include "cc/test/fake_resource_provider.h"
-#include "components/viz/client/client_resource_provider.h"
-#include "components/viz/test/fake_output_surface.h"
-#include "components/viz/test/test_gles2_interface.h"
-#include "gpu/GLES2/gl2extchromium.h"
-#include "media/base/video_frame.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace cc {
-namespace {
-
-class UploadCounterGLES2Interface : public viz::TestGLES2Interface {
- public:
- void TexSubImage2D(GLenum target,
- GLint level,
- GLint xoffset,
- GLint yoffset,
- GLsizei width,
- GLsizei height,
- GLenum format,
- GLenum type,
- const void* pixels) override {
- ++upload_count_;
- }
-
- void TexStorage2DEXT(GLenum target,
- GLint levels,
- GLuint internalformat,
- GLint width,
- GLint height) override {}
-
- void GenTextures(GLsizei n, GLuint* textures) override {
- created_texture_count_ += n;
- viz::TestGLES2Interface::GenTextures(n, textures);
- }
-
- void DeleteTextures(GLsizei n, const GLuint* textures) override {
- created_texture_count_ -= n;
- viz::TestGLES2Interface::DeleteTextures(n, textures);
- }
-
- int UploadCount() { return upload_count_; }
- void ResetUploadCount() { upload_count_ = 0; }
-
- int TextureCreationCount() { return created_texture_count_; }
- void ResetTextureCreationCount() { created_texture_count_ = 0; }
-
- private:
- int upload_count_;
- int created_texture_count_;
-};
-
-class VideoResourceUpdaterTest : public testing::Test {
- protected:
- VideoResourceUpdaterTest() {
- std::unique_ptr<UploadCounterGLES2Interface> gl(
- new UploadCounterGLES2Interface());
-
- gl_ = gl.get();
- gl_->set_support_texture_storage(true);
-
- context_provider_ = viz::TestContextProvider::Create(std::move(gl));
- context_provider_->BindToCurrentThread();
- }
-
- // testing::Test implementation.
- void SetUp() override {
- testing::Test::SetUp();
- layer_tree_frame_sink_software_ = FakeLayerTreeFrameSink::CreateSoftware();
- resource_provider3d_ = FakeResourceProvider::CreateClientResourceProvider(
- context_provider_.get());
- resource_provider_software_ =
- FakeResourceProvider::CreateClientResourceProvider(nullptr);
- }
-
- std::unique_ptr<VideoResourceUpdater> CreateUpdaterForHardware(
- bool use_stream_video_draw_quad = false) {
- return std::make_unique<VideoResourceUpdater>(
- context_provider_.get(), nullptr, resource_provider3d_.get(),
- use_stream_video_draw_quad, /*use_gpu_memory_buffer_resources=*/false,
- /*use_r16_texture=*/use_r16_texture_, /*max_resource_size=*/10000);
- }
-
- std::unique_ptr<VideoResourceUpdater> CreateUpdaterForSoftware() {
- return std::make_unique<VideoResourceUpdater>(
- nullptr, layer_tree_frame_sink_software_.get(),
- resource_provider_software_.get(),
- /*use_stream_video_draw_quad=*/false,
- /*use_gpu_memory_buffer_resources=*/false,
- /*use_r16_texture=*/false,
- /*max_resource_size=*/10000);
- }
-
- // Note that the number of pixels needed for |size| must be less than or equal
- // to the number of pixels needed for size of 100x100.
- scoped_refptr<media::VideoFrame> CreateTestYUVVideoFrame(
- const gfx::Size& size = gfx::Size(10, 10)) {
- constexpr int kMaxDimension = 100;
- static uint8_t y_data[kMaxDimension * kMaxDimension] = {0};
- static uint8_t u_data[kMaxDimension * kMaxDimension / 2] = {0};
- static uint8_t v_data[kMaxDimension * kMaxDimension / 2] = {0};
-
- CHECK_LE(size.width() * size.height(), kMaxDimension * kMaxDimension);
-
- scoped_refptr<media::VideoFrame> video_frame =
- media::VideoFrame::WrapExternalYuvData(
- media::PIXEL_FORMAT_I422, // format
- size, // coded_size
- gfx::Rect(size), // visible_rect
- size, // natural_size
- size.width(), // y_stride
- size.width() / 2, // u_stride
- size.width() / 2, // v_stride
- y_data, // y_data
- u_data, // u_data
- v_data, // v_data
- base::TimeDelta()); // timestamp
- EXPECT_TRUE(video_frame);
- return video_frame;
- }
-
- scoped_refptr<media::VideoFrame> CreateWonkyTestYUVVideoFrame() {
- const int kDimension = 10;
- const int kYWidth = kDimension + 5;
- const int kUWidth = (kYWidth + 1) / 2 + 200;
- const int kVWidth = (kYWidth + 1) / 2 + 1;
- static uint8_t y_data[kYWidth * kDimension] = {0};
- static uint8_t u_data[kUWidth * kDimension] = {0};
- static uint8_t v_data[kVWidth * kDimension] = {0};
-
- scoped_refptr<media::VideoFrame> video_frame =
- media::VideoFrame::WrapExternalYuvData(
- media::PIXEL_FORMAT_I422, // format
- gfx::Size(kYWidth, kDimension), // coded_size
- gfx::Rect(2, 0, kDimension, kDimension), // visible_rect
- gfx::Size(kDimension, kDimension), // natural_size
- -kYWidth, // y_stride (negative)
- kUWidth, // u_stride
- kVWidth, // v_stride
- y_data + kYWidth * (kDimension - 1), // y_data
- u_data, // u_data
- v_data, // v_data
- base::TimeDelta()); // timestamp
- EXPECT_TRUE(video_frame);
- return video_frame;
- }
-
- scoped_refptr<media::VideoFrame> CreateTestHighBitFrame() {
- const int kDimension = 10;
- gfx::Size size(kDimension, kDimension);
-
- scoped_refptr<media::VideoFrame> video_frame(media::VideoFrame::CreateFrame(
- media::PIXEL_FORMAT_YUV420P10, size, gfx::Rect(size), size,
- base::TimeDelta()));
- EXPECT_TRUE(video_frame);
- return video_frame;
- }
-
- void SetReleaseSyncToken(const gpu::SyncToken& sync_token) {
- release_sync_token_ = sync_token;
- }
-
- scoped_refptr<media::VideoFrame> CreateTestHardwareVideoFrame(
- media::VideoPixelFormat format,
- unsigned target) {
- const int kDimension = 10;
- gfx::Size size(kDimension, kDimension);
-
- gpu::Mailbox mailbox;
- mailbox.name[0] = 51;
-
- gpu::MailboxHolder mailbox_holders[media::VideoFrame::kMaxPlanes] = {
- gpu::MailboxHolder(mailbox, kMailboxSyncToken, target)};
- scoped_refptr<media::VideoFrame> video_frame =
- media::VideoFrame::WrapNativeTextures(
- format, mailbox_holders,
- base::Bind(&VideoResourceUpdaterTest::SetReleaseSyncToken,
- base::Unretained(this)),
- size, // coded_size
- gfx::Rect(size), // visible_rect
- size, // natural_size
- base::TimeDelta()); // timestamp
- EXPECT_TRUE(video_frame);
- return video_frame;
- }
-
- scoped_refptr<media::VideoFrame> CreateTestRGBAHardwareVideoFrame() {
- return CreateTestHardwareVideoFrame(media::PIXEL_FORMAT_ARGB,
- GL_TEXTURE_2D);
- }
-
- scoped_refptr<media::VideoFrame> CreateTestStreamTextureHardwareVideoFrame(
- bool needs_copy) {
- scoped_refptr<media::VideoFrame> video_frame = CreateTestHardwareVideoFrame(
- media::PIXEL_FORMAT_ARGB, GL_TEXTURE_EXTERNAL_OES);
- video_frame->metadata()->SetBoolean(
- media::VideoFrameMetadata::COPY_REQUIRED, needs_copy);
- return video_frame;
- }
-
- scoped_refptr<media::VideoFrame> CreateTestYuvHardwareVideoFrame(
- media::VideoPixelFormat format,
- size_t num_textures,
- unsigned target) {
- const int kDimension = 10;
- gfx::Size size(kDimension, kDimension);
-
- gpu::MailboxHolder mailbox_holders[media::VideoFrame::kMaxPlanes];
- for (size_t i = 0; i < num_textures; ++i) {
- gpu::Mailbox mailbox;
- mailbox.name[0] = 50 + 1;
- mailbox_holders[i] =
- gpu::MailboxHolder(mailbox, kMailboxSyncToken, target);
- }
- scoped_refptr<media::VideoFrame> video_frame =
- media::VideoFrame::WrapNativeTextures(
- format, mailbox_holders,
- base::Bind(&VideoResourceUpdaterTest::SetReleaseSyncToken,
- base::Unretained(this)),
- size, // coded_size
- gfx::Rect(size), // visible_rect
- size, // natural_size
- base::TimeDelta()); // timestamp
- EXPECT_TRUE(video_frame);
- return video_frame;
- }
-
- static const gpu::SyncToken kMailboxSyncToken;
-
- UploadCounterGLES2Interface* gl_;
- scoped_refptr<viz::TestContextProvider> context_provider_;
- std::unique_ptr<FakeLayerTreeFrameSink> layer_tree_frame_sink_software_;
- std::unique_ptr<viz::ClientResourceProvider> resource_provider3d_;
- std::unique_ptr<viz::ClientResourceProvider> resource_provider_software_;
- gpu::SyncToken release_sync_token_;
- bool use_r16_texture_ = false;
-};
-
-const gpu::SyncToken VideoResourceUpdaterTest::kMailboxSyncToken =
- gpu::SyncToken(gpu::CommandBufferNamespace::GPU_IO,
- gpu::CommandBufferId::FromUnsafeValue(0x123),
- 7);
-
-TEST_F(VideoResourceUpdaterTest, SoftwareFrame) {
- std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForHardware();
- scoped_refptr<media::VideoFrame> video_frame = CreateTestYUVVideoFrame();
-
- VideoFrameExternalResources resources =
- updater->CreateExternalResourcesFromVideoFrame(video_frame);
- EXPECT_EQ(VideoFrameResourceType::YUV, resources.type);
-}
-
-TEST_F(VideoResourceUpdaterTest, HighBitFrameNoF16) {
- std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForHardware();
- scoped_refptr<media::VideoFrame> video_frame = CreateTestHighBitFrame();
-
- VideoFrameExternalResources resources =
- updater->CreateExternalResourcesFromVideoFrame(video_frame);
- EXPECT_EQ(VideoFrameResourceType::YUV, resources.type);
-}
-
-class VideoResourceUpdaterTestWithF16 : public VideoResourceUpdaterTest {
- public:
- VideoResourceUpdaterTestWithF16() : VideoResourceUpdaterTest() {
- gl_->set_support_texture_half_float_linear(true);
- }
-};
-
-TEST_F(VideoResourceUpdaterTestWithF16, HighBitFrame) {
- std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForHardware();
- scoped_refptr<media::VideoFrame> video_frame = CreateTestHighBitFrame();
-
- VideoFrameExternalResources resources =
- updater->CreateExternalResourcesFromVideoFrame(video_frame);
- EXPECT_EQ(VideoFrameResourceType::YUV, resources.type);
- EXPECT_NEAR(resources.multiplier, 2.0, 0.1);
- EXPECT_NEAR(resources.offset, 0.5, 0.1);
-
- // Create the resource again, to test the path where the
- // resources are cached.
- VideoFrameExternalResources resources2 =
- updater->CreateExternalResourcesFromVideoFrame(video_frame);
- EXPECT_EQ(VideoFrameResourceType::YUV, resources2.type);
- EXPECT_NEAR(resources2.multiplier, 2.0, 0.1);
- EXPECT_NEAR(resources2.offset, 0.5, 0.1);
-}
-
-class VideoResourceUpdaterTestWithR16 : public VideoResourceUpdaterTest {
- public:
- VideoResourceUpdaterTestWithR16() : VideoResourceUpdaterTest() {
- use_r16_texture_ = true;
- gl_->set_support_texture_norm16(true);
- }
-};
-
-TEST_F(VideoResourceUpdaterTestWithR16, HighBitFrame) {
- std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForHardware();
- scoped_refptr<media::VideoFrame> video_frame = CreateTestHighBitFrame();
-
- VideoFrameExternalResources resources =
- updater->CreateExternalResourcesFromVideoFrame(video_frame);
- EXPECT_EQ(VideoFrameResourceType::YUV, resources.type);
-
- // Max 10-bit values as read by a sampler.
- double max_10bit_value = ((1 << 10) - 1) / 65535.0;
- EXPECT_NEAR(resources.multiplier * max_10bit_value, 1.0, 0.0001);
- EXPECT_NEAR(resources.offset, 0.0, 0.1);
-
- // Create the resource again, to test the path where the
- // resources are cached.
- VideoFrameExternalResources resources2 =
- updater->CreateExternalResourcesFromVideoFrame(video_frame);
- EXPECT_EQ(VideoFrameResourceType::YUV, resources2.type);
- EXPECT_NEAR(resources2.multiplier * max_10bit_value, 1.0, 0.0001);
- EXPECT_NEAR(resources2.offset, 0.0, 0.1);
-}
-
-TEST_F(VideoResourceUpdaterTest, HighBitFrameSoftwareCompositor) {
- std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForSoftware();
- scoped_refptr<media::VideoFrame> video_frame = CreateTestHighBitFrame();
-
- VideoFrameExternalResources resources =
- updater->CreateExternalResourcesFromVideoFrame(video_frame);
- EXPECT_EQ(VideoFrameResourceType::RGBA_PREMULTIPLIED, resources.type);
-}
-
-TEST_F(VideoResourceUpdaterTest, WonkySoftwareFrame) {
- std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForHardware();
- scoped_refptr<media::VideoFrame> video_frame = CreateWonkyTestYUVVideoFrame();
-
- VideoFrameExternalResources resources =
- updater->CreateExternalResourcesFromVideoFrame(video_frame);
- EXPECT_EQ(VideoFrameResourceType::YUV, resources.type);
-}
-
-TEST_F(VideoResourceUpdaterTest, WonkySoftwareFrameSoftwareCompositor) {
- std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForSoftware();
- scoped_refptr<media::VideoFrame> video_frame = CreateWonkyTestYUVVideoFrame();
-
- VideoFrameExternalResources resources =
- updater->CreateExternalResourcesFromVideoFrame(video_frame);
- EXPECT_EQ(VideoFrameResourceType::RGBA_PREMULTIPLIED, resources.type);
-}
-
-TEST_F(VideoResourceUpdaterTest, ReuseResource) {
- std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForHardware();
- scoped_refptr<media::VideoFrame> video_frame = CreateTestYUVVideoFrame();
- video_frame->set_timestamp(base::TimeDelta::FromSeconds(1234));
-
- // Allocate the resources for a YUV video frame.
- gl_->ResetUploadCount();
- VideoFrameExternalResources resources =
- updater->CreateExternalResourcesFromVideoFrame(video_frame);
- EXPECT_EQ(VideoFrameResourceType::YUV, resources.type);
- EXPECT_EQ(3u, resources.resources.size());
- EXPECT_EQ(3u, resources.release_callbacks.size());
- // Expect exactly three texture uploads, one for each plane.
- EXPECT_EQ(3, gl_->UploadCount());
-
- // Simulate the ResourceProvider releasing the resources back to the video
- // updater.
- for (auto& release_callback : resources.release_callbacks)
- std::move(release_callback).Run(gpu::SyncToken(), false);
-
- // Allocate resources for the same frame.
- gl_->ResetUploadCount();
- resources = updater->CreateExternalResourcesFromVideoFrame(video_frame);
- EXPECT_EQ(VideoFrameResourceType::YUV, resources.type);
- EXPECT_EQ(3u, resources.resources.size());
- EXPECT_EQ(3u, resources.release_callbacks.size());
- // The data should be reused so expect no texture uploads.
- EXPECT_EQ(0, gl_->UploadCount());
-}
-
-TEST_F(VideoResourceUpdaterTest, ReuseResourceNoDelete) {
- std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForHardware();
- scoped_refptr<media::VideoFrame> video_frame = CreateTestYUVVideoFrame();
- video_frame->set_timestamp(base::TimeDelta::FromSeconds(1234));
-
- // Allocate the resources for a YUV video frame.
- gl_->ResetUploadCount();
- VideoFrameExternalResources resources =
- updater->CreateExternalResourcesFromVideoFrame(video_frame);
- EXPECT_EQ(VideoFrameResourceType::YUV, resources.type);
- EXPECT_EQ(3u, resources.resources.size());
- EXPECT_EQ(3u, resources.release_callbacks.size());
- // Expect exactly three texture uploads, one for each plane.
- EXPECT_EQ(3, gl_->UploadCount());
-
- // Allocate resources for the same frame.
- gl_->ResetUploadCount();
- resources = updater->CreateExternalResourcesFromVideoFrame(video_frame);
- EXPECT_EQ(VideoFrameResourceType::YUV, resources.type);
- EXPECT_EQ(3u, resources.resources.size());
- EXPECT_EQ(3u, resources.release_callbacks.size());
- // The data should be reused so expect no texture uploads.
- EXPECT_EQ(0, gl_->UploadCount());
-}
-
-TEST_F(VideoResourceUpdaterTest, SoftwareFrameSoftwareCompositor) {
- std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForSoftware();
- scoped_refptr<media::VideoFrame> video_frame = CreateTestYUVVideoFrame();
-
- VideoFrameExternalResources resources =
- updater->CreateExternalResourcesFromVideoFrame(video_frame);
- EXPECT_EQ(VideoFrameResourceType::RGBA_PREMULTIPLIED, resources.type);
-}
-
-TEST_F(VideoResourceUpdaterTest, ReuseResourceSoftwareCompositor) {
- std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForSoftware();
- scoped_refptr<media::VideoFrame> video_frame = CreateTestYUVVideoFrame();
- video_frame->set_timestamp(base::TimeDelta::FromSeconds(1234));
-
- // Allocate the resources for a software video frame.
- VideoFrameExternalResources resources =
- updater->CreateExternalResourcesFromVideoFrame(video_frame);
- EXPECT_EQ(VideoFrameResourceType::RGBA_PREMULTIPLIED, resources.type);
- EXPECT_EQ(1u, resources.resources.size());
- EXPECT_EQ(1u, resources.release_callbacks.size());
- // Expect exactly one allocated shared bitmap.
- EXPECT_EQ(1u, layer_tree_frame_sink_software_->shared_bitmaps().size());
- auto shared_bitmaps = layer_tree_frame_sink_software_->shared_bitmaps();
-
- // Simulate the ResourceProvider releasing the resource back to the video
- // updater.
- std::move(resources.release_callbacks[0]).Run(gpu::SyncToken(), false);
-
- // Allocate resources for the same frame.
- resources = updater->CreateExternalResourcesFromVideoFrame(video_frame);
- EXPECT_EQ(VideoFrameResourceType::RGBA_PREMULTIPLIED, resources.type);
- EXPECT_EQ(1u, resources.resources.size());
- EXPECT_EQ(1u, resources.release_callbacks.size());
-
- // Ensure that the same shared bitmap was reused.
- EXPECT_EQ(layer_tree_frame_sink_software_->shared_bitmaps(), shared_bitmaps);
-}
-
-TEST_F(VideoResourceUpdaterTest, ReuseResourceNoDeleteSoftwareCompositor) {
- std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForSoftware();
- scoped_refptr<media::VideoFrame> video_frame = CreateTestYUVVideoFrame();
- video_frame->set_timestamp(base::TimeDelta::FromSeconds(1234));
-
- // Allocate the resources for a software video frame.
- VideoFrameExternalResources resources =
- updater->CreateExternalResourcesFromVideoFrame(video_frame);
- EXPECT_EQ(VideoFrameResourceType::RGBA_PREMULTIPLIED, resources.type);
- EXPECT_EQ(1u, resources.resources.size());
- EXPECT_EQ(1u, resources.release_callbacks.size());
- // Expect exactly one allocated shared bitmap.
- EXPECT_EQ(1u, layer_tree_frame_sink_software_->shared_bitmaps().size());
- auto shared_bitmaps = layer_tree_frame_sink_software_->shared_bitmaps();
-
- // Allocate resources for the same frame.
- resources = updater->CreateExternalResourcesFromVideoFrame(video_frame);
- EXPECT_EQ(VideoFrameResourceType::RGBA_PREMULTIPLIED, resources.type);
- EXPECT_EQ(1u, resources.resources.size());
- EXPECT_EQ(1u, resources.release_callbacks.size());
-
- // Ensure that the same shared bitmap was reused.
- EXPECT_EQ(layer_tree_frame_sink_software_->shared_bitmaps(), shared_bitmaps);
-}
-
-TEST_F(VideoResourceUpdaterTest, ChangeResourceSizeSoftwareCompositor) {
- constexpr gfx::Size kSize1(10, 10);
- constexpr gfx::Size kSize2(20, 20);
-
- std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForSoftware();
-
- // Allocate the resources for a software video frame.
- VideoFrameExternalResources resources =
- updater->CreateExternalResourcesFromVideoFrame(
- CreateTestYUVVideoFrame(kSize1));
- // Expect exactly one allocated shared bitmap.
- EXPECT_EQ(1u, layer_tree_frame_sink_software_->shared_bitmaps().size());
- auto shared_bitmaps = layer_tree_frame_sink_software_->shared_bitmaps();
-
- // Simulate the ResourceProvider releasing the resource back to the video
- // updater.
- std::move(resources.release_callbacks[0]).Run(gpu::SyncToken(), false);
-
- // Allocate resources for the next frame with a different size.
- resources = updater->CreateExternalResourcesFromVideoFrame(
- CreateTestYUVVideoFrame(kSize2));
-
- // The first resource was released, so it can be reused but it's the wrong
- // size. We should expect the first shared bitmap to be deleted and a new
- // shared bitmap to be allocated.
- EXPECT_EQ(1u, layer_tree_frame_sink_software_->shared_bitmaps().size());
- EXPECT_NE(layer_tree_frame_sink_software_->shared_bitmaps(), shared_bitmaps);
-}
-
-TEST_F(VideoResourceUpdaterTest, CreateForHardwarePlanes) {
- std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForHardware();
-
- scoped_refptr<media::VideoFrame> video_frame =
- CreateTestRGBAHardwareVideoFrame();
-
- VideoFrameExternalResources resources =
- updater->CreateExternalResourcesFromVideoFrame(video_frame);
- EXPECT_EQ(VideoFrameResourceType::RGBA_PREMULTIPLIED, resources.type);
- EXPECT_EQ(1u, resources.resources.size());
- EXPECT_EQ(1u, resources.release_callbacks.size());
-
- video_frame = CreateTestYuvHardwareVideoFrame(media::PIXEL_FORMAT_I420, 3,
- GL_TEXTURE_RECTANGLE_ARB);
-
- resources = updater->CreateExternalResourcesFromVideoFrame(video_frame);
- EXPECT_EQ(VideoFrameResourceType::YUV, resources.type);
- EXPECT_EQ(3u, resources.resources.size());
- EXPECT_EQ(3u, resources.release_callbacks.size());
- EXPECT_FALSE(resources.resources[0].read_lock_fences_enabled);
- EXPECT_FALSE(resources.resources[1].read_lock_fences_enabled);
- EXPECT_FALSE(resources.resources[2].read_lock_fences_enabled);
-
- video_frame = CreateTestYuvHardwareVideoFrame(media::PIXEL_FORMAT_I420, 3,
- GL_TEXTURE_RECTANGLE_ARB);
- video_frame->metadata()->SetBoolean(
- media::VideoFrameMetadata::READ_LOCK_FENCES_ENABLED, true);
-
- resources = updater->CreateExternalResourcesFromVideoFrame(video_frame);
- EXPECT_TRUE(resources.resources[0].read_lock_fences_enabled);
- EXPECT_TRUE(resources.resources[1].read_lock_fences_enabled);
- EXPECT_TRUE(resources.resources[2].read_lock_fences_enabled);
-}
-
-TEST_F(VideoResourceUpdaterTest, CreateForHardwarePlanes_StreamTexture) {
- // Note that |use_stream_video_draw_quad| is true for this test.
- std::unique_ptr<VideoResourceUpdater> updater =
- CreateUpdaterForHardware(true);
- gl_->ResetTextureCreationCount();
- scoped_refptr<media::VideoFrame> video_frame =
- CreateTestStreamTextureHardwareVideoFrame(false);
-
- VideoFrameExternalResources resources =
- updater->CreateExternalResourcesFromVideoFrame(video_frame);
- EXPECT_EQ(VideoFrameResourceType::STREAM_TEXTURE, resources.type);
- EXPECT_EQ(1u, resources.resources.size());
- EXPECT_EQ((GLenum)GL_TEXTURE_EXTERNAL_OES,
- resources.resources[0].mailbox_holder.texture_target);
- EXPECT_EQ(1u, resources.release_callbacks.size());
- EXPECT_EQ(0, gl_->TextureCreationCount());
-
- // A copied stream texture should return an RGBA resource in a new
- // GL_TEXTURE_2D texture.
- gl_->ResetTextureCreationCount();
- video_frame = CreateTestStreamTextureHardwareVideoFrame(true);
- resources = updater->CreateExternalResourcesFromVideoFrame(video_frame);
- EXPECT_EQ(VideoFrameResourceType::RGBA_PREMULTIPLIED, resources.type);
- EXPECT_EQ(1u, resources.resources.size());
- EXPECT_EQ((GLenum)GL_TEXTURE_2D,
- resources.resources[0].mailbox_holder.texture_target);
- EXPECT_EQ(1u, resources.release_callbacks.size());
- EXPECT_EQ(1, gl_->TextureCreationCount());
-}
-
-TEST_F(VideoResourceUpdaterTest, CreateForHardwarePlanes_TextureQuad) {
- std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForHardware();
- gl_->ResetTextureCreationCount();
- scoped_refptr<media::VideoFrame> video_frame =
- CreateTestStreamTextureHardwareVideoFrame(false);
-
- VideoFrameExternalResources resources =
- updater->CreateExternalResourcesFromVideoFrame(video_frame);
- EXPECT_EQ(VideoFrameResourceType::RGBA_PREMULTIPLIED, resources.type);
- EXPECT_EQ(1u, resources.resources.size());
- EXPECT_EQ((GLenum)GL_TEXTURE_EXTERNAL_OES,
- resources.resources[0].mailbox_holder.texture_target);
- EXPECT_EQ(1u, resources.release_callbacks.size());
- EXPECT_EQ(0, gl_->TextureCreationCount());
-}
-
-// Passthrough the sync token returned by the compositor if we don't have an
-// existing release sync token.
-TEST_F(VideoResourceUpdaterTest, PassReleaseSyncToken) {
- std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForHardware();
-
- const gpu::SyncToken sync_token(gpu::CommandBufferNamespace::GPU_IO,
- gpu::CommandBufferId::FromUnsafeValue(0x123),
- 123);
-
- {
- scoped_refptr<media::VideoFrame> video_frame =
- CreateTestRGBAHardwareVideoFrame();
-
- VideoFrameExternalResources resources =
- updater->CreateExternalResourcesFromVideoFrame(video_frame);
-
- ASSERT_EQ(resources.release_callbacks.size(), 1u);
- std::move(resources.release_callbacks[0]).Run(sync_token, false);
- }
-
- EXPECT_EQ(release_sync_token_, sync_token);
-}
-
-// Generate new sync token because video frame has an existing sync token.
-TEST_F(VideoResourceUpdaterTest, GenerateReleaseSyncToken) {
- std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForHardware();
-
- const gpu::SyncToken sync_token1(gpu::CommandBufferNamespace::GPU_IO,
- gpu::CommandBufferId::FromUnsafeValue(0x123),
- 123);
-
- const gpu::SyncToken sync_token2(gpu::CommandBufferNamespace::GPU_IO,
- gpu::CommandBufferId::FromUnsafeValue(0x234),
- 234);
-
- {
- scoped_refptr<media::VideoFrame> video_frame =
- CreateTestRGBAHardwareVideoFrame();
-
- VideoFrameExternalResources resources1 =
- updater->CreateExternalResourcesFromVideoFrame(video_frame);
- ASSERT_EQ(resources1.release_callbacks.size(), 1u);
- std::move(resources1.release_callbacks[0]).Run(sync_token1, false);
-
- VideoFrameExternalResources resources2 =
- updater->CreateExternalResourcesFromVideoFrame(video_frame);
- ASSERT_EQ(resources2.release_callbacks.size(), 1u);
- std::move(resources2.release_callbacks[0]).Run(sync_token2, false);
- }
-
- EXPECT_TRUE(release_sync_token_.HasData());
- EXPECT_NE(release_sync_token_, sync_token1);
- EXPECT_NE(release_sync_token_, sync_token2);
-}
-
-// Pass mailbox sync token as is if no GL operations are performed before frame
-// resources are handed off to the compositor.
-TEST_F(VideoResourceUpdaterTest, PassMailboxSyncToken) {
- std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForHardware();
-
- scoped_refptr<media::VideoFrame> video_frame =
- CreateTestRGBAHardwareVideoFrame();
-
- VideoFrameExternalResources resources =
- updater->CreateExternalResourcesFromVideoFrame(video_frame);
-
- ASSERT_EQ(resources.resources.size(), 1u);
- EXPECT_TRUE(resources.resources[0].mailbox_holder.sync_token.HasData());
- EXPECT_EQ(resources.resources[0].mailbox_holder.sync_token,
- kMailboxSyncToken);
-}
-
-// Generate new sync token for compositor when copying the texture.
-TEST_F(VideoResourceUpdaterTest, GenerateSyncTokenOnTextureCopy) {
- std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForHardware();
-
- scoped_refptr<media::VideoFrame> video_frame =
- CreateTestStreamTextureHardwareVideoFrame(true /* needs_copy */);
-
- VideoFrameExternalResources resources =
- updater->CreateExternalResourcesFromVideoFrame(video_frame);
-
- ASSERT_EQ(resources.resources.size(), 1u);
- EXPECT_TRUE(resources.resources[0].mailbox_holder.sync_token.HasData());
- EXPECT_NE(resources.resources[0].mailbox_holder.sync_token,
- kMailboxSyncToken);
-}
-
-// NV12 VideoFrames backed by a single native texture can be sampled out
-// by GL as RGB. To use them as HW overlays we need to know the format
-// of the underlying buffer, that is YUV_420_BIPLANAR.
-TEST_F(VideoResourceUpdaterTest, CreateForHardwarePlanes_SingleNV12) {
- std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForHardware();
- gl_->ResetTextureCreationCount();
- scoped_refptr<media::VideoFrame> video_frame = CreateTestHardwareVideoFrame(
- media::PIXEL_FORMAT_NV12, GL_TEXTURE_EXTERNAL_OES);
-
- VideoFrameExternalResources resources =
- updater->CreateExternalResourcesFromVideoFrame(video_frame);
- EXPECT_EQ(VideoFrameResourceType::RGB, resources.type);
- EXPECT_EQ(1u, resources.resources.size());
- EXPECT_EQ((GLenum)GL_TEXTURE_EXTERNAL_OES,
- resources.resources[0].mailbox_holder.texture_target);
- EXPECT_EQ(gfx::BufferFormat::YUV_420_BIPLANAR,
- resources.resources[0].buffer_format);
-
- video_frame = CreateTestYuvHardwareVideoFrame(media::PIXEL_FORMAT_NV12, 1,
- GL_TEXTURE_RECTANGLE_ARB);
- resources = updater->CreateExternalResourcesFromVideoFrame(video_frame);
- EXPECT_EQ(VideoFrameResourceType::RGB, resources.type);
- EXPECT_EQ(1u, resources.resources.size());
- EXPECT_EQ((GLenum)GL_TEXTURE_RECTANGLE_ARB,
- resources.resources[0].mailbox_holder.texture_target);
- EXPECT_EQ(gfx::BufferFormat::YUV_420_BIPLANAR,
- resources.resources[0].buffer_format);
-
- EXPECT_EQ(0, gl_->TextureCreationCount());
-}
-
-TEST_F(VideoResourceUpdaterTest, CreateForHardwarePlanes_DualNV12) {
- std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForHardware();
- gl_->ResetTextureCreationCount();
- scoped_refptr<media::VideoFrame> video_frame =
- CreateTestYuvHardwareVideoFrame(media::PIXEL_FORMAT_NV12, 2,
- GL_TEXTURE_EXTERNAL_OES);
-
- VideoFrameExternalResources resources =
- updater->CreateExternalResourcesFromVideoFrame(video_frame);
- EXPECT_EQ(VideoFrameResourceType::YUV, resources.type);
- EXPECT_EQ(2u, resources.resources.size());
- EXPECT_EQ(2u, resources.release_callbacks.size());
- EXPECT_EQ((GLenum)GL_TEXTURE_EXTERNAL_OES,
- resources.resources[0].mailbox_holder.texture_target);
- // |updater| doesn't set |buffer_format| in this case.
- EXPECT_EQ(gfx::BufferFormat::RGBA_8888, resources.resources[0].buffer_format);
-
- video_frame = CreateTestYuvHardwareVideoFrame(media::PIXEL_FORMAT_NV12, 2,
- GL_TEXTURE_RECTANGLE_ARB);
- resources = updater->CreateExternalResourcesFromVideoFrame(video_frame);
- EXPECT_EQ(VideoFrameResourceType::YUV, resources.type);
- EXPECT_EQ(2u, resources.resources.size());
- EXPECT_EQ((GLenum)GL_TEXTURE_RECTANGLE_ARB,
- resources.resources[0].mailbox_holder.texture_target);
- EXPECT_EQ(gfx::BufferFormat::RGBA_8888, resources.resources[0].buffer_format);
- EXPECT_EQ(0, gl_->TextureCreationCount());
-}
-
-} // namespace
-} // namespace cc
diff --git a/cc/trees/layer_tree_frame_sink.h b/cc/trees/layer_tree_frame_sink.h
index 7f550dc..0a6c126 100644
--- a/cc/trees/layer_tree_frame_sink.h
+++ b/cc/trees/layer_tree_frame_sink.h
@@ -14,11 +14,11 @@
#include "base/single_thread_task_runner.h"
#include "base/threading/thread_checker.h"
#include "cc/cc_export.h"
+#include "components/viz/client/shared_bitmap_reporter.h"
#include "components/viz/common/gpu/context_lost_observer.h"
#include "components/viz/common/gpu/context_provider.h"
#include "components/viz/common/gpu/raster_context_provider.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 "ui/gfx/color_space.h"