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 "CanvasContext.h"
20 #include "BakedOpDispatcher.h"
21 #include "BakedOpRenderer.h"
22 #include "FrameBuilder.h"
23 #include "IRenderPipeline.h"
24 
25 namespace android {
26 namespace uirenderer {
27 namespace renderthread {
28 
29 class OpenGLPipeline : public IRenderPipeline {
30 public:
31     OpenGLPipeline(RenderThread& thread);
~OpenGLPipeline()32     virtual ~OpenGLPipeline() {}
33 
34     MakeCurrentResult makeCurrent() override;
35     Frame getFrame() override;
36     bool draw(const Frame& frame, const SkRect& screenDirty, const SkRect& dirty,
37             const FrameBuilder::LightGeometry& lightGeometry,
38             LayerUpdateQueue* layerUpdateQueue,
39             const Rect& contentDrawBounds, bool opaque,
40             const BakedOpRenderer::LightInfo& lightInfo,
41             const std::vector< sp<RenderNode> >& renderNodes,
42             FrameInfoVisualizer* profiler) override;
43     bool swapBuffers(const Frame& frame, bool drew, const SkRect& screenDirty,
44             FrameInfo* currentFrameInfo, bool* requireSwap) override;
45     bool copyLayerInto(DeferredLayerUpdater* layer, SkBitmap* bitmap) override;
46     DeferredLayerUpdater* createTextureLayer() override;
47     bool setSurface(Surface* window, SwapBehavior swapBehavior) override;
48     void onStop() override;
49     bool isSurfaceReady() override;
50     bool isContextReady() override;
51     void onDestroyHardwareResources() override;
52     void renderLayers(const FrameBuilder::LightGeometry& lightGeometry,
53             LayerUpdateQueue* layerUpdateQueue, bool opaque,
54             const BakedOpRenderer::LightInfo& lightInfo) override;
55     TaskManager* getTaskManager() override;
56     bool createOrUpdateLayer(RenderNode* node,
57             const DamageAccumulator& damageAccumulator) override;
pinImages(std::vector<SkImage * > & mutableImages)58     bool pinImages(std::vector<SkImage*>& mutableImages) override { return false; }
59     bool pinImages(LsaVector<sk_sp<Bitmap>>& images) override;
60     void unpinImages() override;
61     static void destroyLayer(RenderNode* node);
62     static void prepareToDraw(const RenderThread& thread, Bitmap* bitmap);
63     static void invokeFunctor(const RenderThread& thread, Functor* functor);
64 
65 private:
66     EglManager& mEglManager;
67     EGLSurface mEglSurface = EGL_NO_SURFACE;
68     bool mBufferPreserved = false;
69     RenderThread& mRenderThread;
70 };
71 
72 } /* namespace renderthread */
73 } /* namespace uirenderer */
74 } /* namespace android */
75