0

[Dr-Dc] Direct Rendering Display Compositor gpu thread.

1. Add support for a new gpu thread to be used by display compositor.
This new gpu thread is known as dr-dc aka direct rendering display
compositor. A new shared context will be current on this thread.

2. Add finch feature flags to enable it only on android P devices via
finch rollout. It will be currently disabled for all other platforms
and is currently disabled by default on android P also.

3. Viz changes to use this new thread when enabled.

Bug: 1186275
Change-Id: I10f72e331f9273b35e90372c291de1c41a906e28
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2901026
Reviewed-by: Bo <boliu@chromium.org>
Reviewed-by: kylechar <kylechar@chromium.org>
Reviewed-by: Vasiliy Telezhnikov <vasilyt@chromium.org>
Reviewed-by: Sunny Sachanandani <sunnyps@chromium.org>
Commit-Queue: vikas soni <vikassoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#892199}
This commit is contained in:
Vikas Soni
2021-06-14 19:02:19 +00:00
committed by Chromium LUCI CQ
parent b057bddfbc
commit 532d738362
25 changed files with 376 additions and 51 deletions

@ -268,6 +268,9 @@ bool AwMainDelegate::BasicStartupComplete(int* exit_code) {
// Disabled until viz scheduling can be improved.
features.DisableIfNotSet(::features::kUseSurfaceLayerForVideoDefault);
// Disable dr-dc on webview.
features.DisableIfNotSet(::features::kEnableDrDc);
}
android_webview::RegisterPathProvider();

