1*8975f5c5SAndroid Build Coastguard Worker // 2*8975f5c5SAndroid Build Coastguard Worker // Copyright 2024 The ANGLE Project Authors. All rights reserved. 3*8975f5c5SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be 4*8975f5c5SAndroid Build Coastguard Worker // found in the LICENSE file. 5*8975f5c5SAndroid Build Coastguard Worker // 6*8975f5c5SAndroid Build Coastguard Worker // SurfaceWgpu.h: 7*8975f5c5SAndroid Build Coastguard Worker // Defines the class interface for SurfaceWgpu, implementing SurfaceImpl. 8*8975f5c5SAndroid Build Coastguard Worker // 9*8975f5c5SAndroid Build Coastguard Worker 10*8975f5c5SAndroid Build Coastguard Worker #ifndef LIBANGLE_RENDERER_WGPU_SURFACEWGPU_H_ 11*8975f5c5SAndroid Build Coastguard Worker #define LIBANGLE_RENDERER_WGPU_SURFACEWGPU_H_ 12*8975f5c5SAndroid Build Coastguard Worker 13*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/renderer/SurfaceImpl.h" 14*8975f5c5SAndroid Build Coastguard Worker 15*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/renderer/wgpu/RenderTargetWgpu.h" 16*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/renderer/wgpu/wgpu_helpers.h" 17*8975f5c5SAndroid Build Coastguard Worker 18*8975f5c5SAndroid Build Coastguard Worker #include <dawn/webgpu_cpp.h> 19*8975f5c5SAndroid Build Coastguard Worker 20*8975f5c5SAndroid Build Coastguard Worker namespace rx 21*8975f5c5SAndroid Build Coastguard Worker { 22*8975f5c5SAndroid Build Coastguard Worker 23*8975f5c5SAndroid Build Coastguard Worker class SurfaceWgpu : public SurfaceImpl 24*8975f5c5SAndroid Build Coastguard Worker { 25*8975f5c5SAndroid Build Coastguard Worker public: 26*8975f5c5SAndroid Build Coastguard Worker SurfaceWgpu(const egl::SurfaceState &surfaceState); 27*8975f5c5SAndroid Build Coastguard Worker ~SurfaceWgpu() override; 28*8975f5c5SAndroid Build Coastguard Worker 29*8975f5c5SAndroid Build Coastguard Worker protected: 30*8975f5c5SAndroid Build Coastguard Worker struct AttachmentImage 31*8975f5c5SAndroid Build Coastguard Worker { 32*8975f5c5SAndroid Build Coastguard Worker webgpu::ImageHelper texture; 33*8975f5c5SAndroid Build Coastguard Worker RenderTargetWgpu renderTarget; 34*8975f5c5SAndroid Build Coastguard Worker }; 35*8975f5c5SAndroid Build Coastguard Worker angle::Result createDepthStencilAttachment(uint32_t width, 36*8975f5c5SAndroid Build Coastguard Worker uint32_t height, 37*8975f5c5SAndroid Build Coastguard Worker const webgpu::Format &webgpuFormat, 38*8975f5c5SAndroid Build Coastguard Worker wgpu::Device &device, 39*8975f5c5SAndroid Build Coastguard Worker AttachmentImage *outDepthStencilAttachment); 40*8975f5c5SAndroid Build Coastguard Worker }; 41*8975f5c5SAndroid Build Coastguard Worker 42*8975f5c5SAndroid Build Coastguard Worker class OffscreenSurfaceWgpu : public SurfaceWgpu 43*8975f5c5SAndroid Build Coastguard Worker { 44*8975f5c5SAndroid Build Coastguard Worker public: 45*8975f5c5SAndroid Build Coastguard Worker OffscreenSurfaceWgpu(const egl::SurfaceState &surfaceState); 46*8975f5c5SAndroid Build Coastguard Worker ~OffscreenSurfaceWgpu() override; 47*8975f5c5SAndroid Build Coastguard Worker 48*8975f5c5SAndroid Build Coastguard Worker egl::Error initialize(const egl::Display *display) override; 49*8975f5c5SAndroid Build Coastguard Worker egl::Error swap(const gl::Context *context) override; 50*8975f5c5SAndroid Build Coastguard Worker egl::Error bindTexImage(const gl::Context *context, 51*8975f5c5SAndroid Build Coastguard Worker gl::Texture *texture, 52*8975f5c5SAndroid Build Coastguard Worker EGLint buffer) override; 53*8975f5c5SAndroid Build Coastguard Worker egl::Error releaseTexImage(const gl::Context *context, EGLint buffer) override; 54*8975f5c5SAndroid Build Coastguard Worker void setSwapInterval(const egl::Display *display, EGLint interval) override; 55*8975f5c5SAndroid Build Coastguard Worker 56*8975f5c5SAndroid Build Coastguard Worker // width and height can change with client window resizing 57*8975f5c5SAndroid Build Coastguard Worker EGLint getWidth() const override; 58*8975f5c5SAndroid Build Coastguard Worker EGLint getHeight() const override; 59*8975f5c5SAndroid Build Coastguard Worker 60*8975f5c5SAndroid Build Coastguard Worker EGLint getSwapBehavior() const override; 61*8975f5c5SAndroid Build Coastguard Worker 62*8975f5c5SAndroid Build Coastguard Worker angle::Result initializeContents(const gl::Context *context, 63*8975f5c5SAndroid Build Coastguard Worker GLenum binding, 64*8975f5c5SAndroid Build Coastguard Worker const gl::ImageIndex &imageIndex) override; 65*8975f5c5SAndroid Build Coastguard Worker 66*8975f5c5SAndroid Build Coastguard Worker egl::Error attachToFramebuffer(const gl::Context *context, 67*8975f5c5SAndroid Build Coastguard Worker gl::Framebuffer *framebuffer) override; 68*8975f5c5SAndroid Build Coastguard Worker egl::Error detachFromFramebuffer(const gl::Context *context, 69*8975f5c5SAndroid Build Coastguard Worker gl::Framebuffer *framebuffer) override; 70*8975f5c5SAndroid Build Coastguard Worker 71*8975f5c5SAndroid Build Coastguard Worker angle::Result getAttachmentRenderTarget(const gl::Context *context, 72*8975f5c5SAndroid Build Coastguard Worker GLenum binding, 73*8975f5c5SAndroid Build Coastguard Worker const gl::ImageIndex &imageIndex, 74*8975f5c5SAndroid Build Coastguard Worker GLsizei samples, 75*8975f5c5SAndroid Build Coastguard Worker FramebufferAttachmentRenderTarget **rtOut) override; 76*8975f5c5SAndroid Build Coastguard Worker 77*8975f5c5SAndroid Build Coastguard Worker private: 78*8975f5c5SAndroid Build Coastguard Worker angle::Result initializeImpl(const egl::Display *display); 79*8975f5c5SAndroid Build Coastguard Worker 80*8975f5c5SAndroid Build Coastguard Worker EGLint mWidth; 81*8975f5c5SAndroid Build Coastguard Worker EGLint mHeight; 82*8975f5c5SAndroid Build Coastguard Worker 83*8975f5c5SAndroid Build Coastguard Worker AttachmentImage mColorAttachment; 84*8975f5c5SAndroid Build Coastguard Worker AttachmentImage mDepthStencilAttachment; 85*8975f5c5SAndroid Build Coastguard Worker }; 86*8975f5c5SAndroid Build Coastguard Worker 87*8975f5c5SAndroid Build Coastguard Worker class WindowSurfaceWgpu : public SurfaceWgpu 88*8975f5c5SAndroid Build Coastguard Worker { 89*8975f5c5SAndroid Build Coastguard Worker public: 90*8975f5c5SAndroid Build Coastguard Worker WindowSurfaceWgpu(const egl::SurfaceState &surfaceState, EGLNativeWindowType window); 91*8975f5c5SAndroid Build Coastguard Worker ~WindowSurfaceWgpu() override; 92*8975f5c5SAndroid Build Coastguard Worker 93*8975f5c5SAndroid Build Coastguard Worker egl::Error initialize(const egl::Display *display) override; 94*8975f5c5SAndroid Build Coastguard Worker void destroy(const egl::Display *display) override; 95*8975f5c5SAndroid Build Coastguard Worker egl::Error swap(const gl::Context *context) override; 96*8975f5c5SAndroid Build Coastguard Worker egl::Error bindTexImage(const gl::Context *context, 97*8975f5c5SAndroid Build Coastguard Worker gl::Texture *texture, 98*8975f5c5SAndroid Build Coastguard Worker EGLint buffer) override; 99*8975f5c5SAndroid Build Coastguard Worker egl::Error releaseTexImage(const gl::Context *context, EGLint buffer) override; 100*8975f5c5SAndroid Build Coastguard Worker void setSwapInterval(const egl::Display *display, EGLint interval) override; 101*8975f5c5SAndroid Build Coastguard Worker 102*8975f5c5SAndroid Build Coastguard Worker // width and height can change with client window resizing 103*8975f5c5SAndroid Build Coastguard Worker EGLint getWidth() const override; 104*8975f5c5SAndroid Build Coastguard Worker EGLint getHeight() const override; 105*8975f5c5SAndroid Build Coastguard Worker 106*8975f5c5SAndroid Build Coastguard Worker EGLint getSwapBehavior() const override; 107*8975f5c5SAndroid Build Coastguard Worker 108*8975f5c5SAndroid Build Coastguard Worker angle::Result initializeContents(const gl::Context *context, 109*8975f5c5SAndroid Build Coastguard Worker GLenum binding, 110*8975f5c5SAndroid Build Coastguard Worker const gl::ImageIndex &imageIndex) override; 111*8975f5c5SAndroid Build Coastguard Worker 112*8975f5c5SAndroid Build Coastguard Worker egl::Error attachToFramebuffer(const gl::Context *context, 113*8975f5c5SAndroid Build Coastguard Worker gl::Framebuffer *framebuffer) override; 114*8975f5c5SAndroid Build Coastguard Worker egl::Error detachFromFramebuffer(const gl::Context *context, 115*8975f5c5SAndroid Build Coastguard Worker gl::Framebuffer *framebuffer) override; 116*8975f5c5SAndroid Build Coastguard Worker 117*8975f5c5SAndroid Build Coastguard Worker angle::Result getAttachmentRenderTarget(const gl::Context *context, 118*8975f5c5SAndroid Build Coastguard Worker GLenum binding, 119*8975f5c5SAndroid Build Coastguard Worker const gl::ImageIndex &imageIndex, 120*8975f5c5SAndroid Build Coastguard Worker GLsizei samples, 121*8975f5c5SAndroid Build Coastguard Worker FramebufferAttachmentRenderTarget **rtOut) override; 122*8975f5c5SAndroid Build Coastguard Worker 123*8975f5c5SAndroid Build Coastguard Worker protected: getNativeWindow()124*8975f5c5SAndroid Build Coastguard Worker EGLNativeWindowType getNativeWindow() const { return mNativeWindow; } 125*8975f5c5SAndroid Build Coastguard Worker 126*8975f5c5SAndroid Build Coastguard Worker private: 127*8975f5c5SAndroid Build Coastguard Worker angle::Result initializeImpl(const egl::Display *display); 128*8975f5c5SAndroid Build Coastguard Worker 129*8975f5c5SAndroid Build Coastguard Worker angle::Result swapImpl(const gl::Context *context); 130*8975f5c5SAndroid Build Coastguard Worker 131*8975f5c5SAndroid Build Coastguard Worker angle::Result configureSurface(const egl::Display *display, const gl::Extents &size); 132*8975f5c5SAndroid Build Coastguard Worker angle::Result updateCurrentTexture(const egl::Display *display); 133*8975f5c5SAndroid Build Coastguard Worker 134*8975f5c5SAndroid Build Coastguard Worker virtual angle::Result createWgpuSurface(const egl::Display *display, 135*8975f5c5SAndroid Build Coastguard Worker wgpu::Surface *outSurface) = 0; 136*8975f5c5SAndroid Build Coastguard Worker virtual angle::Result getCurrentWindowSize(const egl::Display *display, 137*8975f5c5SAndroid Build Coastguard Worker gl::Extents *outSize) = 0; 138*8975f5c5SAndroid Build Coastguard Worker 139*8975f5c5SAndroid Build Coastguard Worker EGLNativeWindowType mNativeWindow; 140*8975f5c5SAndroid Build Coastguard Worker wgpu::Surface mSurface; 141*8975f5c5SAndroid Build Coastguard Worker 142*8975f5c5SAndroid Build Coastguard Worker const webgpu::Format *mSurfaceTextureFormat = nullptr; 143*8975f5c5SAndroid Build Coastguard Worker wgpu::TextureUsage mSurfaceTextureUsage; 144*8975f5c5SAndroid Build Coastguard Worker wgpu::PresentMode mPresentMode; 145*8975f5c5SAndroid Build Coastguard Worker 146*8975f5c5SAndroid Build Coastguard Worker const webgpu::Format *mDepthStencilFormat = nullptr; 147*8975f5c5SAndroid Build Coastguard Worker 148*8975f5c5SAndroid Build Coastguard Worker gl::Extents mCurrentSurfaceSize; 149*8975f5c5SAndroid Build Coastguard Worker 150*8975f5c5SAndroid Build Coastguard Worker AttachmentImage mColorAttachment; 151*8975f5c5SAndroid Build Coastguard Worker AttachmentImage mDepthStencilAttachment; 152*8975f5c5SAndroid Build Coastguard Worker }; 153*8975f5c5SAndroid Build Coastguard Worker 154*8975f5c5SAndroid Build Coastguard Worker WindowSurfaceWgpu *CreateWgpuWindowSurface(const egl::SurfaceState &surfaceState, 155*8975f5c5SAndroid Build Coastguard Worker EGLNativeWindowType window); 156*8975f5c5SAndroid Build Coastguard Worker 157*8975f5c5SAndroid Build Coastguard Worker } // namespace rx 158*8975f5c5SAndroid Build Coastguard Worker 159*8975f5c5SAndroid Build Coastguard Worker #endif // LIBANGLE_RENDERER_WGPU_SURFACEWGPU_H_ 160