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