1cb93a386Sopenharmony_ci// 2cb93a386Sopenharmony_ci// Copyright 2002 The ANGLE Project Authors. All rights reserved. 3cb93a386Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be 4cb93a386Sopenharmony_ci// found in the LICENSE file. 5cb93a386Sopenharmony_ci// 6cb93a386Sopenharmony_ci 7cb93a386Sopenharmony_ci// Surface.h: Defines the egl::Surface class, representing a drawing surface 8cb93a386Sopenharmony_ci// such as the client area of a window, including any back buffers. 9cb93a386Sopenharmony_ci// Implements EGLSurface and related functionality. [EGL 1.4] section 2.2 page 3. 10cb93a386Sopenharmony_ci 11cb93a386Sopenharmony_ci#ifndef LIBANGLE_SURFACE_H_ 12cb93a386Sopenharmony_ci#define LIBANGLE_SURFACE_H_ 13cb93a386Sopenharmony_ci 14cb93a386Sopenharmony_ci#include <EGL/egl.h> 15cb93a386Sopenharmony_ci 16cb93a386Sopenharmony_ci#include "common/PackedEnums.h" 17cb93a386Sopenharmony_ci#include "common/angleutils.h" 18cb93a386Sopenharmony_ci#include "libANGLE/AttributeMap.h" 19cb93a386Sopenharmony_ci#include "libANGLE/Debug.h" 20cb93a386Sopenharmony_ci#include "libANGLE/Error.h" 21cb93a386Sopenharmony_ci#include "libANGLE/FramebufferAttachment.h" 22cb93a386Sopenharmony_ci#include "libANGLE/RefCountObject.h" 23cb93a386Sopenharmony_ci#include "libANGLE/formatutils.h" 24cb93a386Sopenharmony_ci#include "libANGLE/renderer/SurfaceImpl.h" 25cb93a386Sopenharmony_ci 26cb93a386Sopenharmony_cinamespace gl 27cb93a386Sopenharmony_ci{ 28cb93a386Sopenharmony_ciclass Context; 29cb93a386Sopenharmony_ciclass Framebuffer; 30cb93a386Sopenharmony_ciclass Texture; 31cb93a386Sopenharmony_ci} // namespace gl 32cb93a386Sopenharmony_ci 33cb93a386Sopenharmony_cinamespace rx 34cb93a386Sopenharmony_ci{ 35cb93a386Sopenharmony_ciclass EGLImplFactory; 36cb93a386Sopenharmony_ci} 37cb93a386Sopenharmony_ci 38cb93a386Sopenharmony_cinamespace egl 39cb93a386Sopenharmony_ci{ 40cb93a386Sopenharmony_ciclass Display; 41cb93a386Sopenharmony_cistruct Config; 42cb93a386Sopenharmony_ci 43cb93a386Sopenharmony_ciusing SupportedCompositorTiming = angle::PackedEnumBitSet<CompositorTiming>; 44cb93a386Sopenharmony_ciusing SupportedTimestamps = angle::PackedEnumBitSet<Timestamp>; 45cb93a386Sopenharmony_ci 46cb93a386Sopenharmony_cistruct SurfaceState final : private angle::NonCopyable 47cb93a386Sopenharmony_ci{ 48cb93a386Sopenharmony_ci SurfaceState(const egl::Config *configIn, const AttributeMap &attributesIn); 49cb93a386Sopenharmony_ci ~SurfaceState(); 50cb93a386Sopenharmony_ci 51cb93a386Sopenharmony_ci bool isRobustResourceInitEnabled() const; 52cb93a386Sopenharmony_ci bool hasProtectedContent() const; 53cb93a386Sopenharmony_ci EGLint getPreferredSwapInterval() const; 54cb93a386Sopenharmony_ci 55cb93a386Sopenharmony_ci EGLLabelKHR label; 56cb93a386Sopenharmony_ci const egl::Config *config; 57cb93a386Sopenharmony_ci AttributeMap attributes; 58cb93a386Sopenharmony_ci 59cb93a386Sopenharmony_ci bool timestampsEnabled; 60cb93a386Sopenharmony_ci SupportedCompositorTiming supportedCompositorTimings; 61cb93a386Sopenharmony_ci SupportedTimestamps supportedTimestamps; 62cb93a386Sopenharmony_ci bool directComposition; 63cb93a386Sopenharmony_ci}; 64cb93a386Sopenharmony_ci 65cb93a386Sopenharmony_ciclass Surface : public LabeledObject, public gl::FramebufferAttachmentObject 66cb93a386Sopenharmony_ci{ 67cb93a386Sopenharmony_ci public: 68cb93a386Sopenharmony_ci rx::SurfaceImpl *getImplementation() const { return mImplementation; } 69cb93a386Sopenharmony_ci 70cb93a386Sopenharmony_ci void setLabel(EGLLabelKHR label) override; 71cb93a386Sopenharmony_ci EGLLabelKHR getLabel() const override; 72cb93a386Sopenharmony_ci 73cb93a386Sopenharmony_ci EGLint getType() const; 74cb93a386Sopenharmony_ci 75cb93a386Sopenharmony_ci Error initialize(const Display *display); 76cb93a386Sopenharmony_ci Error makeCurrent(const gl::Context *context); 77cb93a386Sopenharmony_ci Error unMakeCurrent(const gl::Context *context); 78cb93a386Sopenharmony_ci Error swap(const gl::Context *context); 79cb93a386Sopenharmony_ci Error swapWithDamage(const gl::Context *context, const EGLint *rects, EGLint n_rects); 80cb93a386Sopenharmony_ci Error swapWithFrameToken(const gl::Context *context, EGLFrameTokenANGLE frameToken); 81cb93a386Sopenharmony_ci Error postSubBuffer(const gl::Context *context, 82cb93a386Sopenharmony_ci EGLint x, 83cb93a386Sopenharmony_ci EGLint y, 84cb93a386Sopenharmony_ci EGLint width, 85cb93a386Sopenharmony_ci EGLint height); 86cb93a386Sopenharmony_ci Error setPresentationTime(EGLnsecsANDROID time); 87cb93a386Sopenharmony_ci Error querySurfacePointerANGLE(EGLint attribute, void **value); 88cb93a386Sopenharmony_ci Error bindTexImage(gl::Context *context, gl::Texture *texture, EGLint buffer); 89cb93a386Sopenharmony_ci Error releaseTexImage(const gl::Context *context, EGLint buffer); 90cb93a386Sopenharmony_ci 91cb93a386Sopenharmony_ci Error getSyncValues(EGLuint64KHR *ust, EGLuint64KHR *msc, EGLuint64KHR *sbc); 92cb93a386Sopenharmony_ci Error getMscRate(EGLint *numerator, EGLint *denominator); 93cb93a386Sopenharmony_ci 94cb93a386Sopenharmony_ci EGLint isPostSubBufferSupported() const; 95cb93a386Sopenharmony_ci 96cb93a386Sopenharmony_ci void setSwapInterval(EGLint interval); 97cb93a386Sopenharmony_ci Error onDestroy(const Display *display); 98cb93a386Sopenharmony_ci 99cb93a386Sopenharmony_ci void setMipmapLevel(EGLint level); 100cb93a386Sopenharmony_ci void setMultisampleResolve(EGLenum resolve); 101cb93a386Sopenharmony_ci void setSwapBehavior(EGLenum behavior); 102cb93a386Sopenharmony_ci 103cb93a386Sopenharmony_ci void setFixedWidth(EGLint width); 104cb93a386Sopenharmony_ci void setFixedHeight(EGLint height); 105cb93a386Sopenharmony_ci 106cb93a386Sopenharmony_ci gl::Framebuffer *createDefaultFramebuffer(const gl::Context *context, 107cb93a386Sopenharmony_ci egl::Surface *readSurface); 108cb93a386Sopenharmony_ci 109cb93a386Sopenharmony_ci const Config *getConfig() const; 110cb93a386Sopenharmony_ci 111cb93a386Sopenharmony_ci // width and height can change with client window resizing 112cb93a386Sopenharmony_ci EGLint getWidth() const; 113cb93a386Sopenharmony_ci EGLint getHeight() const; 114cb93a386Sopenharmony_ci // Note: windows cannot be resized on Android. The approach requires 115cb93a386Sopenharmony_ci // calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR. However, that is 116cb93a386Sopenharmony_ci // expensive; and there are troublesome timing issues for other parts of 117cb93a386Sopenharmony_ci // ANGLE (which cause test failures and crashes). Therefore, a 118cb93a386Sopenharmony_ci // special-Android-only path is created just for the querying of EGL_WIDTH 119cb93a386Sopenharmony_ci // and EGL_HEIGHT. 120cb93a386Sopenharmony_ci // https://issuetracker.google.com/issues/153329980 121cb93a386Sopenharmony_ci egl::Error getUserWidth(const egl::Display *display, EGLint *value) const; 122cb93a386Sopenharmony_ci egl::Error getUserHeight(const egl::Display *display, EGLint *value) const; 123cb93a386Sopenharmony_ci EGLint getPixelAspectRatio() const; 124cb93a386Sopenharmony_ci EGLenum getRenderBuffer() const; 125cb93a386Sopenharmony_ci EGLenum getSwapBehavior() const; 126cb93a386Sopenharmony_ci TextureFormat getTextureFormat() const; 127cb93a386Sopenharmony_ci EGLenum getTextureTarget() const; 128cb93a386Sopenharmony_ci bool getLargestPbuffer() const; 129cb93a386Sopenharmony_ci EGLenum getGLColorspace() const; 130cb93a386Sopenharmony_ci EGLenum getVGAlphaFormat() const; 131cb93a386Sopenharmony_ci EGLenum getVGColorspace() const; 132cb93a386Sopenharmony_ci bool getMipmapTexture() const; 133cb93a386Sopenharmony_ci EGLint getMipmapLevel() const; 134cb93a386Sopenharmony_ci EGLint getHorizontalResolution() const; 135cb93a386Sopenharmony_ci EGLint getVerticalResolution() const; 136cb93a386Sopenharmony_ci EGLenum getMultisampleResolve() const; 137cb93a386Sopenharmony_ci bool hasProtectedContent() const override; 138cb93a386Sopenharmony_ci 139cb93a386Sopenharmony_ci // For lock surface buffer 140cb93a386Sopenharmony_ci EGLint getBitmapPitch() const; 141cb93a386Sopenharmony_ci EGLint getBitmapOrigin() const; 142cb93a386Sopenharmony_ci EGLint getRedOffset() const; 143cb93a386Sopenharmony_ci EGLint getGreenOffset() const; 144cb93a386Sopenharmony_ci EGLint getBlueOffset() const; 145cb93a386Sopenharmony_ci EGLint getAlphaOffset() const; 146cb93a386Sopenharmony_ci EGLint getLuminanceOffset() const; 147cb93a386Sopenharmony_ci EGLint getBitmapPixelSize() const; 148cb93a386Sopenharmony_ci EGLAttribKHR getBitmapPointer() const; 149cb93a386Sopenharmony_ci egl::Error lockSurfaceKHR(const egl::Display *display, const AttributeMap &attributes); 150cb93a386Sopenharmony_ci egl::Error unlockSurfaceKHR(const egl::Display *display); 151cb93a386Sopenharmony_ci 152cb93a386Sopenharmony_ci bool isLocked() const; 153cb93a386Sopenharmony_ci bool isCurrentOnAnyContext() const { return mIsCurrentOnAnyContext; } 154cb93a386Sopenharmony_ci 155cb93a386Sopenharmony_ci gl::Texture *getBoundTexture() const { return mTexture; } 156cb93a386Sopenharmony_ci 157cb93a386Sopenharmony_ci EGLint isFixedSize() const; 158cb93a386Sopenharmony_ci 159cb93a386Sopenharmony_ci // FramebufferAttachmentObject implementation 160cb93a386Sopenharmony_ci gl::Extents getAttachmentSize(const gl::ImageIndex &imageIndex) const override; 161cb93a386Sopenharmony_ci gl::Format getAttachmentFormat(GLenum binding, const gl::ImageIndex &imageIndex) const override; 162cb93a386Sopenharmony_ci GLsizei getAttachmentSamples(const gl::ImageIndex &imageIndex) const override; 163cb93a386Sopenharmony_ci bool isRenderable(const gl::Context *context, 164cb93a386Sopenharmony_ci GLenum binding, 165cb93a386Sopenharmony_ci const gl::ImageIndex &imageIndex) const override; 166cb93a386Sopenharmony_ci bool isYUV() const override; 167cb93a386Sopenharmony_ci 168cb93a386Sopenharmony_ci void onAttach(const gl::Context *context, rx::Serial framebufferSerial) override {} 169cb93a386Sopenharmony_ci void onDetach(const gl::Context *context, rx::Serial framebufferSerial) override {} 170cb93a386Sopenharmony_ci GLuint getId() const override; 171cb93a386Sopenharmony_ci 172cb93a386Sopenharmony_ci EGLint getOrientation() const { return mOrientation; } 173cb93a386Sopenharmony_ci 174cb93a386Sopenharmony_ci bool directComposition() const { return mState.directComposition; } 175cb93a386Sopenharmony_ci 176cb93a386Sopenharmony_ci gl::InitState initState(const gl::ImageIndex &imageIndex) const override; 177cb93a386Sopenharmony_ci void setInitState(const gl::ImageIndex &imageIndex, gl::InitState initState) override; 178cb93a386Sopenharmony_ci 179cb93a386Sopenharmony_ci bool isRobustResourceInitEnabled() const { return mRobustResourceInitialization; } 180cb93a386Sopenharmony_ci 181cb93a386Sopenharmony_ci const gl::Format &getBindTexImageFormat() const { return mColorFormat; } 182cb93a386Sopenharmony_ci 183cb93a386Sopenharmony_ci // EGL_ANDROID_get_frame_timestamps entry points 184cb93a386Sopenharmony_ci void setTimestampsEnabled(bool enabled); 185cb93a386Sopenharmony_ci bool isTimestampsEnabled() const; 186cb93a386Sopenharmony_ci 187cb93a386Sopenharmony_ci const SupportedCompositorTiming &getSupportedCompositorTimings() const; 188cb93a386Sopenharmony_ci Error getCompositorTiming(EGLint numTimestamps, 189cb93a386Sopenharmony_ci const EGLint *names, 190cb93a386Sopenharmony_ci EGLnsecsANDROID *values) const; 191cb93a386Sopenharmony_ci 192cb93a386Sopenharmony_ci Error getNextFrameId(EGLuint64KHR *frameId) const; 193cb93a386Sopenharmony_ci const SupportedTimestamps &getSupportedTimestamps() const; 194cb93a386Sopenharmony_ci Error getFrameTimestamps(EGLuint64KHR frameId, 195cb93a386Sopenharmony_ci EGLint numTimestamps, 196cb93a386Sopenharmony_ci const EGLint *timestamps, 197cb93a386Sopenharmony_ci EGLnsecsANDROID *values) const; 198cb93a386Sopenharmony_ci 199cb93a386Sopenharmony_ci // Returns the offset into the texture backing the surface if specified via texture offset 200cb93a386Sopenharmony_ci // attributes (see EGL_ANGLE_d3d_texture_client_buffer extension). Returns zero offset 201cb93a386Sopenharmony_ci // otherwise. 202cb93a386Sopenharmony_ci const gl::Offset &getTextureOffset() const { return mTextureOffset; } 203cb93a386Sopenharmony_ci 204cb93a386Sopenharmony_ci Error getBufferAge(const gl::Context *context, EGLint *age) const; 205cb93a386Sopenharmony_ci 206cb93a386Sopenharmony_ci Error setRenderBuffer(EGLint renderBuffer); 207cb93a386Sopenharmony_ci 208cb93a386Sopenharmony_ci protected: 209cb93a386Sopenharmony_ci Surface(EGLint surfaceType, 210cb93a386Sopenharmony_ci const egl::Config *config, 211cb93a386Sopenharmony_ci const AttributeMap &attributes, 212cb93a386Sopenharmony_ci bool forceRobustResourceInit, 213cb93a386Sopenharmony_ci EGLenum buftype = EGL_NONE); 214cb93a386Sopenharmony_ci ~Surface() override; 215cb93a386Sopenharmony_ci rx::FramebufferAttachmentObjectImpl *getAttachmentImpl() const override; 216cb93a386Sopenharmony_ci 217cb93a386Sopenharmony_ci gl::Framebuffer *createDefaultFramebuffer(const Display *display); 218cb93a386Sopenharmony_ci 219cb93a386Sopenharmony_ci // ANGLE-only method, used internally 220cb93a386Sopenharmony_ci friend class gl::Texture; 221cb93a386Sopenharmony_ci Error releaseTexImageFromTexture(const gl::Context *context); 222cb93a386Sopenharmony_ci 223cb93a386Sopenharmony_ci SurfaceState mState; 224cb93a386Sopenharmony_ci rx::SurfaceImpl *mImplementation; 225cb93a386Sopenharmony_ci int mRefCount; 226cb93a386Sopenharmony_ci bool mDestroyed; 227cb93a386Sopenharmony_ci 228cb93a386Sopenharmony_ci EGLint mType; 229cb93a386Sopenharmony_ci EGLenum mBuftype; 230cb93a386Sopenharmony_ci 231cb93a386Sopenharmony_ci bool mPostSubBufferRequested; 232cb93a386Sopenharmony_ci 233cb93a386Sopenharmony_ci bool mLargestPbuffer; 234cb93a386Sopenharmony_ci EGLenum mGLColorspace; 235cb93a386Sopenharmony_ci EGLenum mVGAlphaFormat; 236cb93a386Sopenharmony_ci EGLenum mVGColorspace; 237cb93a386Sopenharmony_ci bool mMipmapTexture; 238cb93a386Sopenharmony_ci EGLint mMipmapLevel; 239cb93a386Sopenharmony_ci EGLint mHorizontalResolution; 240cb93a386Sopenharmony_ci EGLint mVerticalResolution; 241cb93a386Sopenharmony_ci EGLenum mMultisampleResolve; 242cb93a386Sopenharmony_ci 243cb93a386Sopenharmony_ci bool mFixedSize; 244cb93a386Sopenharmony_ci size_t mFixedWidth; 245cb93a386Sopenharmony_ci size_t mFixedHeight; 246cb93a386Sopenharmony_ci 247cb93a386Sopenharmony_ci bool mRobustResourceInitialization; 248cb93a386Sopenharmony_ci 249cb93a386Sopenharmony_ci TextureFormat mTextureFormat; 250cb93a386Sopenharmony_ci EGLenum mTextureTarget; 251cb93a386Sopenharmony_ci 252cb93a386Sopenharmony_ci EGLint mPixelAspectRatio; // Display aspect ratio 253cb93a386Sopenharmony_ci EGLenum mRenderBuffer; // Render buffer 254cb93a386Sopenharmony_ci EGLenum mSwapBehavior; // Buffer swap behavior 255cb93a386Sopenharmony_ci 256cb93a386Sopenharmony_ci EGLint mOrientation; 257cb93a386Sopenharmony_ci 258cb93a386Sopenharmony_ci // We don't use a binding pointer here. We don't ever want to own an orphaned texture. If a 259cb93a386Sopenharmony_ci // Texture is deleted the Surface is unbound in onDestroy. 260cb93a386Sopenharmony_ci gl::Texture *mTexture; 261cb93a386Sopenharmony_ci 262cb93a386Sopenharmony_ci gl::Format mColorFormat; 263cb93a386Sopenharmony_ci gl::Format mDSFormat; 264cb93a386Sopenharmony_ci 265cb93a386Sopenharmony_ci gl::Offset mTextureOffset; 266cb93a386Sopenharmony_ci 267cb93a386Sopenharmony_ci bool mIsCurrentOnAnyContext; // The surface is current to a context/client API 268cb93a386Sopenharmony_ci uint8_t *mLockBufferPtr; // Memory owned by backend. 269cb93a386Sopenharmony_ci EGLint mLockBufferPitch; 270cb93a386Sopenharmony_ci 271cb93a386Sopenharmony_ci private: 272cb93a386Sopenharmony_ci Error destroyImpl(const Display *display); 273cb93a386Sopenharmony_ci 274cb93a386Sopenharmony_ci void postSwap(const gl::Context *context); 275cb93a386Sopenharmony_ci Error releaseRef(const Display *display); 276cb93a386Sopenharmony_ci 277cb93a386Sopenharmony_ci // ObserverInterface implementation. 278cb93a386Sopenharmony_ci void onSubjectStateChange(angle::SubjectIndex index, angle::SubjectMessage message) override; 279cb93a386Sopenharmony_ci 280cb93a386Sopenharmony_ci gl::InitState mInitState; 281cb93a386Sopenharmony_ci angle::ObserverBinding mImplObserverBinding; 282cb93a386Sopenharmony_ci}; 283cb93a386Sopenharmony_ci 284cb93a386Sopenharmony_ciclass WindowSurface final : public Surface 285cb93a386Sopenharmony_ci{ 286cb93a386Sopenharmony_ci public: 287cb93a386Sopenharmony_ci WindowSurface(rx::EGLImplFactory *implFactory, 288cb93a386Sopenharmony_ci const Config *config, 289cb93a386Sopenharmony_ci EGLNativeWindowType window, 290cb93a386Sopenharmony_ci const AttributeMap &attribs, 291cb93a386Sopenharmony_ci bool robustResourceInit); 292cb93a386Sopenharmony_ci ~WindowSurface() override; 293cb93a386Sopenharmony_ci}; 294cb93a386Sopenharmony_ci 295cb93a386Sopenharmony_ciclass PbufferSurface final : public Surface 296cb93a386Sopenharmony_ci{ 297cb93a386Sopenharmony_ci public: 298cb93a386Sopenharmony_ci PbufferSurface(rx::EGLImplFactory *implFactory, 299cb93a386Sopenharmony_ci const Config *config, 300cb93a386Sopenharmony_ci const AttributeMap &attribs, 301cb93a386Sopenharmony_ci bool robustResourceInit); 302cb93a386Sopenharmony_ci PbufferSurface(rx::EGLImplFactory *implFactory, 303cb93a386Sopenharmony_ci const Config *config, 304cb93a386Sopenharmony_ci EGLenum buftype, 305cb93a386Sopenharmony_ci EGLClientBuffer clientBuffer, 306cb93a386Sopenharmony_ci const AttributeMap &attribs, 307cb93a386Sopenharmony_ci bool robustResourceInit); 308cb93a386Sopenharmony_ci 309cb93a386Sopenharmony_ci protected: 310cb93a386Sopenharmony_ci ~PbufferSurface() override; 311cb93a386Sopenharmony_ci}; 312cb93a386Sopenharmony_ci 313cb93a386Sopenharmony_ciclass PixmapSurface final : public Surface 314cb93a386Sopenharmony_ci{ 315cb93a386Sopenharmony_ci public: 316cb93a386Sopenharmony_ci PixmapSurface(rx::EGLImplFactory *implFactory, 317cb93a386Sopenharmony_ci const Config *config, 318cb93a386Sopenharmony_ci NativePixmapType nativePixmap, 319cb93a386Sopenharmony_ci const AttributeMap &attribs, 320cb93a386Sopenharmony_ci bool robustResourceInit); 321cb93a386Sopenharmony_ci 322cb93a386Sopenharmony_ci protected: 323cb93a386Sopenharmony_ci ~PixmapSurface() override; 324cb93a386Sopenharmony_ci}; 325cb93a386Sopenharmony_ci 326cb93a386Sopenharmony_ciclass SurfaceDeleter final 327cb93a386Sopenharmony_ci{ 328cb93a386Sopenharmony_ci public: 329cb93a386Sopenharmony_ci SurfaceDeleter(const Display *display); 330cb93a386Sopenharmony_ci ~SurfaceDeleter(); 331cb93a386Sopenharmony_ci void operator()(Surface *surface); 332cb93a386Sopenharmony_ci 333cb93a386Sopenharmony_ci private: 334cb93a386Sopenharmony_ci const Display *mDisplay; 335cb93a386Sopenharmony_ci}; 336cb93a386Sopenharmony_ci 337cb93a386Sopenharmony_ciusing SurfacePointer = angle::UniqueObjectPointerBase<Surface, SurfaceDeleter>; 338cb93a386Sopenharmony_ci 339cb93a386Sopenharmony_ci} // namespace egl 340cb93a386Sopenharmony_ci 341cb93a386Sopenharmony_ci#endif // LIBANGLE_SURFACE_H_ 342