diff --git a/BUILD.gn b/BUILD.gn index 7cd6f7f9d32f7..fe0ed6dd1b584 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -842,10 +842,6 @@ group("gn_all") { } } - if (enable_vulkan) { - deps += [ "//gpu/vulkan/demo" ] - } - if (use_atk) { deps += [ "//tools/accessibility/inspect:ax_dump_events", diff --git a/gpu/vulkan/demo/BUILD.gn b/gpu/vulkan/demo/BUILD.gn deleted file mode 100644 index a6d8705f942de..0000000000000 --- a/gpu/vulkan/demo/BUILD.gn +++ /dev/null @@ -1,41 +0,0 @@ -# Copyright 2018 The Chromium Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -import("//build/config/ui.gni") -import("//gpu/vulkan/features.gni") - -assert(enable_vulkan) - -# TODO(cblume): These tests should run on each platform -- crbug.com/858614 - -group("demo") { - if (use_ozone && is_linux) { - deps = [ ":vulkan_demo" ] - } -} - -if (use_ozone && is_linux) { - executable("vulkan_demo") { - sources = [ - "main.cc", - "vulkan_demo.cc", - "vulkan_demo.h", - ] - - deps = [ - "//base", - "//components/tracing:startup_tracing", - "//components/viz/common", - "//gpu/vulkan/init", - "//skia", - "//ui/display/types", - "//ui/events", - "//ui/events/platform", - "//ui/gfx:native_widget_types", - "//ui/gfx/geometry", - "//ui/ozone", - "//ui/platform_window:platform_window", - ] - } -} diff --git a/gpu/vulkan/demo/DEPS b/gpu/vulkan/demo/DEPS deleted file mode 100644 index d590920e56e62..0000000000000 --- a/gpu/vulkan/demo/DEPS +++ /dev/null @@ -1,7 +0,0 @@ -include_rules = [ - "+components/tracing", - "+components/viz", - "+skia/ext", - "+third_party/skia", - "+ui", -] diff --git a/gpu/vulkan/demo/main.cc b/gpu/vulkan/demo/main.cc deleted file mode 100644 index ad3832d918071..0000000000000 --- a/gpu/vulkan/demo/main.cc +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include <memory> - -#include "base/at_exit.h" -#include "base/command_line.h" -#include "base/debug/stack_trace.h" -#include "base/logging.h" -#include "base/message_loop/message_pump_type.h" -#include "base/task/single_thread_task_executor.h" -#include "base/task/thread_pool/thread_pool_instance.h" -#include "base/trace_event/trace_event.h" -#include "components/tracing/common/trace_to_console.h" -#include "components/tracing/common/tracing_switches.h" -#include "gpu/vulkan/demo/vulkan_demo.h" - -int main(int argc, char** argv) { - base::CommandLine::Init(argc, argv); - base::AtExitManager exit_manager; - - base::debug::EnableInProcessStackDumping(); - - // Initialize logging so we can enable VLOG messages. - logging::LoggingSettings settings; - logging::InitLogging(settings); - - // Initialize tracing. - if (base::CommandLine::ForCurrentProcess()->HasSwitch( - switches::kTraceToConsole)) { - base::trace_event::TraceConfig trace_config = - tracing::GetConfigForTraceToConsole(); - base::trace_event::TraceLog::GetInstance()->SetEnabled( - trace_config, base::trace_event::TraceLog::RECORDING_MODE); - } - - // Build UI thread task executor. This is used by platform - // implementations for event polling & running background tasks. - base::SingleThreadTaskExecutor main_task_executor(base::MessagePumpType::UI); - base::ThreadPoolInstance::CreateAndStartWithDefaultParams("VulkanDemo"); - - gpu::VulkanDemo vulkan_demo; - vulkan_demo.Initialize(); - vulkan_demo.Run(); - vulkan_demo.Destroy(); - - return 0; -} diff --git a/gpu/vulkan/demo/vulkan_demo.cc b/gpu/vulkan/demo/vulkan_demo.cc deleted file mode 100644 index 983aaadaeca34..0000000000000 --- a/gpu/vulkan/demo/vulkan_demo.cc +++ /dev/null @@ -1,238 +0,0 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "gpu/vulkan/demo/vulkan_demo.h" - -#include "base/bind.h" -#include "base/run_loop.h" -#include "base/threading/thread_task_runner_handle.h" -#include "components/viz/common/gpu/vulkan_in_process_context_provider.h" -#include "gpu/vulkan/init/vulkan_factory.h" -#include "gpu/vulkan/vulkan_function_pointers.h" -#include "gpu/vulkan/vulkan_implementation.h" -#include "gpu/vulkan/vulkan_surface.h" -#include "skia/ext/legacy_display_globals.h" -#include "third_party/skia/include/core/SkCanvas.h" -#include "third_party/skia/include/core/SkFont.h" -#include "third_party/skia/include/core/SkSurface.h" -#include "third_party/skia/include/effects/SkGradientShader.h" -#include "third_party/skia/include/gpu/GrBackendSemaphore.h" -#include "third_party/skia/include/gpu/GrBackendSurface.h" -#include "third_party/skia/include/gpu/GrDirectContext.h" -#include "ui/events/platform/platform_event_source.h" -#include "ui/ozone/public/ozone_platform.h" -#include "ui/platform_window/platform_window_init_properties.h" - -namespace gpu { - -VulkanDemo::VulkanDemo() = default; - -VulkanDemo::~VulkanDemo() = default; - -void VulkanDemo::Initialize() { - ui::OzonePlatform::InitParams params; - params.single_process = true; - ui::OzonePlatform::InitializeForUI(params); - ui::OzonePlatform::InitializeForGPU(params); - - vulkan_implementation_ = gpu::CreateVulkanImplementation(); - DCHECK(vulkan_implementation_) << ":Failed to create vulkan implementation."; - - auto result = vulkan_implementation_->InitializeVulkanInstance(); - DCHECK(result) << "Failed to initialize vulkan implementation."; - - vulkan_context_provider_ = - viz::VulkanInProcessContextProvider::Create(vulkan_implementation_.get()); - DCHECK(vulkan_context_provider_) - << "Failed to create vulkan context provider."; - - event_source_ = ui::PlatformEventSource::CreateDefault(); - - ui::PlatformWindowInitProperties properties; - properties.bounds = gfx::Rect(100, 100, 800, 600); - window_ = ui::OzonePlatform::GetInstance()->CreatePlatformWindow( - this, std::move(properties)); - window_->Show(); - - // Sync up size between |window_| and |vulkan_surface_| - vulkan_surface_->Reshape(window_->GetBounds().size(), - gfx::OVERLAY_TRANSFORM_NONE); - sk_surfaces_.resize(vulkan_surface_->swap_chain()->num_images()); -} - -void VulkanDemo::Destroy() { - VkDevice device = - vulkan_context_provider_->GetDeviceQueue()->GetVulkanDevice(); - vkDeviceWaitIdle(device); - vulkan_surface_->Destroy(); -} - -void VulkanDemo::Run() { - DCHECK(!is_running_); - DCHECK(!run_loop_); - base::RunLoop run_loop; - is_running_ = true; - run_loop_ = &run_loop; - RenderFrame(); - run_loop.Run(); - run_loop_ = nullptr; -} - -void VulkanDemo::OnBoundsChanged(const BoundsChange& change) { - if (vulkan_surface_->image_size() == change.bounds.size()) - return; - auto generation = vulkan_surface_->swap_chain_generation(); - vulkan_surface_->Reshape(change.bounds.size(), gfx::OVERLAY_TRANSFORM_NONE); - if (vulkan_surface_->swap_chain_generation() != generation) { - // Size has been changed, we need to clear all surfaces which will be - // recreated later. - sk_surfaces_.clear(); - sk_surfaces_.resize(vulkan_surface_->swap_chain()->num_images()); - } -} - -void VulkanDemo::OnCloseRequest() { - is_running_ = false; - if (run_loop_) - run_loop_->QuitWhenIdle(); -} - -void VulkanDemo::OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) { - DCHECK_EQ(accelerated_widget_, gfx::kNullAcceleratedWidget); - accelerated_widget_ = widget; - - vulkan_surface_ = - vulkan_implementation_->CreateViewSurface(accelerated_widget_); - DCHECK(vulkan_surface_); - - auto result = - vulkan_surface_->Initialize(vulkan_context_provider_->GetDeviceQueue(), - gpu::VulkanSurface::DEFAULT_SURFACE_FORMAT); - DCHECK(result) << "Failed to initialize vulkan surface."; -} - -void VulkanDemo::CreateSkSurface() { - scoped_write_.emplace(vulkan_surface_->swap_chain()); - auto& sk_surface = sk_surfaces_[scoped_write_->image_index()]; - - if (!sk_surface) { - SkSurfaceProps surface_props = - skia::LegacyDisplayGlobals::GetSkSurfaceProps(); - - GrVkImageInfo vk_image_info; - vk_image_info.fImage = scoped_write_->image(); - vk_image_info.fImageLayout = scoped_write_->image_layout(); - vk_image_info.fImageTiling = VK_IMAGE_TILING_OPTIMAL; - vk_image_info.fFormat = VK_FORMAT_B8G8R8A8_UNORM; - vk_image_info.fImageUsageFlags = scoped_write_->image_usage(); - vk_image_info.fSampleCount = 1; - vk_image_info.fLevelCount = 1; - const auto& size = vulkan_surface_->image_size(); - GrBackendRenderTarget render_target(size.width(), size.height(), 0, - vk_image_info); - sk_surface = SkSurface::MakeFromBackendRenderTarget( - vulkan_context_provider_->GetGrContext(), render_target, - kTopLeft_GrSurfaceOrigin, kBGRA_8888_SkColorType, nullptr, - &surface_props); - } else { - auto backend = sk_surface->getBackendRenderTarget( - SkSurface::kFlushRead_BackendHandleAccess); - backend.setVkImageLayout(scoped_write_->image_layout()); - } - DCHECK(sk_surface); - - sk_surface_ = sk_surface; - GrBackendSemaphore semaphore; - semaphore.initVulkan(scoped_write_->begin_semaphore()); - auto result = - sk_surface_->wait(1, &semaphore, /*deleteSemaphoresAfterWait=*/false); - DCHECK(result); -} - -void VulkanDemo::Draw(SkCanvas* canvas, float fraction) { - canvas->save(); - canvas->clear(SkColorSetARGB(255, 255 * fraction, 255 * (1 - fraction), 0)); - - constexpr float kWidth = 800; - constexpr float kHeight = 600; - - const auto& size = vulkan_surface_->image_size(); - canvas->scale(size.width() / kWidth, size.height() / kHeight); - - SkPaint paint; - paint.setColor(SK_ColorRED); - - // Draw a rectangle with red paint - SkRect rect = SkRect::MakeXYWH(10, 10, 128, 128); - canvas->drawRect(rect, paint); - - // Set up a linear gradient and draw a circle - { - SkPoint linearPoints[] = {{0, 0}, {300, 300}}; - SkColor linearColors[] = {SK_ColorGREEN, SK_ColorBLACK}; - paint.setShader(SkGradientShader::MakeLinear( - linearPoints, linearColors, nullptr, 2, SkTileMode::kMirror)); - paint.setAntiAlias(true); - - canvas->drawCircle(200, 200, 64, paint); - - // Detach shader - paint.setShader(nullptr); - } - - // Draw a message with a nice black paint - paint.setColor(SK_ColorBLACK); - - SkFont font; - font.setSize(32); - font.setSubpixel(true); - - static const char message[] = "Hello Vulkan"; - - // Translate and rotate - canvas->translate(300, 300); - rotation_angle_ += 0.2f; - if (rotation_angle_ > 360) { - rotation_angle_ -= 360; - } - canvas->rotate(rotation_angle_); - - // Draw the text - canvas->drawString(message, 0, 0, font, paint); - - canvas->restore(); -} - -void VulkanDemo::RenderFrame() { - if (!is_running_) - return; - CreateSkSurface(); - Draw(sk_surface_->getCanvas(), 0.7); - GrBackendSemaphore semaphore; - semaphore.initVulkan(scoped_write_->end_semaphore()); - GrFlushInfo flush_info = { - .fNumSemaphores = 1, - .fSignalSemaphores = &semaphore, - }; - auto queue_index = - vulkan_context_provider_->GetDeviceQueue()->GetVulkanQueueIndex(); - GrBackendSurfaceMutableState state(VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, - queue_index); - sk_surface_->flush(flush_info, &state); - sk_surface_->recordingContext()->asDirectContext()->submit(); - auto backend = sk_surface_->getBackendRenderTarget( - SkSurface::kFlushRead_BackendHandleAccess); - GrVkImageInfo vk_image_info; - if (!backend.getVkImageInfo(&vk_image_info)) - NOTREACHED() << "Failed to get image info"; - DCHECK_EQ(vk_image_info.fImageLayout, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR); - scoped_write_.reset(); - vulkan_surface_->SwapBuffers(); - - base::ThreadTaskRunnerHandle::Get()->PostTask( - FROM_HERE, - base::BindOnce(&VulkanDemo::RenderFrame, base::Unretained(this))); -} - -} // namespace gpu diff --git a/gpu/vulkan/demo/vulkan_demo.h b/gpu/vulkan/demo/vulkan_demo.h deleted file mode 100644 index da6323c3e50f4..0000000000000 --- a/gpu/vulkan/demo/vulkan_demo.h +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef GPU_VULKAN_DEMO_VULKAN_DEMO_H_ -#define GPU_VULKAN_DEMO_VULKAN_DEMO_H_ - -#include <memory> - -#include "base/memory/scoped_refptr.h" -#include "gpu/vulkan/vulkan_swap_chain.h" -#include "third_party/abseil-cpp/absl/types/optional.h" -#include "third_party/skia/include/core/SkRefCnt.h" -#include "ui/gfx/geometry/size.h" -#include "ui/platform_window/platform_window.h" -#include "ui/platform_window/platform_window_delegate.h" - -class SkCanvas; -class SkSurface; - -namespace base { -class RunLoop; -} - -namespace viz { -class VulkanContextProvider; -} - -namespace ui { -class PlatformEventSource; -} // namespace ui - -namespace gpu { - -class VulkanImplementation; -class VulkanSurface; - -class VulkanDemo : public ui::PlatformWindowDelegate { - public: - VulkanDemo(); - ~VulkanDemo() override; - - void Initialize(); - void Destroy(); - void Run(); - - private: - // ui::PlatformWindowDelegate: - void OnBoundsChanged(const BoundsChange& change) override; - void OnDamageRect(const gfx::Rect& damaged_region) override {} - void DispatchEvent(ui::Event* event) override {} - void OnCloseRequest() override; - void OnClosed() override {} - void OnWindowStateChanged(ui::PlatformWindowState old_state, - ui::PlatformWindowState new_state) override {} - void OnLostCapture() override {} - void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) override; - void OnWillDestroyAcceleratedWidget() override {} - void OnAcceleratedWidgetDestroyed() override {} - void OnActivationChanged(bool active) override {} - void OnMouseEnter() override {} - - void CreateSkSurface(); - void Draw(SkCanvas* canvas, float fraction); - void RenderFrame(); - - std::unique_ptr<VulkanImplementation> vulkan_implementation_; - scoped_refptr<viz::VulkanContextProvider> vulkan_context_provider_; - gfx::AcceleratedWidget accelerated_widget_ = gfx::kNullAcceleratedWidget; - std::unique_ptr<ui::PlatformEventSource> event_source_; - std::unique_ptr<ui::PlatformWindow> window_; - std::unique_ptr<VulkanSurface> vulkan_surface_; - absl::optional<VulkanSwapChain::ScopedWrite> scoped_write_; - sk_sp<SkSurface> sk_surface_; - std::vector<sk_sp<SkSurface>> sk_surfaces_; - float rotation_angle_ = 0; - base::RunLoop* run_loop_ = nullptr; - bool is_running_ = false; -}; - -} // namespace gpu - -#endif // GPU_VULKAN_DEMO_VULKAN_DEMO_H_