blob: a04269b0257f4446e220fe4984ae56c04b0c851f [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 Reckfe5e7b72014-05-23 17:42:28 -070026#include "../DrawProfiler.h"
John Reck860d1552014-04-11 19:15:05 -070027#include "../RenderNode.h"
John Reck4f02bf42014-01-03 18:09:17 -080028#include "RenderTask.h"
John Recke45b1fd2014-04-15 09:50:16 -070029#include "RenderThread.h"
John Reck4f02bf42014-01-03 18:09:17 -080030
31#define FUNCTOR_PROCESS_DELAY 4
John Reck23b797a2014-01-03 18:08:34 -080032
33namespace android {
34namespace uirenderer {
John Reck4f02bf42014-01-03 18:09:17 -080035
John Reck19b6bcf2014-02-14 20:03:38 -080036class DeferredLayerUpdater;
John Reck4f02bf42014-01-03 18:09:17 -080037class OpenGLRenderer;
38class Rect;
John Reck1949e792014-04-08 15:18:56 -070039class Layer;
John Reck4f02bf42014-01-03 18:09:17 -080040
John Reck23b797a2014-01-03 18:08:34 -080041namespace renderthread {
42
43class GlobalContext;
John Reck4f02bf42014-01-03 18:09:17 -080044
John Reck23b797a2014-01-03 18:08:34 -080045// This per-renderer class manages the bridge between the global EGL context
46// and the render surface.
John Recke45b1fd2014-04-15 09:50:16 -070047class CanvasContext : public IFrameCallback {
John Reck23b797a2014-01-03 18:08:34 -080048public:
John Recke45b1fd2014-04-15 09:50:16 -070049 CanvasContext(bool translucent, RenderNode* rootRenderNode);
50 virtual ~CanvasContext();
John Reck23b797a2014-01-03 18:08:34 -080051
John Recka5dda642014-05-22 15:43:54 -070052 bool initialize(ANativeWindow* window);
53 void updateSurface(ANativeWindow* window);
54 void pauseSurface(ANativeWindow* window);
Chris Craik797b95b22014-05-20 18:10:25 -070055 void setup(int width, int height, const Vector3& lightCenter, float lightRadius);
John Reck63a06672014-05-07 13:45:54 -070056 void setOpaque(bool opaque);
John Reck860d1552014-04-11 19:15:05 -070057 void makeCurrent();
John Reckf9be7792014-05-02 18:21:16 -070058 void prepareDraw(const Vector<DeferredLayerUpdater*>* layerUpdaters, TreeInfo& info);
John Recke45b1fd2014-04-15 09:50:16 -070059 void draw(Rect* dirty);
John Reckfae904d2014-04-14 11:01:57 -070060 void destroyCanvasAndSurface();
John Reck23b797a2014-01-03 18:08:34 -080061
John Recke45b1fd2014-04-15 09:50:16 -070062 // IFrameCallback, Chroreographer-driven frame callback entry point
John Reck18f16e62014-05-02 16:46:41 -070063 virtual void doFrame();
John Recke45b1fd2014-04-15 09:50:16 -070064
John Reck19b6bcf2014-02-14 20:03:38 -080065 bool copyLayerInto(DeferredLayerUpdater* layer, SkBitmap* bitmap);
66
John Recke1628b72014-05-23 15:11:19 -070067 void flushCaches(Caches::FlushMode flushMode);
68
John Reck0d1f6342014-03-28 20:30:27 -070069 void invokeFunctor(Functor* functor);
John Reck23b797a2014-01-03 18:08:34 -080070
John Reckfc53ef272014-02-11 10:40:25 -080071 void runWithGlContext(RenderTask* task);
72
John Reck1949e792014-04-08 15:18:56 -070073 Layer* createRenderLayer(int width, int height);
74 Layer* createTextureLayer();
75
John Reck66f0be62014-05-13 13:39:31 -070076 ANDROID_API static void setTextureAtlas(const sp<GraphicBuffer>& buffer,
77 int64_t* map, size_t mapSize);
78
John Recka5dda642014-05-22 15:43:54 -070079 void notifyFramePending();
80
John Reckfe5e7b72014-05-23 17:42:28 -070081 DrawProfiler& profiler() { return mProfiler; }
82
John Reck23b797a2014-01-03 18:08:34 -080083private:
John Recka5dda642014-05-22 15:43:54 -070084 friend class RegisterFrameCallbackTask;
85
John Reckf9be7792014-05-02 18:21:16 -070086 void processLayerUpdates(const Vector<DeferredLayerUpdater*>* layerUpdaters, TreeInfo& info);
87 void prepareTree(TreeInfo& info);
88
John Recka5dda642014-05-22 15:43:54 -070089 void setSurface(ANativeWindow* window);
John Reck4f02bf42014-01-03 18:09:17 -080090 void swapBuffers();
John Reckf7d9c1d2014-04-09 10:01:03 -070091 void requireSurface();
John Reck4f02bf42014-01-03 18:09:17 -080092
John Reck19b6bcf2014-02-14 20:03:38 -080093 void requireGlContext();
94
John Reck23b797a2014-01-03 18:08:34 -080095 GlobalContext* mGlobalContext;
John Reck4f02bf42014-01-03 18:09:17 -080096 RenderThread& mRenderThread;
John Recka5dda642014-05-22 15:43:54 -070097 sp<ANativeWindow> mNativeWindow;
John Reck23b797a2014-01-03 18:08:34 -080098 EGLSurface mEglSurface;
99 bool mDirtyRegionsEnabled;
John Reck4f02bf42014-01-03 18:09:17 -0800100
101 bool mOpaque;
102 OpenGLRenderer* mCanvas;
103 bool mHaveNewSurface;
John Recke45b1fd2014-04-15 09:50:16 -0700104
105 const sp<RenderNode> mRootRenderNode;
John Reckfe5e7b72014-05-23 17:42:28 -0700106
107 DrawProfiler mProfiler;
John Reck23b797a2014-01-03 18:08:34 -0800108};
109
110} /* namespace renderthread */
111} /* namespace uirenderer */
112} /* namespace android */
113#endif /* CANVASCONTEXT_H_ */