blob: 4fd792c1b503348beeeaf3645931979a470a9025 [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#include <private/hwui/DrawGlInfo.h>
Chris Craik44eb2c02015-01-29 09:45:09 -080026#include <renderstate/Blend.h>
Chris Craik6c15ffa2015-02-02 13:50:55 -080027
John Reckebd52612014-12-10 16:47:36 -080028#include "AssetAtlas.h"
John Reck3b202512014-06-23 13:13:08 -070029#include "Caches.h"
Chris Craik6c15ffa2015-02-02 13:50:55 -080030#include "Glop.h"
Chris Craik96a5c4c2015-01-27 15:46:35 -080031#include "renderstate/MeshState.h"
32#include "renderstate/PixelBufferState.h"
33#include "renderstate/Scissor.h"
34#include "renderstate/Stencil.h"
John Reck3b202512014-06-23 13:13:08 -070035#include "utils/Macros.h"
36
37namespace android {
38namespace uirenderer {
39
Tom Hudson2dc236b2014-10-15 15:46:42 -040040class Caches;
41class Layer;
42
John Reck3b202512014-06-23 13:13:08 -070043namespace renderthread {
John Reck443a7142014-09-04 17:40:05 -070044class CanvasContext;
John Reck3b202512014-06-23 13:13:08 -070045class RenderThread;
46}
47
48// TODO: Replace Cache's GL state tracking with this. For now it's more a thin
49// wrapper of Caches for users to migrate to.
50class RenderState {
51 PREVENT_COPY_AND_ASSIGN(RenderState);
52public:
53 void onGLContextCreated();
Chris Craik1d477422014-08-26 17:30:15 -070054 void onGLContextDestroyed();
John Reck3b202512014-06-23 13:13:08 -070055
56 void setViewport(GLsizei width, GLsizei height);
57 void getViewport(GLsizei* outWidth, GLsizei* outHeight);
58
59 void bindFramebuffer(GLuint fbo);
60 GLint getFramebuffer() { return mFramebuffer; }
61
62 void invokeFunctor(Functor* functor, DrawGlInfo::Mode mode, DrawGlInfo* info);
63
64 void debugOverdraw(bool enable, bool clear);
65
John Reck49bc4ac2015-01-29 12:53:38 -080066 void registerLayer(Layer* layer) {
Chris Craik1d477422014-08-26 17:30:15 -070067 mActiveLayers.insert(layer);
68 }
John Reck49bc4ac2015-01-29 12:53:38 -080069 void unregisterLayer(Layer* layer) {
Chris Craik1d477422014-08-26 17:30:15 -070070 mActiveLayers.erase(layer);
71 }
72
John Reck443a7142014-09-04 17:40:05 -070073 void registerCanvasContext(renderthread::CanvasContext* context) {
74 mRegisteredContexts.insert(context);
75 }
76
77 void unregisterCanvasContext(renderthread::CanvasContext* context) {
78 mRegisteredContexts.erase(context);
79 }
80
John Reck0e89e2b2014-10-31 14:49:06 -070081 void requireGLContext();
82
83 // TODO: This system is a little clunky feeling, this could use some
84 // more thinking...
85 void postDecStrong(VirtualLightRefBase* object);
86
Chris Craik6c15ffa2015-02-02 13:50:55 -080087 void render(const Glop& glop);
88
John Reckebd52612014-12-10 16:47:36 -080089 AssetAtlas& assetAtlas() { return mAssetAtlas; }
Chris Craik44eb2c02015-01-29 09:45:09 -080090 Blend& blend() { return *mBlend; }
Chris Craik96a5c4c2015-01-27 15:46:35 -080091 MeshState& meshState() { return *mMeshState; }
92 Scissor& scissor() { return *mScissor; }
93 Stencil& stencil() { return *mStencil; }
Chris Craik117bdbc2015-02-05 10:12:38 -080094
95 void dump();
John Reck3b202512014-06-23 13:13:08 -070096private:
97 friend class renderthread::RenderThread;
John Reck17035b02014-09-03 07:39:53 -070098 friend class Caches;
John Reck3b202512014-06-23 13:13:08 -070099
100 void interruptForFunctorInvoke();
101 void resumeFromFunctorInvoke();
John Reck0e89e2b2014-10-31 14:49:06 -0700102 void assertOnGLThread();
John Reck3b202512014-06-23 13:13:08 -0700103
John Reck0e89e2b2014-10-31 14:49:06 -0700104 RenderState(renderthread::RenderThread& thread);
John Reck3b202512014-06-23 13:13:08 -0700105 ~RenderState();
106
Chris Craik65fe5ee2015-01-26 18:06:29 -0800107
John Reck0e89e2b2014-10-31 14:49:06 -0700108 renderthread::RenderThread& mRenderThread;
Chris Craik44eb2c02015-01-29 09:45:09 -0800109 Caches* mCaches = nullptr;
Chris Craik96a5c4c2015-01-27 15:46:35 -0800110
Chris Craik44eb2c02015-01-29 09:45:09 -0800111 Blend* mBlend = nullptr;
112 MeshState* mMeshState = nullptr;
113 Scissor* mScissor = nullptr;
114 Stencil* mStencil = nullptr;
Chris Craik96a5c4c2015-01-27 15:46:35 -0800115
John Reckebd52612014-12-10 16:47:36 -0800116 AssetAtlas mAssetAtlas;
John Reck49bc4ac2015-01-29 12:53:38 -0800117 std::set<Layer*> mActiveLayers;
John Reck443a7142014-09-04 17:40:05 -0700118 std::set<renderthread::CanvasContext*> mRegisteredContexts;
John Reck3b202512014-06-23 13:13:08 -0700119
120 GLsizei mViewportWidth;
121 GLsizei mViewportHeight;
122 GLuint mFramebuffer;
John Reck0e89e2b2014-10-31 14:49:06 -0700123
124 pthread_t mThreadId;
John Reck3b202512014-06-23 13:13:08 -0700125};
126
127} /* namespace uirenderer */
128} /* namespace android */
129
130#endif /* RENDERSTATE_H */