summaryrefslogtreecommitdiff
path: root/chromium/gpu/vulkan/demo/vulkan_demo.h
blob: da6323c3e50f4d843c4901f555fe0b887d8acd27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// 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_