blob: b2d5cc527e8f119ae09afc7a8a568beedd789c5c [file] [log] [blame]
John Reck3b202512014-06-23 13:13:08 -07001/*
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
Chris Craik1d477422014-08-26 17:30:15 -070019#include <set>
John Reck3b202512014-06-23 13:13:08 -070020#include <GLES2/gl2.h>
21#include <GLES2/gl2ext.h>
Chris Craik599e2542014-09-05 15:17:11 -070022#include <utils/Mutex.h>
Tom Hudson2dc236b2014-10-15 15:46:42 -040023#include <utils/Functor.h>
Nick Kralevichbfed8272014-11-01 18:37:39 -070024#include <utils/RefBase.h>
John Reck3b202512014-06-23 13:13:08 -070025
26#include <private/hwui/DrawGlInfo.h>
27
John Reckebd52612014-12-10 16:47:36 -080028#include "AssetAtlas.h"
John Reck3b202512014-06-23 13:13:08 -070029#include "Caches.h"
Chris Craik65fe5ee2015-01-26 18:06:29 -080030#include "Scissor.h"
John Reck3b202512014-06-23 13:13:08 -070031#include "utils/Macros.h"
32
33namespace android {
34namespace uirenderer {
35
Tom Hudson2dc236b2014-10-15 15:46:42 -040036class Caches;
37class Layer;
38
John Reck3b202512014-06-23 13:13:08 -070039namespace renderthread {
John Reck443a7142014-09-04 17:40:05 -070040class CanvasContext;
John Reck3b202512014-06-23 13:13:08 -070041class RenderThread;
42}
43
44// TODO: Replace Cache's GL state tracking with this. For now it's more a thin
45// wrapper of Caches for users to migrate to.
46class RenderState {
47 PREVENT_COPY_AND_ASSIGN(RenderState);
48public:
49 void onGLContextCreated();
Chris Craik1d477422014-08-26 17:30:15 -070050 void onGLContextDestroyed();
John Reck3b202512014-06-23 13:13:08 -070051
52 void setViewport(GLsizei width, GLsizei height);
53 void getViewport(GLsizei* outWidth, GLsizei* outHeight);
54
55 void bindFramebuffer(GLuint fbo);
56 GLint getFramebuffer() { return mFramebuffer; }
57
58 void invokeFunctor(Functor* functor, DrawGlInfo::Mode mode, DrawGlInfo* info);
59
60 void debugOverdraw(bool enable, bool clear);
61
Chris Craik1d477422014-08-26 17:30:15 -070062 void registerLayer(const Layer* layer) {
63 mActiveLayers.insert(layer);
64 }
65 void unregisterLayer(const Layer* layer) {
66 mActiveLayers.erase(layer);
67 }
68
John Reck443a7142014-09-04 17:40:05 -070069 void registerCanvasContext(renderthread::CanvasContext* context) {
70 mRegisteredContexts.insert(context);
71 }
72
73 void unregisterCanvasContext(renderthread::CanvasContext* context) {
74 mRegisteredContexts.erase(context);
75 }
76
John Reck0e89e2b2014-10-31 14:49:06 -070077 void requireGLContext();
78
79 // TODO: This system is a little clunky feeling, this could use some
80 // more thinking...
81 void postDecStrong(VirtualLightRefBase* object);
82
John Reckebd52612014-12-10 16:47:36 -080083 AssetAtlas& assetAtlas() { return mAssetAtlas; }
84
Chris Craik65fe5ee2015-01-26 18:06:29 -080085 Scissor& scissor() { return mScissor; }
John Reck3b202512014-06-23 13:13:08 -070086private:
87 friend class renderthread::RenderThread;
John Reck17035b02014-09-03 07:39:53 -070088 friend class Caches;
John Reck3b202512014-06-23 13:13:08 -070089
90 void interruptForFunctorInvoke();
91 void resumeFromFunctorInvoke();
John Reck0e89e2b2014-10-31 14:49:06 -070092 void assertOnGLThread();
John Reck3b202512014-06-23 13:13:08 -070093
John Reck0e89e2b2014-10-31 14:49:06 -070094 RenderState(renderthread::RenderThread& thread);
John Reck3b202512014-06-23 13:13:08 -070095 ~RenderState();
96
Chris Craik65fe5ee2015-01-26 18:06:29 -080097 Scissor mScissor;
98
John Reck0e89e2b2014-10-31 14:49:06 -070099 renderthread::RenderThread& mRenderThread;
John Reck3b202512014-06-23 13:13:08 -0700100 Caches* mCaches;
John Reckebd52612014-12-10 16:47:36 -0800101 AssetAtlas mAssetAtlas;
Chris Craik1d477422014-08-26 17:30:15 -0700102 std::set<const Layer*> mActiveLayers;
John Reck443a7142014-09-04 17:40:05 -0700103 std::set<renderthread::CanvasContext*> mRegisteredContexts;
John Reck3b202512014-06-23 13:13:08 -0700104
105 GLsizei mViewportWidth;
106 GLsizei mViewportHeight;
107 GLuint mFramebuffer;
John Reck0e89e2b2014-10-31 14:49:06 -0700108
109 pthread_t mThreadId;
John Reck3b202512014-06-23 13:13:08 -0700110};
111
112} /* namespace uirenderer */
113} /* namespace android */
114
115#endif /* RENDERSTATE_H */