File: skia_output_device_vulkan_secondary_cb.cc

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (141 lines) | stat: -rw-r--r-- 5,647 bytes parent folder | download | duplicates (5)
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// Copyright 2020 The Chromium Authors
// 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/skia_output_device_vulkan_secondary_cb.h"

#include <utility>

#include "components/viz/common/gpu/vulkan_context_provider.h"
#include "gpu/command_buffer/service/shared_context_state.h"
#include "third_party/skia/include/gpu/ganesh/GrBackendSurface.h"
#include "third_party/skia/include/gpu/ganesh/GrDirectContext.h"
#include "third_party/skia/include/gpu/ganesh/GrTypes.h"
#include "third_party/skia/include/gpu/ganesh/vk/GrVkBackendSemaphore.h"
#include "third_party/skia/include/gpu/ganesh/vk/GrVkBackendSurface.h"
#include "third_party/skia/include/private/chromium/GrDeferredDisplayList.h"
#include "third_party/skia/include/private/chromium/GrSurfaceCharacterization.h"
#include "third_party/skia/include/private/chromium/GrVkSecondaryCBDrawContext.h"
#include "ui/gfx/presentation_feedback.h"

namespace viz {

SkiaOutputDeviceVulkanSecondaryCB::SkiaOutputDeviceVulkanSecondaryCB(
    VulkanContextProvider* context_provider,
    gpu::MemoryTracker* memory_tracker,
    DidSwapBufferCompleteCallback did_swap_buffer_complete_callback)
    : SkiaOutputDevice(context_provider->GetGrContext(),
                       /*graphite_shared_context=*/nullptr,
                       memory_tracker,
                       std::move(did_swap_buffer_complete_callback)),
      context_provider_(context_provider) {
  capabilities_.uses_default_gl_framebuffer = false;
  capabilities_.pending_swap_params.max_pending_swaps = 1;
  capabilities_.output_surface_origin = gfx::SurfaceOrigin::kTopLeft;
  capabilities_.supports_post_sub_buffer = false;
  capabilities_.orientation_mode = OutputSurface::OrientationMode::kLogic;
  capabilities_.root_is_vulkan_secondary_command_buffer = true;

  GrVkSecondaryCBDrawContext* secondary_cb_draw_context =
      context_provider_->GetGrSecondaryCBDrawContext();
  GrSurfaceCharacterization characterization;
  VkFormat vkFormat = VK_FORMAT_UNDEFINED;
  bool result = secondary_cb_draw_context->characterize(&characterization);
  CHECK(result);
  GrBackendFormats::AsVkFormat(characterization.backendFormat(), &vkFormat);
  auto sk_color_type = vkFormat == VK_FORMAT_R8G8B8A8_UNORM
                           ? kRGBA_8888_SkColorType
                           : kBGRA_8888_SkColorType;
  capabilities_.sk_color_type_map[SinglePlaneFormat::kRGBA_8888] =
      sk_color_type;
  capabilities_.sk_color_type_map[SinglePlaneFormat::kBGRA_8888] =
      sk_color_type;
}

std::unique_ptr<SkiaOutputDevice::ScopedPaint>
SkiaOutputDeviceVulkanSecondaryCB::BeginScopedPaint() {
  std::vector<GrBackendSemaphore> end_semaphores;
  SkSurface* sk_surface = BeginPaint(&end_semaphores);
  return std::make_unique<SkiaOutputDevice::ScopedPaint>(
      std::move(end_semaphores), this, sk_surface);
}

void SkiaOutputDeviceVulkanSecondaryCB::Submit(
    scoped_refptr<gpu::SharedContextState> context_state,
    bool sync_cpu,
    base::OnceClosure callback) {
  // Submit the primary command buffer which may render passes.
  context_provider_->GetGrContext()->submit(sync_cpu ? GrSyncCpu::kYes
                                                     : GrSyncCpu::kNo);
  context_provider_->EnqueueSecondaryCBPostSubmitTask(std::move(callback));
}

bool SkiaOutputDeviceVulkanSecondaryCB::Reshape(const ReshapeParams& params) {
  // No-op
  size_ = params.GfxSize();
  return true;
}

void SkiaOutputDeviceVulkanSecondaryCB::Present(
    const std::optional<gfx::Rect>& update_rect,
    BufferPresentedCallback feedback,
    OutputSurfaceFrame frame) {
  CHECK(!update_rect);
  StartSwapBuffers(std::move(feedback));
  FinishSwapBuffers(gfx::SwapCompletionResult(gfx::SwapResult::SWAP_ACK), size_,
                    std::move(frame));
}

SkSurface* SkiaOutputDeviceVulkanSecondaryCB::BeginPaint(
    std::vector<GrBackendSemaphore>* end_semaphores) {
  return nullptr;
}

void SkiaOutputDeviceVulkanSecondaryCB::EndPaint() {}

SkCanvas* SkiaOutputDeviceVulkanSecondaryCB::GetCanvas(SkSurface* sk_surface) {
  DCHECK(!sk_surface);
  return context_provider_->GetGrSecondaryCBDrawContext()->getCanvas();
}

GrSemaphoresSubmitted SkiaOutputDeviceVulkanSecondaryCB::Flush(
    SkSurface* sk_surface,
    VulkanContextProvider* vulkan_context_provider,
    std::vector<GrBackendSemaphore> end_semaphores,
    base::OnceClosure on_finished) {
  DCHECK(!sk_surface);
  DCHECK_EQ(context_provider_, vulkan_context_provider);

  std::vector<VkSemaphore> vk_end_semaphores;
  for (const GrBackendSemaphore& gr_semaphore : end_semaphores) {
    vk_end_semaphores.push_back(
        GrBackendSemaphores::GetVkSemaphore(gr_semaphore));
  }
  vulkan_context_provider->EnqueueSecondaryCBSemaphores(
      std::move(vk_end_semaphores));
  if (on_finished) {
    vulkan_context_provider->EnqueueSecondaryCBPostSubmitTask(
        std::move(on_finished));
  }
  vulkan_context_provider->GetGrSecondaryCBDrawContext()->flush();
  return GrSemaphoresSubmitted::kYes;
}

bool SkiaOutputDeviceVulkanSecondaryCB::Wait(
    SkSurface* sk_surface,
    int num_semaphores,
    const GrBackendSemaphore wait_semaphores[],
    bool delete_semaphores_after_wait) {
  DCHECK(!sk_surface);
  return context_provider_->GetGrSecondaryCBDrawContext()->wait(
      num_semaphores, wait_semaphores, delete_semaphores_after_wait);
}

bool SkiaOutputDeviceVulkanSecondaryCB::Draw(
    SkSurface* sk_surface,
    sk_sp<const GrDeferredDisplayList> ddl) {
  DCHECK(!sk_surface);
  return context_provider_->GetGrSecondaryCBDrawContext()->draw(ddl);
}

}  // namespace viz