blob: 898dc5457828fa2cadd97b046ff87c72aa2344fd [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
20#include <sys/types.h>
21#include <mutex>
22#include <unordered_map>
23
24#include <android-base/thread_annotations.h>
25#include <renderengine/RenderEngine.h>
26
27#include <GrDirectContext.h>
28#include <SkSurface.h>
29
30#include "SkiaRenderEngine.h"
Lucas Dupinf4cb4a02020-09-22 14:19:26 -070031#include "filters/BlurFilter.h"
John Reck67b1e2b2020-08-26 13:17:24 -070032
33namespace android {
34namespace renderengine {
35namespace skia {
36
37class SkiaGLRenderEngine : public skia::SkiaRenderEngine {
38public:
39 static std::unique_ptr<SkiaGLRenderEngine> create(const RenderEngineCreationArgs& args);
Lucas Dupinf4cb4a02020-09-22 14:19:26 -070040 SkiaGLRenderEngine(const RenderEngineCreationArgs& args, EGLDisplay display, EGLConfig config,
41 EGLContext ctxt, EGLSurface placeholder, EGLContext protectedContext,
John Reck67b1e2b2020-08-26 13:17:24 -070042 EGLSurface protectedPlaceholder);
43 ~SkiaGLRenderEngine() override{};
44
45 void unbindExternalTextureBuffer(uint64_t bufferId) override;
46 status_t drawLayers(const DisplaySettings& display,
47 const std::vector<const LayerSettings*>& layers,
48 const sp<GraphicBuffer>& buffer, const bool useFramebufferCache,
49 base::unique_fd&& bufferFence, base::unique_fd* drawFence) override;
50 void cleanFramebufferCache() override;
51
52protected:
53 void dump(std::string& /*result*/) override{};
54 size_t getMaxTextureSize() const override;
55 size_t getMaxViewportDims() const override;
56
57private:
58 static EGLConfig chooseEglConfig(EGLDisplay display, int format, bool logConfig);
59 static EGLContext createEglContext(EGLDisplay display, EGLConfig config,
60 EGLContext shareContext, bool useContextPriority,
61 Protection protection);
62 static EGLSurface createPlaceholderEglPbufferSurface(EGLDisplay display, EGLConfig config,
63 int hwcFormat, Protection protection);
Lucas Dupin3f11e922020-09-22 17:31:04 -070064 inline SkRect getSkRect(const FloatRect& layer);
65 inline SkRect getSkRect(const Rect& layer);
Lucas Dupin21f348e2020-09-16 17:31:26 -070066 inline SkRRect getRoundedRect(const LayerSettings* layer);
Lucas Dupin3f11e922020-09-22 17:31:04 -070067 inline SkColor getSkColor(const vec4& color);
Lucas Dupinbb1a1d42020-09-18 15:17:02 -070068 inline SkM44 getSkM44(const mat4& matrix);
Lucas Dupin3f11e922020-09-22 17:31:04 -070069 inline SkPoint3 getSkPoint3(const vec3& vector);
John Reck67b1e2b2020-08-26 13:17:24 -070070
71 base::unique_fd flush();
72 bool waitFence(base::unique_fd fenceFd);
Lucas Dupin3f11e922020-09-22 17:31:04 -070073 void drawShadow(SkCanvas* canvas, const SkRect& casterRect, float casterCornerRadius,
74 const ShadowSettings& shadowSettings);
John Reck67b1e2b2020-08-26 13:17:24 -070075
76 EGLDisplay mEGLDisplay;
77 EGLConfig mEGLConfig;
78 EGLContext mEGLContext;
79 EGLSurface mPlaceholderSurface;
80 EGLContext mProtectedEGLContext;
81 EGLSurface mProtectedPlaceholderSurface;
Lucas Dupinf4cb4a02020-09-22 14:19:26 -070082 BlurFilter* mBlurFilter = nullptr;
John Reck67b1e2b2020-08-26 13:17:24 -070083
84 // Cache of GL images that we'll store per GraphicBuffer ID
85 std::unordered_map<uint64_t, sk_sp<SkImage>> mImageCache GUARDED_BY(mRenderingMutex);
86 // Mutex guarding rendering operations, so that:
87 // 1. GL operations aren't interleaved, and
88 // 2. Internal state related to rendering that is potentially modified by
89 // multiple threads is guaranteed thread-safe.
90 std::mutex mRenderingMutex;
91
92 sp<Fence> mLastDrawFence;
93
94 sk_sp<GrDirectContext> mGrContext;
95
96 std::unordered_map<uint64_t, sk_sp<SkSurface>> mSurfaceCache;
97};
98
99} // namespace skia
100} // namespace renderengine
101} // namespace android
102
103#endif /* SF_GLESRENDERENGINE_H_ */