Home | History | Annotate | Download | only in hwui
      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 <set>
     20 #include <GLES2/gl2.h>
     21 #include <GLES2/gl2ext.h>
     22 #include <utils/Mutex.h>
     23 
     24 #include <private/hwui/DrawGlInfo.h>
     25 
     26 #include "Caches.h"
     27 #include "utils/Macros.h"
     28 
     29 namespace android {
     30 namespace uirenderer {
     31 
     32 namespace renderthread {
     33 class CanvasContext;
     34 class RenderThread;
     35 }
     36 
     37 // TODO: Replace Cache's GL state tracking with this. For now it's more a thin
     38 // wrapper of Caches for users to migrate to.
     39 class RenderState {
     40     PREVENT_COPY_AND_ASSIGN(RenderState);
     41 public:
     42     void onGLContextCreated();
     43     void onGLContextDestroyed();
     44 
     45     void setViewport(GLsizei width, GLsizei height);
     46     void getViewport(GLsizei* outWidth, GLsizei* outHeight);
     47 
     48     void bindFramebuffer(GLuint fbo);
     49     GLint getFramebuffer() { return mFramebuffer; }
     50 
     51     void invokeFunctor(Functor* functor, DrawGlInfo::Mode mode, DrawGlInfo* info);
     52 
     53     void debugOverdraw(bool enable, bool clear);
     54 
     55     void registerLayer(const Layer* layer) {
     56         /*
     57         AutoMutex _lock(mLayerLock);
     58         mActiveLayers.insert(layer);
     59         */
     60     }
     61     void unregisterLayer(const Layer* layer) {
     62         /*
     63         AutoMutex _lock(mLayerLock);
     64         mActiveLayers.erase(layer);
     65         */
     66     }
     67 
     68     void registerCanvasContext(renderthread::CanvasContext* context) {
     69         mRegisteredContexts.insert(context);
     70     }
     71 
     72     void unregisterCanvasContext(renderthread::CanvasContext* context) {
     73         mRegisteredContexts.erase(context);
     74     }
     75 
     76 private:
     77     friend class renderthread::RenderThread;
     78     friend class Caches;
     79 
     80     void interruptForFunctorInvoke();
     81     void resumeFromFunctorInvoke();
     82 
     83     RenderState();
     84     ~RenderState();
     85 
     86     Caches* mCaches;
     87     std::set<const Layer*> mActiveLayers;
     88     std::set<renderthread::CanvasContext*> mRegisteredContexts;
     89 
     90     GLsizei mViewportWidth;
     91     GLsizei mViewportHeight;
     92     GLuint mFramebuffer;
     93     Mutex mLayerLock;
     94 };
     95 
     96 } /* namespace uirenderer */
     97 } /* namespace android */
     98 
     99 #endif /* RENDERSTATE_H */
    100