• 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 // DisplayMtl.h:
7 //    Defines the class interface for DisplayMtl, implementing DisplayImpl.
8 //
9 
10 #ifndef LIBANGLE_RENDERER_METAL_DISPLAYMTL_H_
11 #define LIBANGLE_RENDERER_METAL_DISPLAYMTL_H_
12 
13 #include "common/PackedEnums.h"
14 #include "libANGLE/angletypes.h"
15 #include "libANGLE/renderer/DisplayImpl.h"
16 #include "libANGLE/renderer/metal/mtl_command_buffer.h"
17 #include "libANGLE/renderer/metal/mtl_format_utils.h"
18 #include "libANGLE/renderer/metal/mtl_render_utils.h"
19 #include "libANGLE/renderer/metal/mtl_state_cache.h"
20 #include "libANGLE/renderer/metal/mtl_utils.h"
21 #include "platform/FeaturesMtl.h"
22 
23 namespace egl
24 {
25 class Surface;
26 }
27 
28 namespace rx
29 {
30 class ContextMtl;
31 
32 class DisplayMtl : public DisplayImpl
33 {
34   public:
35     DisplayMtl(const egl::DisplayState &state);
36     ~DisplayMtl() override;
37 
38     egl::Error initialize(egl::Display *display) override;
39     void terminate() override;
40 
41     bool testDeviceLost() override;
42     egl::Error restoreLostDevice(const egl::Display *display) override;
43 
44     std::string getVendorString() const override;
45 
46     DeviceImpl *createDevice() override;
47 
48     egl::Error waitClient(const gl::Context *context) override;
49     egl::Error waitNative(const gl::Context *context, EGLint engine) override;
50 
51     SurfaceImpl *createWindowSurface(const egl::SurfaceState &state,
52                                      EGLNativeWindowType window,
53                                      const egl::AttributeMap &attribs) override;
54     SurfaceImpl *createPbufferSurface(const egl::SurfaceState &state,
55                                       const egl::AttributeMap &attribs) override;
56     SurfaceImpl *createPbufferFromClientBuffer(const egl::SurfaceState &state,
57                                                EGLenum buftype,
58                                                EGLClientBuffer clientBuffer,
59                                                const egl::AttributeMap &attribs) override;
60     SurfaceImpl *createPixmapSurface(const egl::SurfaceState &state,
61                                      NativePixmapType nativePixmap,
62                                      const egl::AttributeMap &attribs) override;
63 
64     ImageImpl *createImage(const egl::ImageState &state,
65                            const gl::Context *context,
66                            EGLenum target,
67                            const egl::AttributeMap &attribs) override;
68 
69     ContextImpl *createContext(const gl::State &state,
70                                gl::ErrorSet *errorSet,
71                                const egl::Config *configuration,
72                                const gl::Context *shareContext,
73                                const egl::AttributeMap &attribs) override;
74 
75     StreamProducerImpl *createStreamProducerD3DTexture(egl::Stream::ConsumerType consumerType,
76                                                        const egl::AttributeMap &attribs) override;
77 
78     gl::Version getMaxSupportedESVersion() const override;
79     gl::Version getMaxConformantESVersion() const override;
80 
81     EGLSyncImpl *createSync(const egl::AttributeMap &attribs) override;
82 
83     egl::Error makeCurrent(egl::Surface *drawSurface,
84                            egl::Surface *readSurface,
85                            gl::Context *context) override;
86 
87     void populateFeatureList(angle::FeatureList *features) override;
88 
89     bool isValidNativeWindow(EGLNativeWindowType window) const override;
90 
91     egl::ConfigSet generateConfigs() override;
92 
93     std::string getRendererDescription() const;
94     gl::Caps getNativeCaps() const;
95     const gl::TextureCapsMap &getNativeTextureCaps() const;
96     const gl::Extensions &getNativeExtensions() const;
getNativeLimitations()97     const gl::Limitations &getNativeLimitations() const { return mNativeLimitations; }
getFeatures()98     const angle::FeaturesMtl &getFeatures() const { return mFeatures; }
99 
getMetalDevice()100     id<MTLDevice> getMetalDevice() const { return mMetalDevice; }
101 
cmdQueue()102     mtl::CommandQueue &cmdQueue() { return mCmdQueue; }
getFormatTable()103     const mtl::FormatTable &getFormatTable() const { return mFormatTable; }
getUtils()104     mtl::RenderUtils &getUtils() { return mUtils; }
getStateCache()105     mtl::StateCache &getStateCache() { return mStateCache; }
106 
getDepthStencilState(const mtl::DepthStencilDesc & desc)107     id<MTLDepthStencilState> getDepthStencilState(const mtl::DepthStencilDesc &desc)
108     {
109         return mStateCache.getDepthStencilState(getMetalDevice(), desc);
110     }
getSamplerState(const mtl::SamplerDesc & desc)111     id<MTLSamplerState> getSamplerState(const mtl::SamplerDesc &desc)
112     {
113         return mStateCache.getSamplerState(getMetalDevice(), desc);
114     }
115 
116     const mtl::TextureRef &getNullTexture(const gl::Context *context, gl::TextureType type);
117 
getPixelFormat(angle::FormatID angleFormatId)118     const mtl::Format &getPixelFormat(angle::FormatID angleFormatId) const
119     {
120         return mFormatTable.getPixelFormat(angleFormatId);
121     }
122 
123     // See mtl::FormatTable::getVertexFormat()
getVertexFormat(angle::FormatID angleFormatId,bool tightlyPacked)124     const mtl::VertexFormat &getVertexFormat(angle::FormatID angleFormatId,
125                                              bool tightlyPacked) const
126     {
127         return mFormatTable.getVertexFormat(angleFormatId, tightlyPacked);
128     }
129 
130   protected:
131     void generateExtensions(egl::DisplayExtensions *outExtensions) const override;
132     void generateCaps(egl::Caps *outCaps) const override;
133 
134   private:
135     angle::Result initializeImpl(egl::Display *display);
136     void ensureCapsInitialized() const;
137     void initializeCaps() const;
138     void initializeExtensions() const;
139     void initializeTextureCaps() const;
140     void initializeFeatures();
141 
142     mtl::AutoObjCPtr<id<MTLDevice>> mMetalDevice = nil;
143 
144     mtl::CommandQueue mCmdQueue;
145 
146     mtl::FormatTable mFormatTable;
147     mtl::StateCache mStateCache;
148     mtl::RenderUtils mUtils;
149 
150     angle::PackedEnumMap<gl::TextureType, mtl::TextureRef> mNullTextures;
151 
152     mutable bool mCapsInitialized;
153     mutable gl::TextureCapsMap mNativeTextureCaps;
154     mutable gl::Extensions mNativeExtensions;
155     mutable gl::Caps mNativeCaps;
156     mutable gl::Limitations mNativeLimitations;
157 
158     angle::FeaturesMtl mFeatures;
159 
160     // track whether we initialized (or released) glslang
161     bool mGlslangInitialized;
162 };
163 
164 }  // namespace rx
165 
166 #endif /* LIBANGLE_RENDERER_METAL_DISPLAYMTL_H_ */
167