John Reck | 67b1e2b | 2020-08-26 13:17:24 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2020 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef SF_SKIAGLRENDERENGINE_H_ |
| 18 | #define SF_SKIAGLRENDERENGINE_H_ |
| 19 | |
Alec Mouri | b577745 | 2020-09-28 11:32:42 -0700 | [diff] [blame] | 20 | #include <EGL/egl.h> |
| 21 | #include <EGL/eglext.h> |
| 22 | #include <GLES2/gl2.h> |
| 23 | #include <GrDirectContext.h> |
| 24 | #include <SkSurface.h> |
| 25 | #include <android-base/thread_annotations.h> |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 26 | #include <renderengine/ExternalTexture.h> |
Alec Mouri | b577745 | 2020-09-28 11:32:42 -0700 | [diff] [blame] | 27 | #include <renderengine/RenderEngine.h> |
John Reck | 67b1e2b | 2020-08-26 13:17:24 -0700 | [diff] [blame] | 28 | #include <sys/types.h> |
Alec Mouri | b577745 | 2020-09-28 11:32:42 -0700 | [diff] [blame] | 29 | |
John Reck | 67b1e2b | 2020-08-26 13:17:24 -0700 | [diff] [blame] | 30 | #include <mutex> |
| 31 | #include <unordered_map> |
| 32 | |
Alec Mouri | c7f6c8b | 2020-11-09 18:35:20 -0800 | [diff] [blame] | 33 | #include "AutoBackendTexture.h" |
Alec Mouri | b577745 | 2020-09-28 11:32:42 -0700 | [diff] [blame] | 34 | #include "EGL/egl.h" |
Leon Scroggins III | 9f3072c | 2021-03-22 10:42:47 -0400 | [diff] [blame] | 35 | #include "GrContextOptions.h" |
Alec Mouri | c7f6c8b | 2020-11-09 18:35:20 -0800 | [diff] [blame] | 36 | #include "SkImageInfo.h" |
John Reck | 67b1e2b | 2020-08-26 13:17:24 -0700 | [diff] [blame] | 37 | #include "SkiaRenderEngine.h" |
Alec Mouri | c7f6c8b | 2020-11-09 18:35:20 -0800 | [diff] [blame] | 38 | #include "android-base/macros.h" |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 39 | #include "debug/SkiaCapture.h" |
Lucas Dupin | f4cb4a0 | 2020-09-22 14:19:26 -0700 | [diff] [blame] | 40 | #include "filters/BlurFilter.h" |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 41 | #include "filters/LinearEffect.h" |
Nader Jawad | 2dfc98b | 2021-04-08 20:35:39 -0700 | [diff] [blame] | 42 | #include "filters/StretchShaderFactory.h" |
John Reck | 67b1e2b | 2020-08-26 13:17:24 -0700 | [diff] [blame] | 43 | |
Kevin Lubick | 8e0ef68 | 2022-03-04 10:34:35 -0500 | [diff] [blame] | 44 | class SkData; |
| 45 | |
Kevin Lubick | bd9374e | 2022-04-22 15:09:19 -0400 | [diff] [blame] | 46 | struct SkPoint3; |
| 47 | |
John Reck | 67b1e2b | 2020-08-26 13:17:24 -0700 | [diff] [blame] | 48 | namespace android { |
| 49 | namespace renderengine { |
| 50 | namespace skia { |
| 51 | |
| 52 | class SkiaGLRenderEngine : public skia::SkiaRenderEngine { |
| 53 | public: |
| 54 | static std::unique_ptr<SkiaGLRenderEngine> create(const RenderEngineCreationArgs& args); |
Lucas Dupin | d508e47 | 2020-11-04 04:32:06 +0000 | [diff] [blame] | 55 | SkiaGLRenderEngine(const RenderEngineCreationArgs& args, EGLDisplay display, EGLContext ctxt, |
| 56 | EGLSurface placeholder, EGLContext protectedContext, |
John Reck | 67b1e2b | 2020-08-26 13:17:24 -0700 | [diff] [blame] | 57 | EGLSurface protectedPlaceholder); |
Lingfeng Yang | 00c1ff6 | 2022-06-02 09:19:28 -0700 | [diff] [blame^] | 58 | ~SkiaGLRenderEngine() override; |
John Reck | 67b1e2b | 2020-08-26 13:17:24 -0700 | [diff] [blame] | 59 | |
Alec Mouri | d6f0946 | 2020-12-07 11:18:17 -0800 | [diff] [blame] | 60 | int getContextPriority() override; |
John Reck | 67b1e2b | 2020-08-26 13:17:24 -0700 | [diff] [blame] | 61 | |
| 62 | protected: |
Lingfeng Yang | 00c1ff6 | 2022-06-02 09:19:28 -0700 | [diff] [blame^] | 63 | // Implementations of abstract SkiaRenderEngine functions specific to |
| 64 | // rendering backend |
| 65 | virtual SkiaRenderEngine::Contexts createDirectContexts(const GrContextOptions& options); |
| 66 | bool supportsProtectedContentImpl() const override; |
| 67 | bool useProtectedContextImpl(GrProtected isProtected) override; |
| 68 | void waitFence(GrDirectContext* grContext, base::borrowed_fd fenceFd) override; |
| 69 | base::unique_fd flushAndSubmit(GrDirectContext* context) override; |
| 70 | void appendBackendSpecificInfoToDump(std::string& result) override; |
John Reck | 67b1e2b | 2020-08-26 13:17:24 -0700 | [diff] [blame] | 71 | |
| 72 | private: |
Lingfeng Yang | 00c1ff6 | 2022-06-02 09:19:28 -0700 | [diff] [blame^] | 73 | bool waitGpuFence(base::borrowed_fd fenceFd); |
| 74 | base::unique_fd flush(); |
John Reck | 67b1e2b | 2020-08-26 13:17:24 -0700 | [diff] [blame] | 75 | static EGLConfig chooseEglConfig(EGLDisplay display, int format, bool logConfig); |
| 76 | static EGLContext createEglContext(EGLDisplay display, EGLConfig config, |
Alec Mouri | d6f0946 | 2020-12-07 11:18:17 -0800 | [diff] [blame] | 77 | EGLContext shareContext, |
| 78 | std::optional<ContextPriority> contextPriority, |
John Reck | 67b1e2b | 2020-08-26 13:17:24 -0700 | [diff] [blame] | 79 | Protection protection); |
Alec Mouri | d6f0946 | 2020-12-07 11:18:17 -0800 | [diff] [blame] | 80 | static std::optional<RenderEngine::ContextPriority> createContextPriority( |
| 81 | const RenderEngineCreationArgs& args); |
Lingfeng Yang | 00c1ff6 | 2022-06-02 09:19:28 -0700 | [diff] [blame^] | 82 | static EGLSurface createPlaceholderEglPbufferSurface( |
| 83 | EGLDisplay display, EGLConfig config, int hwcFormat, Protection protection); |
John Reck | 67b1e2b | 2020-08-26 13:17:24 -0700 | [diff] [blame] | 84 | |
| 85 | EGLDisplay mEGLDisplay; |
John Reck | 67b1e2b | 2020-08-26 13:17:24 -0700 | [diff] [blame] | 86 | EGLContext mEGLContext; |
| 87 | EGLSurface mPlaceholderSurface; |
| 88 | EGLContext mProtectedEGLContext; |
| 89 | EGLSurface mProtectedPlaceholderSurface; |
John Reck | 67b1e2b | 2020-08-26 13:17:24 -0700 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | } // namespace skia |
| 93 | } // namespace renderengine |
| 94 | } // namespace android |
| 95 | |
Galia Peycheva | 6c46065 | 2020-11-03 19:42:42 +0100 | [diff] [blame] | 96 | #endif /* SF_GLESRENDERENGINE_H_ */ |