1 //
2 // Copyright 2014 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 
7 // SurfaceImpl.h: Implementation methods of egl::Surface
8 
9 #ifndef LIBANGLE_RENDERER_SURFACEIMPL_H_
10 #define LIBANGLE_RENDERER_SURFACEIMPL_H_
11 
12 #include <EGL/egl.h>
13 #include <EGL/eglext.h>
14 
15 #include "common/angleutils.h"
16 #include "libANGLE/Error.h"
17 #include "libANGLE/FramebufferAttachment.h"
18 #include "libANGLE/renderer/FramebufferAttachmentObjectImpl.h"
19 
20 namespace angle
21 {
22 struct Format;
23 }
24 
25 namespace gl
26 {
27 class Context;
28 class FramebufferState;
29 }  // namespace gl
30 
31 namespace egl
32 {
33 class Display;
34 struct Config;
35 struct SurfaceState;
36 class Thread;
37 
38 using SupportedTimestamps        = angle::PackedEnumBitSet<Timestamp>;
39 using SupportedCompositorTimings = angle::PackedEnumBitSet<CompositorTiming>;
40 }  // namespace egl
41 
42 namespace rx
43 {
44 class FramebufferImpl;
45 
46 class SurfaceImpl : public FramebufferAttachmentObjectImpl
47 {
48   public:
49     SurfaceImpl(const egl::SurfaceState &surfaceState);
50     ~SurfaceImpl() override;
destroy(const egl::Display * display)51     virtual void destroy(const egl::Display *display) {}
52 
53     virtual egl::Error initialize(const egl::Display *display)                           = 0;
54     virtual FramebufferImpl *createDefaultFramebuffer(const gl::Context *context,
55                                                       const gl::FramebufferState &state) = 0;
56     virtual egl::Error makeCurrent(const gl::Context *context);
57     virtual egl::Error unMakeCurrent(const gl::Context *context);
58     virtual egl::Error swap(const gl::Context *context) = 0;
59     virtual egl::Error swapWithDamage(const gl::Context *context,
60                                       const EGLint *rects,
61                                       EGLint n_rects);
62     virtual egl::Error swapWithFrameToken(const gl::Context *context,
63                                           EGLFrameTokenANGLE frameToken);
64     virtual egl::Error postSubBuffer(const gl::Context *context,
65                                      EGLint x,
66                                      EGLint y,
67                                      EGLint width,
68                                      EGLint height) = 0;
69     virtual egl::Error setPresentationTime(EGLnsecsANDROID time);
70     virtual egl::Error querySurfacePointerANGLE(EGLint attribute, void **value)               = 0;
71     virtual egl::Error bindTexImage(const gl::Context *context,
72                                     gl::Texture *texture,
73                                     EGLint buffer)                                            = 0;
74     virtual egl::Error releaseTexImage(const gl::Context *context, EGLint buffer)             = 0;
75     virtual egl::Error getSyncValues(EGLuint64KHR *ust, EGLuint64KHR *msc, EGLuint64KHR *sbc) = 0;
76     virtual egl::Error getMscRate(EGLint *numerator, EGLint *denominator)                     = 0;
77     virtual void setSwapInterval(EGLint interval)                                             = 0;
78     virtual void setFixedWidth(EGLint width);
79     virtual void setFixedHeight(EGLint height);
80 
81     // width and height can change with client window resizing
82     virtual EGLint getWidth() const  = 0;
83     virtual EGLint getHeight() const = 0;
84     // Note: windows cannot be resized on Android.  The approach requires
85     // calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR.  However, that is
86     // expensive; and there are troublesome timing issues for other parts of
87     // ANGLE (which cause test failures and crashes).  Therefore, a
88     // special-Android-only path is created just for the querying of EGL_WIDTH
89     // and EGL_HEIGHT.
90     // https://issuetracker.google.com/issues/153329980
91     virtual egl::Error getUserWidth(const egl::Display *display, EGLint *value) const;
92     virtual egl::Error getUserHeight(const egl::Display *display, EGLint *value) const;
93 
94     virtual EGLint isPostSubBufferSupported() const = 0;
95     virtual EGLint getSwapBehavior() const          = 0;
96 
97     // Used to query color format from pbuffers created from D3D textures.
98     virtual const angle::Format *getD3DTextureColorFormat() const;
99 
100     // EGL_ANDROID_get_frame_timestamps
101     virtual void setTimestampsEnabled(bool enabled);
102     virtual egl::SupportedCompositorTimings getSupportedCompositorTimings() const;
103     virtual egl::Error getCompositorTiming(EGLint numTimestamps,
104                                            const EGLint *names,
105                                            EGLnsecsANDROID *values) const;
106     virtual egl::Error getNextFrameId(EGLuint64KHR *frameId) const;
107     virtual egl::SupportedTimestamps getSupportedTimestamps() const;
108     virtual egl::Error getFrameTimestamps(EGLuint64KHR frameId,
109                                           EGLint numTimestamps,
110                                           const EGLint *timestamps,
111                                           EGLnsecsANDROID *values) const;
112     virtual egl::Error getBufferAge(const gl::Context *context, EGLint *age);
113 
114   protected:
115     const egl::SurfaceState &mState;
116 };
117 
118 }  // namespace rx
119 
120 #endif  // LIBANGLE_RENDERER_SURFACEIMPL_H_
121