| 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> | 
|  | 26 | #include <renderengine/RenderEngine.h> | 
| John Reck | 67b1e2b | 2020-08-26 13:17:24 -0700 | [diff] [blame] | 27 | #include <sys/types.h> | 
| Alec Mouri | b577745 | 2020-09-28 11:32:42 -0700 | [diff] [blame] | 28 |  | 
| John Reck | 67b1e2b | 2020-08-26 13:17:24 -0700 | [diff] [blame] | 29 | #include <mutex> | 
|  | 30 | #include <unordered_map> | 
|  | 31 |  | 
| Alec Mouri | b577745 | 2020-09-28 11:32:42 -0700 | [diff] [blame] | 32 | #include "EGL/egl.h" | 
| John Reck | 67b1e2b | 2020-08-26 13:17:24 -0700 | [diff] [blame] | 33 | #include "SkiaRenderEngine.h" | 
| Lucas Dupin | f4cb4a0 | 2020-09-22 14:19:26 -0700 | [diff] [blame] | 34 | #include "filters/BlurFilter.h" | 
| John Reck | 67b1e2b | 2020-08-26 13:17:24 -0700 | [diff] [blame] | 35 |  | 
|  | 36 | namespace android { | 
|  | 37 | namespace renderengine { | 
|  | 38 | namespace skia { | 
|  | 39 |  | 
|  | 40 | class SkiaGLRenderEngine : public skia::SkiaRenderEngine { | 
|  | 41 | public: | 
|  | 42 | static std::unique_ptr<SkiaGLRenderEngine> create(const RenderEngineCreationArgs& args); | 
| Lucas Dupin | f4cb4a0 | 2020-09-22 14:19:26 -0700 | [diff] [blame] | 43 | SkiaGLRenderEngine(const RenderEngineCreationArgs& args, EGLDisplay display, EGLConfig config, | 
|  | 44 | EGLContext ctxt, EGLSurface placeholder, EGLContext protectedContext, | 
| John Reck | 67b1e2b | 2020-08-26 13:17:24 -0700 | [diff] [blame] | 45 | EGLSurface protectedPlaceholder); | 
|  | 46 | ~SkiaGLRenderEngine() override{}; | 
|  | 47 |  | 
|  | 48 | void unbindExternalTextureBuffer(uint64_t bufferId) override; | 
|  | 49 | status_t drawLayers(const DisplaySettings& display, | 
|  | 50 | const std::vector<const LayerSettings*>& layers, | 
|  | 51 | const sp<GraphicBuffer>& buffer, const bool useFramebufferCache, | 
|  | 52 | base::unique_fd&& bufferFence, base::unique_fd* drawFence) override; | 
|  | 53 | void cleanFramebufferCache() override; | 
|  | 54 |  | 
|  | 55 | protected: | 
|  | 56 | void dump(std::string& /*result*/) override{}; | 
|  | 57 | size_t getMaxTextureSize() const override; | 
|  | 58 | size_t getMaxViewportDims() const override; | 
|  | 59 |  | 
|  | 60 | private: | 
|  | 61 | static EGLConfig chooseEglConfig(EGLDisplay display, int format, bool logConfig); | 
|  | 62 | static EGLContext createEglContext(EGLDisplay display, EGLConfig config, | 
|  | 63 | EGLContext shareContext, bool useContextPriority, | 
|  | 64 | Protection protection); | 
|  | 65 | static EGLSurface createPlaceholderEglPbufferSurface(EGLDisplay display, EGLConfig config, | 
|  | 66 | int hwcFormat, Protection protection); | 
| Lucas Dupin | 3f11e92 | 2020-09-22 17:31:04 -0700 | [diff] [blame] | 67 | inline SkRect getSkRect(const FloatRect& layer); | 
|  | 68 | inline SkRect getSkRect(const Rect& layer); | 
| Lucas Dupin | 21f348e | 2020-09-16 17:31:26 -0700 | [diff] [blame] | 69 | inline SkRRect getRoundedRect(const LayerSettings* layer); | 
| Lucas Dupin | 3f11e92 | 2020-09-22 17:31:04 -0700 | [diff] [blame] | 70 | inline SkColor getSkColor(const vec4& color); | 
| Lucas Dupin | bb1a1d4 | 2020-09-18 15:17:02 -0700 | [diff] [blame] | 71 | inline SkM44 getSkM44(const mat4& matrix); | 
| Galia Peycheva | 6c46065 | 2020-11-03 19:42:42 +0100 | [diff] [blame] | 72 | inline SkMatrix getDrawTransform(const LayerSettings* layer, const SkMatrix& screenTransform); | 
| Lucas Dupin | 3f11e92 | 2020-09-22 17:31:04 -0700 | [diff] [blame] | 73 | inline SkPoint3 getSkPoint3(const vec3& vector); | 
| John Reck | 67b1e2b | 2020-08-26 13:17:24 -0700 | [diff] [blame] | 74 |  | 
|  | 75 | base::unique_fd flush(); | 
|  | 76 | bool waitFence(base::unique_fd fenceFd); | 
| Lucas Dupin | 3f11e92 | 2020-09-22 17:31:04 -0700 | [diff] [blame] | 77 | void drawShadow(SkCanvas* canvas, const SkRect& casterRect, float casterCornerRadius, | 
|  | 78 | const ShadowSettings& shadowSettings); | 
| Lucas Dupin | c3800b8 | 2020-10-02 16:24:48 -0700 | [diff] [blame] | 79 | void drawBlurRegion(SkCanvas* canvas, const BlurRegion& blurRegion, const SkRect& layerBounds, | 
|  | 80 | sk_sp<SkSurface> blurrendSurface); | 
| John Reck | 67b1e2b | 2020-08-26 13:17:24 -0700 | [diff] [blame] | 81 |  | 
|  | 82 | EGLDisplay mEGLDisplay; | 
|  | 83 | EGLConfig mEGLConfig; | 
|  | 84 | EGLContext mEGLContext; | 
|  | 85 | EGLSurface mPlaceholderSurface; | 
|  | 86 | EGLContext mProtectedEGLContext; | 
|  | 87 | EGLSurface mProtectedPlaceholderSurface; | 
| Lucas Dupin | f4cb4a0 | 2020-09-22 14:19:26 -0700 | [diff] [blame] | 88 | BlurFilter* mBlurFilter = nullptr; | 
| John Reck | 67b1e2b | 2020-08-26 13:17:24 -0700 | [diff] [blame] | 89 |  | 
| Alec Mouri | b577745 | 2020-09-28 11:32:42 -0700 | [diff] [blame] | 90 | const bool mUseColorManagement; | 
|  | 91 |  | 
| John Reck | 67b1e2b | 2020-08-26 13:17:24 -0700 | [diff] [blame] | 92 | // Cache of GL images that we'll store per GraphicBuffer ID | 
|  | 93 | std::unordered_map<uint64_t, sk_sp<SkImage>> mImageCache GUARDED_BY(mRenderingMutex); | 
|  | 94 | // Mutex guarding rendering operations, so that: | 
|  | 95 | // 1. GL operations aren't interleaved, and | 
|  | 96 | // 2. Internal state related to rendering that is potentially modified by | 
|  | 97 | // multiple threads is guaranteed thread-safe. | 
|  | 98 | std::mutex mRenderingMutex; | 
|  | 99 |  | 
|  | 100 | sp<Fence> mLastDrawFence; | 
|  | 101 |  | 
|  | 102 | sk_sp<GrDirectContext> mGrContext; | 
|  | 103 |  | 
|  | 104 | std::unordered_map<uint64_t, sk_sp<SkSurface>> mSurfaceCache; | 
|  | 105 | }; | 
|  | 106 |  | 
|  | 107 | } // namespace skia | 
|  | 108 | } // namespace renderengine | 
|  | 109 | } // namespace android | 
|  | 110 |  | 
| Galia Peycheva | 6c46065 | 2020-11-03 19:42:42 +0100 | [diff] [blame] | 111 | #endif /* SF_GLESRENDERENGINE_H_ */ |