RenderState.h revision 45ec62ba72c5017fae7d8baab20bfb0d4c99c627
1/* 2 * Copyright (C) 2014 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#ifndef RENDERSTATE_H 17#define RENDERSTATE_H 18 19#include "Caches.h" 20#include "Glop.h" 21#include "renderstate/Blend.h" 22#include "renderstate/MeshState.h" 23#include "renderstate/OffscreenBufferPool.h" 24#include "renderstate/PixelBufferState.h" 25#include "renderstate/Scissor.h" 26#include "renderstate/Stencil.h" 27#include "utils/Macros.h" 28 29#include <set> 30#include <GLES2/gl2.h> 31#include <GLES2/gl2ext.h> 32#include <ui/Region.h> 33#include <utils/Mutex.h> 34#include <utils/Functor.h> 35#include <utils/RefBase.h> 36#include <private/hwui/DrawGlInfo.h> 37 38class GrContext; 39 40namespace android { 41namespace uirenderer { 42 43class Caches; 44class Layer; 45 46namespace renderthread { 47class CanvasContext; 48class RenderThread; 49} 50 51// TODO: Replace Cache's GL state tracking with this. For now it's more a thin 52// wrapper of Caches for users to migrate to. 53class RenderState { 54 PREVENT_COPY_AND_ASSIGN(RenderState); 55 friend class renderthread::RenderThread; 56 friend class Caches; 57public: 58 void onGLContextCreated(); 59 void onGLContextDestroyed(); 60 61 void onVkContextCreated(); 62 void onVkContextDestroyed(); 63 64 void flush(Caches::FlushMode flushMode); 65 66 void setViewport(GLsizei width, GLsizei height); 67 void getViewport(GLsizei* outWidth, GLsizei* outHeight); 68 69 void bindFramebuffer(GLuint fbo); 70 GLuint getFramebuffer() { return mFramebuffer; } 71 GLuint createFramebuffer(); 72 void deleteFramebuffer(GLuint fbo); 73 74 void invokeFunctor(Functor* functor, DrawGlInfo::Mode mode, DrawGlInfo* info); 75 76 void debugOverdraw(bool enable, bool clear); 77 78 void registerLayer(Layer* layer) { 79 mActiveLayers.insert(layer); 80 } 81 void unregisterLayer(Layer* layer) { 82 mActiveLayers.erase(layer); 83 } 84 85 void registerCanvasContext(renderthread::CanvasContext* context) { 86 mRegisteredContexts.insert(context); 87 } 88 89 void unregisterCanvasContext(renderthread::CanvasContext* context) { 90 mRegisteredContexts.erase(context); 91 } 92 93 // TODO: This system is a little clunky feeling, this could use some 94 // more thinking... 95 void postDecStrong(VirtualLightRefBase* object); 96 97 void render(const Glop& glop, const Matrix4& orthoMatrix); 98 99 Blend& blend() { return *mBlend; } 100 MeshState& meshState() { return *mMeshState; } 101 Scissor& scissor() { return *mScissor; } 102 Stencil& stencil() { return *mStencil; } 103 104 OffscreenBufferPool& layerPool() { return mLayerPool; } 105 106 GrContext* getGrContext() const; 107 108 void dump(); 109 110private: 111 void interruptForFunctorInvoke(); 112 void resumeFromFunctorInvoke(); 113 114 explicit RenderState(renderthread::RenderThread& thread); 115 ~RenderState(); 116 117 118 renderthread::RenderThread& mRenderThread; 119 Caches* mCaches = nullptr; 120 121 Blend* mBlend = nullptr; 122 MeshState* mMeshState = nullptr; 123 Scissor* mScissor = nullptr; 124 Stencil* mStencil = nullptr; 125 126 OffscreenBufferPool mLayerPool; 127 128 std::set<Layer*> mActiveLayers; 129 std::set<renderthread::CanvasContext*> mRegisteredContexts; 130 131 GLsizei mViewportWidth; 132 GLsizei mViewportHeight; 133 GLuint mFramebuffer; 134 135 pthread_t mThreadId; 136}; 137 138} /* namespace uirenderer */ 139} /* namespace android */ 140 141#endif /* RENDERSTATE_H */ 142