File: wrapped_graphite_texture_backing.h

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 (118 lines) | stat: -rw-r--r-- 4,652 bytes parent folder | download | duplicates (6)
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
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef GPU_COMMAND_BUFFER_SERVICE_SHARED_IMAGE_WRAPPED_GRAPHITE_TEXTURE_BACKING_H_
#define GPU_COMMAND_BUFFER_SERVICE_SHARED_IMAGE_WRAPPED_GRAPHITE_TEXTURE_BACKING_H_

#include <memory>
#include <vector>

#include "base/containers/span.h"
#include "base/memory/scoped_refptr.h"
#include "base/types/pass_key.h"
#include "gpu/command_buffer/service/shared_context_state.h"
#include "gpu/command_buffer/service/shared_image/shared_image_backing.h"
#include "gpu/command_buffer/service/shared_image/shared_image_representation.h"
#include "gpu/command_buffer/service/shared_image/wrapped_graphite_texture_holder.h"
#include "skia/buildflags.h"
#include "third_party/skia/include/core/SkAlphaType.h"
#include "third_party/skia/include/core/SkColorType.h"
#include "third_party/skia/include/gpu/graphite/BackendTexture.h"

class SkPixmap;

namespace skgpu::graphite {
class Recorder;
}

namespace gpu {

class WrappedSkImageBackingFactory;

// Holds Skia Graphite allocated BackendTextures. Can only be accessed by
// Skia Graphite backend.
class WrappedGraphiteTextureBacking : public ClearTrackingSharedImageBacking {
 public:
  WrappedGraphiteTextureBacking(base::PassKey<WrappedSkImageBackingFactory>,
                                const Mailbox& mailbox,
                                viz::SharedImageFormat format,
                                const gfx::Size& size,
                                const gfx::ColorSpace& color_space,
                                GrSurfaceOrigin surface_origin,
                                SkAlphaType alpha_type,
                                gpu::SharedImageUsageSet usage,
                                std::string debug_label,
                                scoped_refptr<SharedContextState> context_state,
                                const bool thread_safe);

  WrappedGraphiteTextureBacking(const WrappedGraphiteTextureBacking&) = delete;
  WrappedGraphiteTextureBacking& operator=(
      const WrappedGraphiteTextureBacking&) = delete;

  ~WrappedGraphiteTextureBacking() override;

  // Initializes without pixel data.
  bool Initialize();

  // Initializes with pixel data that is uploaded to texture.
  bool InitializeWithData(base::span<const uint8_t> pixels);

  // SharedImageBacking implementation.
  SharedImageBackingType GetType() const override;
  void Update(std::unique_ptr<gfx::GpuFence> in_fence) override;
  bool UploadFromMemory(const std::vector<SkPixmap>& pixmaps) override;
  bool ReadbackToMemory(const std::vector<SkPixmap>& pixmaps) override;

 protected:
  std::unique_ptr<SkiaGraphiteImageRepresentation> ProduceSkiaGraphite(
      SharedImageManager* manager,
      MemoryTypeTracker* tracker,
      scoped_refptr<SharedContextState> context_state) override;

  // Only used for testing 1-copy path where CopySharedImageToGLTexture is
  // called via passthrough command decoder with GL context. This happens on
  // test scenarios with Graphite-Swiftshader-Vulkan backend whereas in
  // production IOSurfaceImageBacking would be used.
  std::unique_ptr<SkiaGaneshImageRepresentation> ProduceSkiaGanesh(
      SharedImageManager* manager,
      MemoryTypeTracker* tracker,
      scoped_refptr<SharedContextState> context_state) override;

#if BUILDFLAG(SKIA_USE_DAWN)
  std::unique_ptr<GLTexturePassthroughImageRepresentation>
  ProduceGLTexturePassthrough(SharedImageManager* manager,
                              MemoryTypeTracker* tracker) override;

  std::unique_ptr<DawnImageRepresentation> ProduceDawn(
      SharedImageManager* manager,
      MemoryTypeTracker* tracker,
      const wgpu::Device& device,
      wgpu::BackendType backend_type,
      std::vector<wgpu::TextureFormat> view_formats,
      scoped_refptr<SharedContextState> context_state) override;
#endif  // BUILDFLAG(SKIA_USE_DAWN)

 private:
  class SkiaGraphiteImageRepresentationImpl;

  const std::vector<
      scoped_refptr<SkiaImageRepresentation::GraphiteTextureHolder>>&
  GetWrappedGraphiteTextureHolders();
  bool InsertRecordingAndSubmit();

  skgpu::graphite::Recorder* recorder() const {
    return context_state_->gpu_main_graphite_recorder();
  }

  scoped_refptr<SharedContextState> context_state_;
  std::vector<scoped_refptr<SkiaImageRepresentation::GraphiteTextureHolder>>
      texture_holders_;

  // Only stored for thread safe backings.
  scoped_refptr<base::SingleThreadTaskRunner> created_task_runner_;
};

}  // namespace gpu

#endif  // GPU_COMMAND_BUFFER_SERVICE_SHARED_IMAGE_WRAPPED_GRAPHITE_TEXTURE_BACKING_H_