summaryrefslogtreecommitdiff
path: root/chromium/gpu/command_buffer/service/external_vk_image_gl_representation.h
blob: 8fa45fffc34ef61ac9853ec8d2f38db755cc52ff (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
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
// Copyright 2019 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_COMMAND_BUFFER_SERVICE_EXTERNAL_VK_IMAGE_GL_REPRESENTATION_H_
#define GPU_COMMAND_BUFFER_SERVICE_EXTERNAL_VK_IMAGE_GL_REPRESENTATION_H_

#include <memory>

#include "gpu/command_buffer/service/external_vk_image_backing.h"
#include "gpu/command_buffer/service/shared_image_representation.h"

namespace gpu {

// ExternalVkImageGLRepresentationShared implements BeginAccess and EndAccess
// methods for ExternalVkImageGLRepresentation and
// ExternalVkImageGLPassthroughRepresentation.
class ExternalVkImageGLRepresentationShared {
 public:
  ExternalVkImageGLRepresentationShared(SharedImageBacking* backing,
                                        GLuint texture_service_id);
  ~ExternalVkImageGLRepresentationShared() = default;

  bool BeginAccess(GLenum mode);
  void EndAccess();

  ExternalVkImageBacking* backing_impl() { return backing_; }

 private:
  gpu::VulkanImplementation* vk_implementation() {
    return backing_impl()
        ->context_state()
        ->vk_context_provider()
        ->GetVulkanImplementation();
  }

  VkDevice vk_device() {
    return backing_impl()
        ->context_state()
        ->vk_context_provider()
        ->GetDeviceQueue()
        ->GetVulkanDevice();
  }

  VkQueue vk_queue() {
    return backing_impl()
        ->context_state()
        ->vk_context_provider()
        ->GetDeviceQueue()
        ->GetVulkanQueue();
  }

  gl::GLApi* api() { return gl::g_current_gl_context; }

  GLuint ImportVkSemaphoreIntoGL(SemaphoreHandle handle);
  void DestroyEndAccessSemaphore();

  ExternalVkImageBacking* backing_;
  GLuint texture_service_id_ = 0;
  GLenum current_access_mode_ = 0;

  DISALLOW_COPY_AND_ASSIGN(ExternalVkImageGLRepresentationShared);
};

class ExternalVkImageGLRepresentation
    : public SharedImageRepresentationGLTexture {
 public:
  ExternalVkImageGLRepresentation(SharedImageManager* manager,
                                  SharedImageBacking* backing,
                                  MemoryTypeTracker* tracker,
                                  gles2::Texture* texture,
                                  GLuint texture_service_id);
  ~ExternalVkImageGLRepresentation() override;

  // SharedImageRepresentationGLTexture implementation.
  gles2::Texture* GetTexture() override;
  bool BeginAccess(GLenum mode) override;
  void EndAccess() override;

 private:
  gles2::Texture* texture_ = nullptr;
  ExternalVkImageGLRepresentationShared representation_shared_;

  DISALLOW_COPY_AND_ASSIGN(ExternalVkImageGLRepresentation);
};

class ExternalVkImageGLPassthroughRepresentation
    : public SharedImageRepresentationGLTexturePassthrough {
 public:
  ExternalVkImageGLPassthroughRepresentation(SharedImageManager* manager,
                                             SharedImageBacking* backing,
                                             MemoryTypeTracker* tracker,
                                             GLuint texture_service_id);
  ~ExternalVkImageGLPassthroughRepresentation() override;

  // SharedImageRepresentationGLTexturePassthrough implementation.
  const scoped_refptr<gles2::TexturePassthrough>& GetTexturePassthrough()
      override;
  bool BeginAccess(GLenum mode) override;
  void EndAccess() override;

 private:
  ExternalVkImageGLRepresentationShared representation_shared_;

  DISALLOW_COPY_AND_ASSIGN(ExternalVkImageGLPassthroughRepresentation);
};

}  // namespace gpu

#endif  // GPU_COMMAND_BUFFER_SERVICE_EXTERNAL_VK_IMAGE_GL_REPRESENTATION_H_