• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2016 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // RenderbufferVk.h:
7 //    Defines the class interface for RenderbufferVk, implementing RenderbufferImpl.
8 //
9 
10 #ifndef LIBANGLE_RENDERER_VULKAN_RENDERBUFFERVK_H_
11 #define LIBANGLE_RENDERER_VULKAN_RENDERBUFFERVK_H_
12 
13 #include "libANGLE/renderer/RenderbufferImpl.h"
14 #include "libANGLE/renderer/vulkan/RenderTargetVk.h"
15 #include "libANGLE/renderer/vulkan/vk_helpers.h"
16 
17 namespace rx
18 {
19 
20 class RenderbufferVk : public RenderbufferImpl, public angle::ObserverInterface
21 {
22   public:
23     RenderbufferVk(const gl::RenderbufferState &state);
24     ~RenderbufferVk() override;
25 
26     void onDestroy(const gl::Context *context) override;
27 
28     angle::Result setStorage(const gl::Context *context,
29                              GLenum internalformat,
30                              GLsizei width,
31                              GLsizei height) override;
32     angle::Result setStorageMultisample(const gl::Context *context,
33                                         GLsizei samples,
34                                         GLenum internalformat,
35                                         GLsizei width,
36                                         GLsizei height,
37                                         gl::MultisamplingMode mode) override;
38     angle::Result setStorageEGLImageTarget(const gl::Context *context, egl::Image *image) override;
39 
40     angle::Result copyRenderbufferSubData(const gl::Context *context,
41                                           const gl::Renderbuffer *srcBuffer,
42                                           GLint srcLevel,
43                                           GLint srcX,
44                                           GLint srcY,
45                                           GLint srcZ,
46                                           GLint dstLevel,
47                                           GLint dstX,
48                                           GLint dstY,
49                                           GLint dstZ,
50                                           GLsizei srcWidth,
51                                           GLsizei srcHeight,
52                                           GLsizei srcDepth) override;
53 
54     angle::Result copyTextureSubData(const gl::Context *context,
55                                      const gl::Texture *srcTexture,
56                                      GLint srcLevel,
57                                      GLint srcX,
58                                      GLint srcY,
59                                      GLint srcZ,
60                                      GLint dstLevel,
61                                      GLint dstX,
62                                      GLint dstY,
63                                      GLint dstZ,
64                                      GLsizei srcWidth,
65                                      GLsizei srcHeight,
66                                      GLsizei srcDepth) override;
67 
68     angle::Result getAttachmentRenderTarget(const gl::Context *context,
69                                             GLenum binding,
70                                             const gl::ImageIndex &imageIndex,
71                                             GLsizei samples,
72                                             FramebufferAttachmentRenderTarget **rtOut) override;
73 
74     angle::Result initializeContents(const gl::Context *context,
75                                      const gl::ImageIndex &imageIndex) override;
76 
getImage()77     vk::ImageHelper *getImage() const { return mImage; }
78     void releaseOwnershipOfImage(const gl::Context *context);
79 
80     GLenum getColorReadFormat(const gl::Context *context) override;
81     GLenum getColorReadType(const gl::Context *context) override;
82 
83     angle::Result getRenderbufferImage(const gl::Context *context,
84                                        const gl::PixelPackState &packState,
85                                        gl::Buffer *packBuffer,
86                                        GLenum format,
87                                        GLenum type,
88                                        void *pixels) override;
89 
90     angle::Result ensureImageInitialized(const gl::Context *context);
91 
92   private:
93     void releaseAndDeleteImage(ContextVk *contextVk);
94     void releaseImage(ContextVk *contextVk);
95 
96     angle::Result setStorageImpl(const gl::Context *context,
97                                  GLsizei samples,
98                                  GLenum internalformat,
99                                  GLsizei width,
100                                  GLsizei height,
101                                  gl::MultisamplingMode mode);
102 
103     const gl::InternalFormat &getImplementationSizedFormat() const;
104 
105     // We monitor the staging buffer for changes. This handles staged data from outside this class.
106     void onSubjectStateChange(angle::SubjectIndex index, angle::SubjectMessage message) override;
107 
108     bool mOwnsImage;
109 
110     // |mOwnsImage| indicates that |RenderbufferVk| owns the image.  Otherwise, this is a weak
111     // pointer shared with another class.  Due to this sharing, for example through EGL images, the
112     // image must always be dynamically allocated as the renderbuffer can release ownership for
113     // example and it can be transferred to another |RenderbufferVk|.
114     vk::ImageHelper *mImage;
115     vk::ImageViewHelper mImageViews;
116 
117     // If renderbuffer is created through the EXT_multisampled_render_to_texture API, it is expected
118     // that all rendering is done multisampled during the renderpass, and is automatically resolved
119     // (into |mImage|) and discarded afterwards.  |mMultisampledImage| is the implicit image that
120     // contains the multisampled data.
121     vk::ImageHelper mMultisampledImage;
122     vk::ImageViewHelper mMultisampledImageViews;
123 
124     RenderTargetVk mRenderTarget;
125 
126     angle::ObserverBinding mImageObserverBinding;
127 };
128 
129 }  // namespace rx
130 
131 #endif  // LIBANGLE_RENDERER_VULKAN_RENDERBUFFERVK_H_
132