| 1 | // Copyright 2013 The Flutter Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef FLUTTER_TESTING_TEST_GL_SURFACE_H_ |
| 6 | #define FLUTTER_TESTING_TEST_GL_SURFACE_H_ |
| 7 | |
| 8 | #include <cstdint> |
| 9 | |
| 10 | #include "flutter/fml/macros.h" |
| 11 | |
| 12 | #include "third_party/skia/include/core/SkSurface.h" |
| 13 | #include "third_party/skia/include/gpu/GrDirectContext.h" |
| 14 | |
| 15 | namespace flutter { |
| 16 | namespace testing { |
| 17 | |
| 18 | class TestGLSurface { |
| 19 | public: |
| 20 | explicit TestGLSurface(SkISize surface_size); |
| 21 | |
| 22 | ~TestGLSurface(); |
| 23 | |
| 24 | const SkISize& GetSurfaceSize() const; |
| 25 | |
| 26 | bool MakeCurrent(); |
| 27 | |
| 28 | bool ClearCurrent(); |
| 29 | |
| 30 | bool Present(); |
| 31 | |
| 32 | uint32_t GetFramebuffer(uint32_t width, uint32_t height) const; |
| 33 | |
| 34 | bool MakeResourceCurrent(); |
| 35 | |
| 36 | void* GetProcAddress(const char* name) const; |
| 37 | |
| 38 | sk_sp<SkSurface> GetOnscreenSurface(); |
| 39 | |
| 40 | sk_sp<GrDirectContext> GetGrContext(); |
| 41 | |
| 42 | sk_sp<GrDirectContext> CreateGrContext(); |
| 43 | |
| 44 | sk_sp<SkImage> GetRasterSurfaceSnapshot(); |
| 45 | |
| 46 | uint32_t GetWindowFBOId() const; |
| 47 | |
| 48 | private: |
| 49 | // Importing the EGL.h pulls in platform headers which are problematic |
| 50 | // (especially X11 which #defineds types like Bool). Any TUs importing |
| 51 | // this header then become susceptible to failures because of platform |
| 52 | // specific craziness. Don't expose EGL internals via this header. |
| 53 | using EGLDisplay = void*; |
| 54 | using EGLContext = void*; |
| 55 | using EGLSurface = void*; |
| 56 | |
| 57 | const SkISize surface_size_; |
| 58 | EGLDisplay display_; |
| 59 | EGLContext onscreen_context_; |
| 60 | EGLContext offscreen_context_; |
| 61 | EGLSurface onscreen_surface_; |
| 62 | EGLSurface offscreen_surface_; |
| 63 | sk_sp<GrDirectContext> context_; |
| 64 | |
| 65 | FML_DISALLOW_COPY_AND_ASSIGN(TestGLSurface); |
| 66 | }; |
| 67 | |
| 68 | } // namespace testing |
| 69 | } // namespace flutter |
| 70 | |
| 71 | #endif // FLUTTER_TESTING_TEST_GL_SURFACE_H_ |
| 72 | |