blob: 4a37ffee83e87de40235448d5904b84cc04ecdb0 [file] [log] [blame]
John Reck67b1e2b2020-08-26 13:17:24 -07001/*
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 Mourib5777452020-09-28 11:32:42 -070020#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 Mouria90a5702021-04-16 16:36:21 +000026#include <renderengine/ExternalTexture.h>
Alec Mourib5777452020-09-28 11:32:42 -070027#include <renderengine/RenderEngine.h>
John Reck67b1e2b2020-08-26 13:17:24 -070028#include <sys/types.h>
Alec Mourib5777452020-09-28 11:32:42 -070029
John Reck67b1e2b2020-08-26 13:17:24 -070030#include <mutex>
31#include <unordered_map>
32
Alec Mouric7f6c8b2020-11-09 18:35:20 -080033#include "AutoBackendTexture.h"
Alec Mourib5777452020-09-28 11:32:42 -070034#include "EGL/egl.h"
Leon Scroggins III9f3072c2021-03-22 10:42:47 -040035#include "GrContextOptions.h"
Alec Mouric7f6c8b2020-11-09 18:35:20 -080036#include "SkImageInfo.h"
John Reck67b1e2b2020-08-26 13:17:24 -070037#include "SkiaRenderEngine.h"
Alec Mouric7f6c8b2020-11-09 18:35:20 -080038#include "android-base/macros.h"
Alec Mouric0aae732021-01-12 13:32:18 -080039#include "debug/SkiaCapture.h"
Lucas Dupinf4cb4a02020-09-22 14:19:26 -070040#include "filters/BlurFilter.h"
Alec Mouric0aae732021-01-12 13:32:18 -080041#include "filters/LinearEffect.h"
Nader Jawad2dfc98b2021-04-08 20:35:39 -070042#include "filters/StretchShaderFactory.h"
John Reck67b1e2b2020-08-26 13:17:24 -070043
Kevin Lubick8e0ef682022-03-04 10:34:35 -050044class SkData;
45
Kevin Lubickbd9374e2022-04-22 15:09:19 -040046struct SkPoint3;
47
John Reck67b1e2b2020-08-26 13:17:24 -070048namespace android {
49namespace renderengine {
50namespace skia {
51
52class SkiaGLRenderEngine : public skia::SkiaRenderEngine {
53public:
54 static std::unique_ptr<SkiaGLRenderEngine> create(const RenderEngineCreationArgs& args);
Lucas Dupind508e472020-11-04 04:32:06 +000055 SkiaGLRenderEngine(const RenderEngineCreationArgs& args, EGLDisplay display, EGLContext ctxt,
56 EGLSurface placeholder, EGLContext protectedContext,
John Reck67b1e2b2020-08-26 13:17:24 -070057 EGLSurface protectedPlaceholder);
Lingfeng Yang00c1ff62022-06-02 09:19:28 -070058 ~SkiaGLRenderEngine() override;
John Reck67b1e2b2020-08-26 13:17:24 -070059
Alec Mourid6f09462020-12-07 11:18:17 -080060 int getContextPriority() override;
John Reck67b1e2b2020-08-26 13:17:24 -070061
62protected:
Lingfeng Yang00c1ff62022-06-02 09:19:28 -070063 // 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 Reck67b1e2b2020-08-26 13:17:24 -070071
72private:
Lingfeng Yang00c1ff62022-06-02 09:19:28 -070073 bool waitGpuFence(base::borrowed_fd fenceFd);
74 base::unique_fd flush();
John Reck67b1e2b2020-08-26 13:17:24 -070075 static EGLConfig chooseEglConfig(EGLDisplay display, int format, bool logConfig);
76 static EGLContext createEglContext(EGLDisplay display, EGLConfig config,
Alec Mourid6f09462020-12-07 11:18:17 -080077 EGLContext shareContext,
78 std::optional<ContextPriority> contextPriority,
John Reck67b1e2b2020-08-26 13:17:24 -070079 Protection protection);
Alec Mourid6f09462020-12-07 11:18:17 -080080 static std::optional<RenderEngine::ContextPriority> createContextPriority(
81 const RenderEngineCreationArgs& args);
Lingfeng Yang00c1ff62022-06-02 09:19:28 -070082 static EGLSurface createPlaceholderEglPbufferSurface(
83 EGLDisplay display, EGLConfig config, int hwcFormat, Protection protection);
John Reck67b1e2b2020-08-26 13:17:24 -070084
85 EGLDisplay mEGLDisplay;
John Reck67b1e2b2020-08-26 13:17:24 -070086 EGLContext mEGLContext;
87 EGLSurface mPlaceholderSurface;
88 EGLContext mProtectedEGLContext;
89 EGLSurface mProtectedPlaceholderSurface;
John Reck67b1e2b2020-08-26 13:17:24 -070090};
91
92} // namespace skia
93} // namespace renderengine
94} // namespace android
95
Galia Peycheva6c460652020-11-03 19:42:42 +010096#endif /* SF_GLESRENDERENGINE_H_ */