• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2019 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 // SurfaceMtl.h: Defines the class interface for Metal Surface.
7 
8 #ifndef LIBANGLE_RENDERER_METAL_SURFACEMTL_H_
9 #define LIBANGLE_RENDERER_METAL_SURFACEMTL_H_
10 
11 #import <Metal/Metal.h>
12 #import <QuartzCore/CALayer.h>
13 #import <QuartzCore/CAMetalLayer.h>
14 
15 #include "libANGLE/renderer/FramebufferImpl.h"
16 #include "libANGLE/renderer/SurfaceImpl.h"
17 #include "libANGLE/renderer/metal/RenderTargetMtl.h"
18 #include "libANGLE/renderer/metal/mtl_format_utils.h"
19 #include "libANGLE/renderer/metal/mtl_resources.h"
20 #include "libANGLE/renderer/metal/mtl_state_cache.h"
21 
22 namespace rx
23 {
24 
25 class DisplayMtl;
26 
27 class SurfaceMtl : public SurfaceImpl
28 {
29   public:
30     SurfaceMtl(DisplayMtl *display,
31                const egl::SurfaceState &state,
32                EGLNativeWindowType window,
33                const egl::AttributeMap &attribs);
34     ~SurfaceMtl() override;
35 
36     void destroy(const egl::Display *display) override;
37 
38     egl::Error initialize(const egl::Display *display) override;
39     FramebufferImpl *createDefaultFramebuffer(const gl::Context *context,
40                                               const gl::FramebufferState &state) override;
41 
42     egl::Error makeCurrent(const gl::Context *context) override;
43     egl::Error unMakeCurrent(const gl::Context *context) override;
44     egl::Error swap(const gl::Context *context) override;
45     egl::Error postSubBuffer(const gl::Context *context,
46                              EGLint x,
47                              EGLint y,
48                              EGLint width,
49                              EGLint height) override;
50 
51     egl::Error querySurfacePointerANGLE(EGLint attribute, void **value) override;
52     egl::Error bindTexImage(const gl::Context *context,
53                             gl::Texture *texture,
54                             EGLint buffer) override;
55     egl::Error releaseTexImage(const gl::Context *context, EGLint buffer) override;
56     egl::Error getSyncValues(EGLuint64KHR *ust, EGLuint64KHR *msc, EGLuint64KHR *sbc) override;
57     egl::Error getMscRate(EGLint *numerator, EGLint *denominator) override;
58     void setSwapInterval(EGLint interval) override;
59     void setFixedWidth(EGLint width) override;
60     void setFixedHeight(EGLint height) override;
61 
62     // width and height can change with client window resizing
63     EGLint getWidth() const override;
64     EGLint getHeight() const override;
65 
66     EGLint isPostSubBufferSupported() const override;
67     EGLint getSwapBehavior() const override;
68 
69     angle::Result getAttachmentRenderTarget(const gl::Context *context,
70                                             GLenum binding,
71                                             const gl::ImageIndex &imageIndex,
72                                             GLsizei samples,
73                                             FramebufferAttachmentRenderTarget **rtOut) override;
74 
75   private:
76     angle::Result swapImpl(const gl::Context *context);
77     angle::Result ensureRenderTargetsCreated(const gl::Context *context);
78     angle::Result obtainNextDrawable(const gl::Context *context);
79     angle::Result ensureDepthStencilSizeCorrect(const gl::Context *context,
80                                                 gl::Framebuffer::DirtyBits *fboDirtyBits);
81     // Check if metal layer has been resized.
82     void checkIfLayerResized();
83 
84     mtl::AutoObjCObj<CAMetalLayer> mMetalLayer = nil;
85     CALayer *mLayer;
86     mtl::AutoObjCPtr<id<CAMetalDrawable>> mCurrentDrawable = nil;
87     mtl::TextureRef mDrawableTexture;
88     mtl::TextureRef mDepthTexture;
89     mtl::TextureRef mStencilTexture;
90     bool mUsePackedDepthStencil = false;
91 
92     mtl::Format mColorFormat;
93     mtl::Format mDepthFormat;
94     mtl::Format mStencilFormat;
95 
96     RenderTargetMtl mColorRenderTarget;
97     RenderTargetMtl mDepthRenderTarget;
98     RenderTargetMtl mStencilRenderTarget;
99 };
100 
101 }  // namespace rx
102 
103 #endif /* LIBANGLE_RENDERER_METAL_SURFACEMTL_H_ */
104