blob: dcb985809247e1e42ea8fae4bfe7afb692eff9ed [file] [log] [blame]
John Reck23b797a2014-01-03 18:08:34 -08001/*
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
17#ifndef CANVASCONTEXT_H_
18#define CANVASCONTEXT_H_
19
20#include <cutils/compiler.h>
21#include <EGL/egl.h>
John Reck19b6bcf2014-02-14 20:03:38 -080022#include <SkBitmap.h>
John Reck4f02bf42014-01-03 18:09:17 -080023#include <utils/Functor.h>
John Reck19b6bcf2014-02-14 20:03:38 -080024#include <utils/Vector.h>
John Reck4f02bf42014-01-03 18:09:17 -080025
John Reck860d1552014-04-11 19:15:05 -070026#include "../RenderNode.h"
John Reck4f02bf42014-01-03 18:09:17 -080027#include "RenderTask.h"
John Recke45b1fd2014-04-15 09:50:16 -070028#include "RenderThread.h"
John Reck4f02bf42014-01-03 18:09:17 -080029
30#define FUNCTOR_PROCESS_DELAY 4
John Reck23b797a2014-01-03 18:08:34 -080031
32namespace android {
33namespace uirenderer {
John Reck4f02bf42014-01-03 18:09:17 -080034
John Reck19b6bcf2014-02-14 20:03:38 -080035class DeferredLayerUpdater;
John Reck4f02bf42014-01-03 18:09:17 -080036class OpenGLRenderer;
37class Rect;
John Reck1949e792014-04-08 15:18:56 -070038class Layer;
John Reck4f02bf42014-01-03 18:09:17 -080039
John Reck23b797a2014-01-03 18:08:34 -080040namespace renderthread {
41
42class GlobalContext;
John Reck4f02bf42014-01-03 18:09:17 -080043
John Reck23b797a2014-01-03 18:08:34 -080044// This per-renderer class manages the bridge between the global EGL context
45// and the render surface.
John Recke45b1fd2014-04-15 09:50:16 -070046class CanvasContext : public IFrameCallback {
John Reck23b797a2014-01-03 18:08:34 -080047public:
John Recke45b1fd2014-04-15 09:50:16 -070048 CanvasContext(bool translucent, RenderNode* rootRenderNode);
49 virtual ~CanvasContext();
John Reck23b797a2014-01-03 18:08:34 -080050
John Reck4f02bf42014-01-03 18:09:17 -080051 bool initialize(EGLNativeWindowType window);
52 void updateSurface(EGLNativeWindowType window);
John Reckf7d9c1d2014-04-09 10:01:03 -070053 void pauseSurface(EGLNativeWindowType window);
John Reck4f02bf42014-01-03 18:09:17 -080054 void setup(int width, int height);
John Reck63a06672014-05-07 13:45:54 -070055 void setOpaque(bool opaque);
John Reck860d1552014-04-11 19:15:05 -070056 void makeCurrent();
John Reckf9be7792014-05-02 18:21:16 -070057 void prepareDraw(const Vector<DeferredLayerUpdater*>* layerUpdaters, TreeInfo& info);
John Recke45b1fd2014-04-15 09:50:16 -070058 void draw(Rect* dirty);
John Reckfae904d2014-04-14 11:01:57 -070059 void destroyCanvasAndSurface();
John Reck23b797a2014-01-03 18:08:34 -080060
John Recke45b1fd2014-04-15 09:50:16 -070061 // IFrameCallback, Chroreographer-driven frame callback entry point
John Reck18f16e62014-05-02 16:46:41 -070062 virtual void doFrame();
John Recke45b1fd2014-04-15 09:50:16 -070063
John Reck19b6bcf2014-02-14 20:03:38 -080064 bool copyLayerInto(DeferredLayerUpdater* layer, SkBitmap* bitmap);
65
John Reck0d1f6342014-03-28 20:30:27 -070066 void invokeFunctor(Functor* functor);
John Reck23b797a2014-01-03 18:08:34 -080067
John Reckfc53ef272014-02-11 10:40:25 -080068 void runWithGlContext(RenderTask* task);
69
John Reck1949e792014-04-08 15:18:56 -070070 Layer* createRenderLayer(int width, int height);
71 Layer* createTextureLayer();
72
John Reck23b797a2014-01-03 18:08:34 -080073private:
John Reckf9be7792014-05-02 18:21:16 -070074 void processLayerUpdates(const Vector<DeferredLayerUpdater*>* layerUpdaters, TreeInfo& info);
75 void prepareTree(TreeInfo& info);
76
John Reck4f02bf42014-01-03 18:09:17 -080077 void setSurface(EGLNativeWindowType window);
78 void swapBuffers();
John Reckf7d9c1d2014-04-09 10:01:03 -070079 void requireSurface();
John Reck4f02bf42014-01-03 18:09:17 -080080
John Reck19b6bcf2014-02-14 20:03:38 -080081 void requireGlContext();
82
John Reck23b797a2014-01-03 18:08:34 -080083 GlobalContext* mGlobalContext;
John Reck4f02bf42014-01-03 18:09:17 -080084 RenderThread& mRenderThread;
John Reck23b797a2014-01-03 18:08:34 -080085 EGLSurface mEglSurface;
86 bool mDirtyRegionsEnabled;
John Reck4f02bf42014-01-03 18:09:17 -080087
88 bool mOpaque;
89 OpenGLRenderer* mCanvas;
90 bool mHaveNewSurface;
John Recke45b1fd2014-04-15 09:50:16 -070091
92 const sp<RenderNode> mRootRenderNode;
John Reck23b797a2014-01-03 18:08:34 -080093};
94
95} /* namespace renderthread */
96} /* namespace uirenderer */
97} /* namespace android */
98#endif /* CANVASCONTEXT_H_ */