@ -7,10 +7,13 @@
#include <stdint.h>
#include <memory>
#include <utility>
#include "base/check_op.h"
#include "base/notreached.h"
#include "base/numerics/checked_math.h"
#include "build/build_config.h"
#include "gpu/config/gpu_finch_features.h"
#include "third_party/skia/include/core/SkImage.h"
#include "third_party/skia/include/core/SkImageInfo.h"
#include "third_party/skia/include/core/SkMallocPixelRef.h"
@ -71,9 +74,29 @@ size_t UIResourceBitmap::SizeInBytes() const {
UIResourceBitmap::UIResourceBitmap(const SkBitmap& skbitmap) {
DCHECK(skbitmap.isImmutable());
sk_sp<SkPixelRef> pixel_ref = sk_ref_sp(skbitmap.pixelRef());
Create(std::move(pixel_ref), skbitmap.info(),
SkColorTypeToUIResourceFormat(skbitmap.colorType()));
const SkBitmap* target = &skbitmap;
if (features::IsDrDcEnabled()) {
#if defined(OS_ANDROID)
// TODO(vikassoni): Forcing everything to N32 while android backing cannot
// support some other formats.
SkBitmap copy;
if (skbitmap.colorType() != kN32_SkColorType) {
SkImageInfo new_info = skbitmap.info().makeColorType(kN32_SkColorType);
copy.allocPixels(new_info, new_info.minRowBytes());
SkCanvas copy_canvas(copy);
copy_canvas.drawImage(skbitmap.asImage(), 0, 0, SkSamplingOptions(),
nullptr);
copy.setImmutable();
target = &copy;
}
DCHECK_EQ(target->width(), target->rowBytesAsPixels());
DCHECK(target->isImmutable());
#endif
}
sk_sp<SkPixelRef> pixel_ref = sk_ref_sp(target->pixelRef());
Create(std::move(pixel_ref), target->info(),
SkColorTypeToUIResourceFormat(target->colorType()));
}
UIResourceBitmap::UIResourceBitmap(const gfx::Size& size, bool is_opaque) {

@ -132,7 +132,6 @@ std::unique_ptr<viz::DisplayCompositorMemoryAndTaskController>
LayerTreePixelTest::CreateDisplayControllerOnThread() {
auto skia_deps = std::make_unique<viz::SkiaOutputSurfaceDependencyImpl>(
viz::TestGpuServiceHolder::GetInstance()->gpu_service(),
viz::TestGpuServiceHolder::GetInstance()->task_executor(),
gpu::kNullSurfaceHandle);
return std::make_unique<viz::DisplayCompositorMemoryAndTaskController>(
std::move(skia_deps));

@ -296,7 +296,7 @@ void PixelTest::SetUpSkiaRenderer(gfx::SurfaceOrigin output_surface_origin) {
gpu_service_holder_ = viz::TestGpuServiceHolder::GetInstance();
auto skia_deps = std::make_unique<viz::SkiaOutputSurfaceDependencyImpl>(
gpu_service(), task_executor(), gpu::kNullSurfaceHandle);
gpu_service(), gpu::kNullSurfaceHandle);
display_controller_ =
std::make_unique<viz::DisplayCompositorMemoryAndTaskController>(
std::move(skia_deps));

@ -124,6 +124,8 @@ viz_component("service") {
"display/texture_deleter.h",
"display_embedder/buffer_queue.cc",
"display_embedder/buffer_queue.h",
"display_embedder/compositor_gpu_thread.cc",
"display_embedder/compositor_gpu_thread.h",
"display_embedder/gl_output_surface.cc",
"display_embedder/gl_output_surface.h",
"display_embedder/gl_output_surface_buffer_queue.cc",

@ -9,6 +9,7 @@ include_rules = [
"+components/viz/service/debugger/viz_debugger.h",
"+components/viz/service/gl/gpu_service_impl.h",
"+components/viz/service/viz_service_export.h",
"+components/viz/service/display_embedder/compositor_gpu_thread.h",
"+gpu/config/gpu_feature_info.h",
"+gpu/ipc/common/surface_handle.h",
"+services/viz/privileged/mojom",

@ -259,7 +259,6 @@ class RendererPerfTest : public VizPerfTest {
#endif
auto* gpu_service = TestGpuServiceHolder::GetInstance()->gpu_service();
auto* task_executor = TestGpuServiceHolder::GetInstance()->task_executor();
gpu_memory_buffer_manager_ =
std::make_unique<InProcessGpuMemoryBufferManager>(
@ -286,7 +285,7 @@ class RendererPerfTest : public VizPerfTest {
display_controller;
if (renderer_settings_.use_skia_renderer) {
auto skia_deps = std::make_unique<SkiaOutputSurfaceDependencyImpl>(
gpu_service, task_executor, gpu::kNullSurfaceHandle);
gpu_service, gpu::kNullSurfaceHandle);
display_controller =
std::make_unique<DisplayCompositorMemoryAndTaskController>(
std::move(skia_deps));

@ -0,0 +1,148 @@
// Copyright 2021 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/service/display_embedder/compositor_gpu_thread.h"
#include <utility>
#include "base/bind_post_task.h"
#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/synchronization/waitable_event.h"
#include "components/viz/common/features.h"
#include "components/viz/common/switches.h"
#include "gpu/command_buffer/service/service_utils.h"
#include "gpu/config/gpu_finch_features.h"
#include "gpu/ipc/common/gpu_client_ids.h"
#include "gpu/ipc/service/gpu_channel_manager.h"
#include "ui/gl/gl_context.h"
#include "ui/gl/gl_surface_egl.h"
#include "ui/gl/init/gl_factory.h"
namespace viz {
// static
std::unique_ptr<CompositorGpuThread> CompositorGpuThread::Create(
gpu::GpuChannelManager* gpu_channel_manager) {
if (!features::IsDrDcEnabled())
return nullptr;
auto compositor_gpu_thread =
base::WrapUnique(new CompositorGpuThread(gpu_channel_manager));
if (!compositor_gpu_thread->Initialize())
return nullptr;
return compositor_gpu_thread;
}
CompositorGpuThread::CompositorGpuThread(
gpu::GpuChannelManager* gpu_channel_manager)
: base::Thread("CompositorGpuThread"),
gpu_channel_manager_(gpu_channel_manager),
weak_ptr_factory_(this) {}
CompositorGpuThread::~CompositorGpuThread() {
base::WaitableEvent event;
task_runner()->PostTask(FROM_HERE,
base::BindOnce(&CompositorGpuThread::DestroyOnThread,
base::Unretained(this), &event));
event.Wait();
base::Thread::Stop();
}
bool CompositorGpuThread::Initialize() {
// Setup thread options.
base::Thread::Options thread_options(base::MessagePumpType::DEFAULT, 0);
if (base::FeatureList::IsEnabled(features::kGpuUseDisplayThreadPriority))
thread_options.priority = base::ThreadPriority::DISPLAY;
StartWithOptions(thread_options);
// Initialize on display compositor gpu thread and wait for init to happen.
base::WaitableEvent event;
bool success = false;
task_runner()->PostTask(
FROM_HERE, base::BindOnce(&CompositorGpuThread::InitializeOnThread,
base::Unretained(this), &event, &success));
event.Wait();
return success;
}
void CompositorGpuThread::InitializeOnThread(base::WaitableEvent* event,
bool* success) {
// Create a new share group. Note that this share group is different from the
// share group which gpu main thread uses.
auto share_group = base::MakeRefCounted<gl::GLShareGroup>();
auto surface = gl::init::CreateOffscreenGLSurface(gfx::Size());
const auto& gpu_preferences = gpu_channel_manager_->gpu_preferences();
const bool use_passthrough_decoder =
gpu::gles2::PassthroughCommandDecoderSupported() &&
gpu_preferences.use_passthrough_cmd_decoder;
gl::GLContextAttribs attribs = gpu::gles2::GenerateGLContextAttribs(
gpu::ContextCreationAttribs(), use_passthrough_decoder);
// Create a new gl context. Note that this gl context is not part of same
// share group which gpu main thread uses. Hence this context does not share
// GL resources with the contexts created on gpu main thread.
auto context =
gl::init::CreateGLContext(share_group.get(), surface.get(), attribs);
if (!context)
return;
const auto& gpu_feature_info = gpu_channel_manager_->gpu_feature_info();
gpu_feature_info.ApplyToGLContext(context.get());
if (!context->MakeCurrent(surface.get()))
return;
// Create a SharedContextState.
shared_context_state_ = base::MakeRefCounted<gpu::SharedContextState>(
std::move(share_group), std::move(surface), std::move(context),
/*use_virtualized_gl_contexts=*/false,
gpu_channel_manager_->GetContextLostCallback(),
gpu_preferences.gr_context_type,
/*vulkan_context_provider=*/nullptr, /*metal_context_provider=*/nullptr,
/*dawn_context_provider=*/nullptr,
/*peak_memory_monitor=*/weak_ptr_factory_.GetWeakPtr());
const auto& workarounds = gpu_channel_manager_->gpu_driver_bug_workarounds();
auto gles2_feature_info = base::MakeRefCounted<gpu::gles2::FeatureInfo>(
workarounds, gpu_feature_info);
// Initialize GL.
if (!shared_context_state_->InitializeGL(gpu_preferences,
std::move(gles2_feature_info))) {
return;
}
// Initialize GrContext.
if (!shared_context_state_->InitializeGrContext(
gpu_preferences, workarounds, gpu_channel_manager_->gr_shader_cache(),
/*activity_flags=*/nullptr, /*progress_reporter=*/nullptr)) {
return;
}
*success = true;
event->Signal();
}
void CompositorGpuThread::DestroyOnThread(base::WaitableEvent* event) {
weak_ptr_factory_.InvalidateWeakPtrs();
if (shared_context_state_) {
shared_context_state_->MakeCurrent(nullptr);
shared_context_state_ = nullptr;
}
event->Signal();
}
void CompositorGpuThread::OnMemoryAllocatedChange(
gpu::CommandBufferId id,
uint64_t old_size,
uint64_t new_size,
gpu::GpuPeakMemoryAllocationSource source) {
gpu_channel_manager_->GetOnMemoryAllocatedChangeCallback().Run(
id, old_size, new_size, source);
}
} // namespace viz

@ -0,0 +1,62 @@
// Copyright 2021 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_SERVICE_DISPLAY_EMBEDDER_COMPOSITOR_GPU_THREAD_H_
#define COMPONENTS_VIZ_SERVICE_DISPLAY_EMBEDDER_COMPOSITOR_GPU_THREAD_H_
#include <memory>
#include "base/threading/thread.h"
#include "components/viz/service/viz_service_export.h"
#include "gpu/command_buffer/service/memory_tracking.h"
#include "gpu/command_buffer/service/shared_context_state.h"
namespace gpu {
class GpuChannelManager;
} // namespace gpu
namespace viz {
class VIZ_SERVICE_EXPORT CompositorGpuThread
: public base::Thread,
public gpu::MemoryTracker::Observer {
public:
static std::unique_ptr<CompositorGpuThread> Create(
gpu::GpuChannelManager* gpu_channel_manager);
// Disallow copy and assign.
CompositorGpuThread(const CompositorGpuThread&) = delete;
CompositorGpuThread& operator=(const CompositorGpuThread&) = delete;
~CompositorGpuThread() override;
scoped_refptr<gpu::SharedContextState> shared_context_state() const {
return shared_context_state_;
}
// gpu::MemoryTracker::Observer implementation.
void OnMemoryAllocatedChange(
gpu::CommandBufferId id,
uint64_t old_size,
uint64_t new_size,
gpu::GpuPeakMemoryAllocationSource source) override;
private:
explicit CompositorGpuThread(gpu::GpuChannelManager* gpu_channel_manager);
bool Initialize();
// Runs on compositor gpu thread.
void InitializeOnThread(base::WaitableEvent* event, bool* success);
void DestroyOnThread(base::WaitableEvent* event);
gpu::GpuChannelManager* gpu_channel_manager_;
scoped_refptr<gpu::SharedContextState> shared_context_state_;
base::WeakPtrFactory<CompositorGpuThread> weak_ptr_factory_;
};
} // namespace viz
#endif // COMPONENTS_VIZ_SERVICE_DISPLAY_EMBEDDER_COMPOSITOR_GPU_THREAD_H_

@ -111,10 +111,9 @@ OutputSurfaceProviderImpl::CreateGpuDependency(
return nullptr;
if (renderer_settings.use_skia_renderer) {
DCHECK(task_executor_);
gpu::ScopedAllowScheduleGpuTask allow_schedule_gpu_task;
auto skia_deps = std::make_unique<SkiaOutputSurfaceDependencyImpl>(
gpu_service_impl_, task_executor_, surface_handle);
gpu_service_impl_, surface_handle);
return std::make_unique<DisplayCompositorMemoryAndTaskController>(
std::move(skia_deps));
} else {

@ -267,8 +267,7 @@ class SkiaOutputDeviceBufferQueueTest : public TestOnGpu {
void SetUpOnMain() override {
gpu::SurfaceHandle surface_handle_ = gpu::kNullSurfaceHandle;
dependency_ = std::make_unique<SkiaOutputSurfaceDependencyImpl>(
gpu_service_holder_->gpu_service(),
gpu_service_holder_->task_executor(), surface_handle_);
gpu_service_holder_->gpu_service(), surface_handle_);
}
void SetUpOnGpu() override {

@ -7,6 +7,7 @@
#include <memory>
#include <utility>
#include "base/bind_post_task.h"
#include "base/callback_helpers.h"
#include "base/threading/thread_task_runner_handle.h"
#include "build/build_config.h"
@ -22,10 +23,8 @@ namespace viz {
SkiaOutputSurfaceDependencyImpl::SkiaOutputSurfaceDependencyImpl(
GpuServiceImpl* gpu_service_impl,
gpu::CommandBufferTaskExecutor* gpu_task_executor,
gpu::SurfaceHandle surface_handle)
: gpu_service_impl_(gpu_service_impl),
gpu_task_executor_(gpu_task_executor),
surface_handle_(surface_handle),
client_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()) {}
@ -33,8 +32,9 @@ SkiaOutputSurfaceDependencyImpl::~SkiaOutputSurfaceDependencyImpl() = default;
std::unique_ptr<gpu::SingleTaskSequence>
SkiaOutputSurfaceDependencyImpl::CreateSequence() {
// Using the |gpu_task_executor_| to create sequence on the gpu main thread.
return gpu_task_executor_->CreateSequence();
return std::make_unique<gpu::SchedulerSequence>(
gpu_service_impl_->GetGpuScheduler(),
gpu_service_impl_->gpu_task_runner());
}
gpu::SharedImageManager*
@ -48,11 +48,14 @@ gpu::SyncPointManager* SkiaOutputSurfaceDependencyImpl::GetSyncPointManager() {
const gpu::GpuDriverBugWorkarounds&
SkiaOutputSurfaceDependencyImpl::GetGpuDriverBugWorkarounds() {
return gpu_service_impl_->gpu_channel_manager()->gpu_driver_bug_workarounds();
return gpu_service_impl_->gpu_driver_bug_workarounds();
}
scoped_refptr<gpu::SharedContextState>
SkiaOutputSurfaceDependencyImpl::GetSharedContextState() {
if (gpu_service_impl_->compositor_gpu_thread()) {
return gpu_service_impl_->compositor_gpu_thread()->shared_context_state();
}
return gpu_service_impl_->GetContextState();
}
@ -109,16 +112,14 @@ scoped_refptr<gl::GLSurface> SkiaOutputSurfaceDependencyImpl::CreateGLSurface(
base::ScopedClosureRunner SkiaOutputSurfaceDependencyImpl::CacheGLSurface(
gl::GLSurface* surface) {
gpu_service_impl_->main_runner()->PostTask(
gpu_service_impl_->gpu_task_runner()->PostTask(
FROM_HERE,
base::BindOnce(&gl::GLSurface::AddRef, base::Unretained(surface)));
auto release_callback = base::BindOnce(
[](const scoped_refptr<base::SequencedTaskRunner>& runner,
gl::GLSurface* surface) {
runner->PostTask(FROM_HERE, base::BindOnce(&gl::GLSurface::Release,
base::Unretained(surface)));
},
gpu_service_impl_->main_runner(), base::Unretained(surface));
auto release_callback = base::BindPostTask(
gpu_service_impl_->gpu_task_runner(),
base::BindOnce(&gl::GLSurface::Release, base::Unretained(surface)));
return base::ScopedClosureRunner(std::move(release_callback));
}
@ -128,17 +129,15 @@ void SkiaOutputSurfaceDependencyImpl::PostTaskToClientThread(
}
void SkiaOutputSurfaceDependencyImpl::ScheduleGrContextCleanup() {
gpu_service_impl_->gpu_channel_manager()->ScheduleGrContextCleanup();
GetSharedContextState()->ScheduleGrContextCleanup();
}
void SkiaOutputSurfaceDependencyImpl::ScheduleDelayedGPUTaskFromGPUThread(
base::OnceClosure task) {
DCHECK(gpu_service_impl_->main_runner()->BelongsToCurrentThread());
constexpr base::TimeDelta kDelayForDelayedWork =
base::TimeDelta::FromMilliseconds(2);
gpu_service_impl_->main_runner()->PostDelayedTask(FROM_HERE, std::move(task),
kDelayForDelayedWork);
gpu_service_impl_->gpu_task_runner()->PostDelayedTask(
FROM_HERE, std::move(task), kDelayForDelayedWork);
}
#if defined(OS_WIN)

@ -16,10 +16,6 @@ namespace base {
class SingleThreadTaskRunner;
}
namespace gpu {
class CommandBufferTaskExecutor;
}
namespace viz {
class GpuServiceImpl;
@ -29,7 +25,6 @@ class VIZ_SERVICE_EXPORT SkiaOutputSurfaceDependencyImpl
public:
SkiaOutputSurfaceDependencyImpl(
GpuServiceImpl* gpu_service_impl,
gpu::CommandBufferTaskExecutor* gpu_task_executor,
gpu::SurfaceHandle surface_handle);
~SkiaOutputSurfaceDependencyImpl() override;
@ -71,7 +66,6 @@ class VIZ_SERVICE_EXPORT SkiaOutputSurfaceDependencyImpl
private:
GpuServiceImpl* const gpu_service_impl_;
gpu::CommandBufferTaskExecutor* const gpu_task_executor_;
const gpu::SurfaceHandle surface_handle_;
scoped_refptr<base::SingleThreadTaskRunner> client_thread_task_runner_;

@ -79,8 +79,7 @@ void SkiaOutputSurfaceImplTest::SetUpSkiaOutputSurfaceImpl() {
RendererSettings settings;
settings.use_skia_renderer = true;
auto skia_deps = std::make_unique<SkiaOutputSurfaceDependencyImpl>(
GetGpuService(), TestGpuServiceHolder::GetInstance()->task_executor(),
gpu::kNullSurfaceHandle);
GetGpuService(), gpu::kNullSurfaceHandle);
display_controller_ =
std::make_unique<DisplayCompositorMemoryAndTaskController>(
std::move(skia_deps));

@ -339,6 +339,8 @@ GpuServiceImpl::GpuServiceImpl(
gpu_preferences_(gpu_preferences),
gpu_info_(gpu_info),
gpu_feature_info_(gpu_feature_info),
gpu_driver_bug_workarounds_(
gpu_feature_info.enabled_gpu_driver_bug_workarounds),
gpu_info_for_hardware_gpu_(gpu_info_for_hardware_gpu),
gpu_feature_info_for_hardware_gpu_(gpu_feature_info_for_hardware_gpu),
gpu_extra_info_(gpu_extra_info),
@ -453,6 +455,7 @@ GpuServiceImpl::~GpuServiceImpl() {
if (watchdog_thread_)
watchdog_thread_->OnGpuProcessTearDown();
compositor_gpu_thread_.reset();
media_gpu_channel_manager_.reset();
gpu_channel_manager_.reset();
@ -552,9 +555,12 @@ void GpuServiceImpl::InitializeWithHost(
// When using real buffers for testing overlay configurations, we need
// access to SharedImageManager on the viz thread to obtain the buffer
// corresponding to a mailbox.
bool thread_safe_manager = features::ShouldUseRealBuffersForPageFlipTest();
const bool display_context_on_another_thread = features::IsDrDcEnabled();
bool thread_safe_manager =
features::ShouldUseRealBuffersForPageFlipTest() ||
display_context_on_another_thread;
owned_shared_image_manager_ = std::make_unique<gpu::SharedImageManager>(
thread_safe_manager, false /* display_context_on_another_thread */);
thread_safe_manager, display_context_on_another_thread);
shared_image_manager = owned_shared_image_manager_.get();
} else {
// With this feature enabled, we don't expect to receive an external
@ -588,6 +594,10 @@ void GpuServiceImpl::InitializeWithHost(
gpu_channel_manager_.get());
if (watchdog_thread())
watchdog_thread()->AddPowerObserver();
// Create and Initialize compositor gpu thread.
compositor_gpu_thread_ =
CompositorGpuThread::Create(gpu_channel_manager_.get());
}
void GpuServiceImpl::Bind(
@ -852,10 +862,8 @@ void GpuServiceImpl::UnregisterDisplayContext(
void GpuServiceImpl::LoseAllContexts() {
DCHECK(main_runner_->BelongsToCurrentThread());
if (IsExiting())
return;
for (auto& display_context : display_contexts_)
display_context.MarkContextLost();
gpu_channel_manager_->LoseAllContexts();

@ -20,6 +20,7 @@
#include "base/threading/thread.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "components/viz/service/display_embedder/compositor_gpu_thread.h"
#include "components/viz/service/viz_service_export.h"
#include "gpu/command_buffer/client/gpu_memory_buffer_manager.h"
#include "gpu/command_buffer/common/activity_flags.h"
@ -250,6 +251,10 @@ class VIZ_SERVICE_EXPORT GpuServiceImpl : public gpu::GpuChannelManagerDelegate,
return gpu_channel_manager_.get();
}
CompositorGpuThread* compositor_gpu_thread() {
return compositor_gpu_thread_.get();
}
gpu::ImageFactory* gpu_image_factory();
gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory() {
return gpu_memory_buffer_factory_.get();
@ -279,12 +284,21 @@ class VIZ_SERVICE_EXPORT GpuServiceImpl : public gpu::GpuChannelManagerDelegate,
return main_runner_;
}
scoped_refptr<base::SingleThreadTaskRunner> gpu_task_runner() {
return compositor_gpu_thread() ? compositor_gpu_thread()->task_runner()
: main_runner_;
}
gpu::GpuWatchdogThread* watchdog_thread() { return watchdog_thread_.get(); }
const gpu::GpuFeatureInfo& gpu_feature_info() const {
return gpu_feature_info_;
}
const gpu::GpuDriverBugWorkarounds& gpu_driver_bug_workarounds() const {
return gpu_driver_bug_workarounds_;
}
bool in_host_process() const { return gpu_info_.in_process_gpu; }
void set_start_time(base::Time start_time) { start_time_ = start_time; }
@ -371,6 +385,8 @@ class VIZ_SERVICE_EXPORT GpuServiceImpl : public gpu::GpuChannelManagerDelegate,
// Information about general chrome feature support for the GPU.
gpu::GpuFeatureInfo gpu_feature_info_;
const gpu::GpuDriverBugWorkarounds gpu_driver_bug_workarounds_;
bool hdr_enabled_ = false;
// What we would have gotten if we haven't fallen back to SwiftShader or
@ -385,6 +401,9 @@ class VIZ_SERVICE_EXPORT GpuServiceImpl : public gpu::GpuChannelManagerDelegate,
std::unique_ptr<gpu::GpuChannelManager> gpu_channel_manager_;
std::unique_ptr<media::MediaGpuChannelManager> media_gpu_channel_manager_;
// Display compositor gpu thread.
std::unique_ptr<CompositorGpuThread> compositor_gpu_thread_;
// On some platforms (e.g. android webview), the SyncPointManager and
// SharedImageManager comes from external sources.
std::unique_ptr<gpu::SyncPointManager> owned_sync_point_manager_;

@ -284,10 +284,16 @@ void VizMainImpl::StopDebugStream() {
#endif
scoped_refptr<gpu::SharedContextState> VizMainImpl::GetSharedContextState() {
// This method should be only called for GLRenderer and not for SkiaRenderer.
// Hence adding DCHECK since DrDc only works with SkiaRenderer.
DCHECK(!features::IsDrDcEnabled());
return gpu_service_->GetContextState();
}
scoped_refptr<gl::GLShareGroup> VizMainImpl::GetShareGroup() {
// This method should be only called for GLRenderer and not for SkiaRenderer.
// Hence adding DCHECK since DrDc only works with SkiaRenderer.
DCHECK(!features::IsDrDcEnabled());
return gpu_service_->share_group();
}

@ -13,7 +13,7 @@
#include "base/synchronization/lock.h"
#include "base/threading/thread_checker.h"
#include "base/trace_event/memory_dump_provider.h"
#include "gpu/gpu_gles2_export.h"
#include "gpu/raster_export.h"
#include "third_party/skia/include/gpu/GrContextOptions.h"
class GrDirectContext;
@ -21,11 +21,11 @@ class GrDirectContext;
namespace gpu {
namespace raster {
class GPU_GLES2_EXPORT GrShaderCache
class RASTER_EXPORT GrShaderCache
: public GrContextOptions::PersistentCache,
public base::trace_event::MemoryDumpProvider {
public:
class GPU_GLES2_EXPORT Client {
class RASTER_EXPORT Client {
public:
virtual ~Client() {}
@ -33,7 +33,7 @@ class GPU_GLES2_EXPORT GrShaderCache
const std::string& shader) = 0;
};
class GPU_GLES2_EXPORT ScopedCacheUse {
class RASTER_EXPORT ScopedCacheUse {
public:
ScopedCacheUse(GrShaderCache* cache, int32_t client_id);
~ScopedCacheUse();

@ -193,6 +193,9 @@ const base::Feature kVulkan {
#endif
};
const base::Feature kEnableDrDc{"EnableDrDc",
base::FEATURE_DISABLED_BY_DEFAULT};
#if defined(OS_ANDROID)
const base::FeatureParam<std::string> kVulkanBlockListByBrand{
@ -288,6 +291,24 @@ bool IsUsingVulkan() {
#endif
}
bool IsDrDcEnabled() {
#if defined(OS_ANDROID)
// Currently only supported on android P.
if (base::android::BuildInfo::GetInstance()->sdk_int() !=
base::android::SDK_VERSION_P) {
return false;
}
// Currently not supported for vulkan.
if (IsUsingVulkan())
return false;
return base::FeatureList::IsEnabled(kEnableDrDc);
#else
return false;
#endif
}
#if defined(OS_ANDROID)
bool IsAImageReaderEnabled() {
return base::FeatureList::IsEnabled(kAImageReader) &&

@ -60,8 +60,11 @@ GPU_EXPORT extern const base::Feature kEnableGrShaderCacheForVulkan;
GPU_EXPORT extern const base::Feature kEnableVkPipelineCache;
GPU_EXPORT extern const base::Feature kReduceOpsTaskSplitting;
GPU_EXPORT extern const base::Feature kEnableDrDc;
GPU_EXPORT bool IsUsingVulkan();
GPU_EXPORT bool IsDrDcEnabled();
#if defined(OS_ANDROID)
GPU_EXPORT bool IsAImageReaderEnabled();
GPU_EXPORT bool IsAndroidSurfaceControlEnabled();

@ -298,7 +298,7 @@ gpu::ContextResult InProcessCommandBuffer::Initialize(
// would be kept alive by VizProcessContextProvider. If no |task_sequence| is
// passed in, create one here.
if (task_sequence) {
task_sequence_ = task_sequence;
task_sequence_ = std::move(task_sequence);
} else {
task_scheduler_holder_ =
std::make_unique<gpu::GpuTaskSchedulerHelper>(task_executor_);

@ -9,6 +9,7 @@
#include <utility>
#include "base/bind.h"
#include "base/bind_post_task.h"
#include "base/command_line.h"
#include "base/debug/crash_logging.h"
#include "base/location.h"
@ -498,6 +499,29 @@ void GpuChannelManager::LoseAllContexts() {
}
}
SharedContextState::ContextLostCallback
GpuChannelManager::GetContextLostCallback() {
return base::BindPostTask(task_runner_,
base::BindOnce(&GpuChannelManager::OnContextLost,
weak_factory_.GetWeakPtr()));
}
GpuChannelManager::OnMemoryAllocatedChangeCallback
GpuChannelManager::GetOnMemoryAllocatedChangeCallback() {
return base::BindPostTask(
task_runner_,
base::BindOnce(
[](base::WeakPtr<gpu::GpuChannelManager> gpu_channel_manager,
gpu::CommandBufferId id, uint64_t old_size, uint64_t new_size,
gpu::GpuPeakMemoryAllocationSource source) {
if (gpu_channel_manager) {
gpu_channel_manager->peak_memory_monitor()
->OnMemoryAllocatedChange(id, old_size, new_size, source);
}
},
weak_factory_.GetWeakPtr()));
}
void GpuChannelManager::DestroyAllChannels() {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
@ -872,8 +896,6 @@ void GpuChannelManager::ScheduleGrContextCleanup() {
void GpuChannelManager::StoreShader(const std::string& key,
const std::string& shader) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
delegate_->StoreShaderToDisk(kGrShaderCacheClientId, key, shader);
}

@ -77,6 +77,12 @@ class ProgramCache;
class GPU_IPC_SERVICE_EXPORT GpuChannelManager
: public raster::GrShaderCache::Client {
public:
using OnMemoryAllocatedChangeCallback =
base::OnceCallback<void(gpu::CommandBufferId id,
uint64_t old_size,
uint64_t new_size,
gpu::GpuPeakMemoryAllocationSource source)>;
GpuChannelManager(
const GpuPreferences& gpu_preferences,
GpuChannelManagerDelegate* delegate,
@ -155,6 +161,8 @@ class GPU_IPC_SERVICE_EXPORT GpuChannelManager
return &peak_memory_monitor_;
}
GpuProcessActivityFlags* activity_flags() { return &activity_flags_; }
#if defined(OS_ANDROID)
void DidAccessGpu();
void OnBackgroundCleanup();
@ -162,13 +170,15 @@ class GPU_IPC_SERVICE_EXPORT GpuChannelManager
void OnApplicationBackgrounded();
MailboxManager* mailbox_manager() { return mailbox_manager_.get(); }
MailboxManager* mailbox_manager() const { return mailbox_manager_.get(); }
gl::GLShareGroup* share_group() const { return share_group_.get(); }
SyncPointManager* sync_point_manager() const { return sync_point_manager_; }
SharedImageManager* shared_image_manager() { return shared_image_manager_; }
SharedImageManager* shared_image_manager() const {
return shared_image_manager_;
}
// Retrieve GPU Resource consumption statistics for the task manager
void GetVideoMemoryUsageStats(
@ -199,6 +209,10 @@ class GPU_IPC_SERVICE_EXPORT GpuChannelManager
void LoseAllContexts();
SharedContextState::ContextLostCallback GetContextLostCallback();
GpuChannelManager::OnMemoryAllocatedChangeCallback
GetOnMemoryAllocatedChangeCallback();
private:
friend class GpuChannelManagerTest;

@ -327,7 +327,6 @@ void InProcessContextFactory::CreateLayerTreeFrameSink(
if (renderer_settings_.use_skia_renderer) {
auto skia_deps = std::make_unique<viz::SkiaOutputSurfaceDependencyImpl>(
viz::TestGpuServiceHolder::GetInstance()->gpu_service(),
viz::TestGpuServiceHolder::GetInstance()->task_executor(),
gpu::kNullSurfaceHandle);
display_dependency =
std::make_unique<viz::DisplayCompositorMemoryAndTaskController>(

@ -1618,6 +1618,12 @@ void NativeViewGLSurfaceEGL::SetEnableSwapTimestamps() {
DCHECK_GE(composition_start_index_, 0);
use_egl_timestamps_ = !supported_egl_timestamps_.empty();
// Recreate the presentation helper here to make sure egl_timestamp_client_
// in |presentation_helper_| is initialized after |use_egl_timestamp_| is
// initialized.
presentation_helper_ =
std::make_unique<GLSurfacePresentationHelper>(GetVSyncProvider());
}
bool NativeViewGLSurfaceEGL::InitializeNativeWindow() {