1 /*
2  * Copyright (C) 2016 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 #pragma once
18 
19 #include <EGL/egl.h>
20 #include <system/window.h>
21 
22 #include "SkiaPipeline.h"
23 #include "renderstate/RenderState.h"
24 #include "renderthread/HardwareBufferRenderParams.h"
25 
26 namespace android {
27 
28 class Bitmap;
29 
30 namespace uirenderer {
31 namespace skiapipeline {
32 
33 class SkiaOpenGLPipeline : public SkiaPipeline, public IGpuContextCallback {
34 public:
35     SkiaOpenGLPipeline(renderthread::RenderThread& thread);
36     virtual ~SkiaOpenGLPipeline();
37 
38     renderthread::MakeCurrentResult makeCurrent() override;
39     renderthread::Frame getFrame() override;
40     renderthread::IRenderPipeline::DrawResult draw(
41             const renderthread::Frame& frame, const SkRect& screenDirty, const SkRect& dirty,
42             const LightGeometry& lightGeometry, LayerUpdateQueue* layerUpdateQueue,
43             const Rect& contentDrawBounds, bool opaque, const LightInfo& lightInfo,
44             const std::vector<sp<RenderNode> >& renderNodes, FrameInfoVisualizer* profiler,
45             const renderthread::HardwareBufferRenderParams& bufferParams) override;
getSurfaceOrigin()46     GrSurfaceOrigin getSurfaceOrigin() override { return kBottomLeft_GrSurfaceOrigin; }
47     bool swapBuffers(const renderthread::Frame& frame, bool drew, const SkRect& screenDirty,
48                      FrameInfo* currentFrameInfo, bool* requireSwap) override;
49     DeferredLayerUpdater* createTextureLayer() override;
50     bool setSurface(ANativeWindow* surface, renderthread::SwapBehavior swapBehavior) override;
51     [[nodiscard]] android::base::unique_fd flush() override;
52     void onStop() override;
53     bool isSurfaceReady() override;
54     bool isContextReady() override;
55 
getPixelSnapMatrix()56     const SkM44& getPixelSnapMatrix() const override {
57         // Small (~1/16th) nudge to ensure that pixel-aligned non-AA'd draws fill the
58         // desired fragment
59         static const SkScalar kOffset = 0.063f;
60         static const SkM44 sSnapMatrix = SkM44::Translate(kOffset, kOffset);
61         return sSnapMatrix;
62     }
63 
64     static void invokeFunctor(const renderthread::RenderThread& thread, Functor* functor);
65 
66 protected:
67     void onContextDestroyed() override;
68 
69 private:
70     renderthread::EglManager& mEglManager;
71     EGLSurface mEglSurface = EGL_NO_SURFACE;
72     sp<ANativeWindow> mNativeWindow;
73     renderthread::SwapBehavior mSwapBehavior = renderthread::SwapBehavior::kSwap_discardBuffer;
74 };
75 
76 } /* namespace skiapipeline */
77 } /* namespace uirenderer */
78 } /* namespace android */
79