John Reck | 23b797a | 2014-01-03 18:08:34 -0800 | [diff] [blame] | 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 | |
| 17 | #ifndef CANVASCONTEXT_H_ |
| 18 | #define CANVASCONTEXT_H_ |
| 19 | |
| 20 | #include <cutils/compiler.h> |
| 21 | #include <EGL/egl.h> |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 22 | #include <utils/Functor.h> |
| 23 | |
| 24 | #include "RenderTask.h" |
| 25 | |
| 26 | #define FUNCTOR_PROCESS_DELAY 4 |
John Reck | 23b797a | 2014-01-03 18:08:34 -0800 | [diff] [blame] | 27 | |
| 28 | namespace android { |
| 29 | namespace uirenderer { |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 30 | |
| 31 | class DisplayList; |
| 32 | class OpenGLRenderer; |
| 33 | class Rect; |
| 34 | |
John Reck | 23b797a | 2014-01-03 18:08:34 -0800 | [diff] [blame] | 35 | namespace renderthread { |
| 36 | |
| 37 | class GlobalContext; |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 38 | class CanvasContext; |
| 39 | class RenderThread; |
| 40 | |
| 41 | class InvokeFunctorsTask : public RenderTask { |
| 42 | public: |
| 43 | InvokeFunctorsTask(CanvasContext* context) |
| 44 | : mContext(context) {} |
| 45 | |
| 46 | virtual void run(); |
| 47 | |
| 48 | private: |
| 49 | CanvasContext* mContext; |
| 50 | }; |
John Reck | 23b797a | 2014-01-03 18:08:34 -0800 | [diff] [blame] | 51 | |
| 52 | // This per-renderer class manages the bridge between the global EGL context |
| 53 | // and the render surface. |
| 54 | class CanvasContext { |
| 55 | public: |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 56 | CanvasContext(bool translucent); |
| 57 | ~CanvasContext(); |
John Reck | 23b797a | 2014-01-03 18:08:34 -0800 | [diff] [blame] | 58 | |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 59 | bool initialize(EGLNativeWindowType window); |
| 60 | void updateSurface(EGLNativeWindowType window); |
| 61 | void setup(int width, int height); |
| 62 | void drawDisplayList(DisplayList* displayList, Rect* dirty); |
| 63 | void destroyCanvas(); |
John Reck | 23b797a | 2014-01-03 18:08:34 -0800 | [diff] [blame] | 64 | |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 65 | void attachFunctor(Functor* functor); |
| 66 | void detachFunctor(Functor* functor); |
John Reck | 23b797a | 2014-01-03 18:08:34 -0800 | [diff] [blame] | 67 | |
John Reck | fc53ef27 | 2014-02-11 10:40:25 -0800 | [diff] [blame] | 68 | void runWithGlContext(RenderTask* task); |
| 69 | |
John Reck | 23b797a | 2014-01-03 18:08:34 -0800 | [diff] [blame] | 70 | private: |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 71 | void setSurface(EGLNativeWindowType window); |
| 72 | void swapBuffers(); |
| 73 | void makeCurrent(); |
| 74 | |
| 75 | friend class InvokeFunctorsTask; |
| 76 | void invokeFunctors(); |
| 77 | void handleFunctorStatus(int status, const Rect& redrawClip); |
| 78 | void removeFunctorsTask(); |
| 79 | void queueFunctorsTask(int delayMs = FUNCTOR_PROCESS_DELAY); |
John Reck | 23b797a | 2014-01-03 18:08:34 -0800 | [diff] [blame] | 80 | |
| 81 | GlobalContext* mGlobalContext; |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 82 | RenderThread& mRenderThread; |
John Reck | 23b797a | 2014-01-03 18:08:34 -0800 | [diff] [blame] | 83 | EGLSurface mEglSurface; |
| 84 | bool mDirtyRegionsEnabled; |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 85 | |
| 86 | bool mOpaque; |
| 87 | OpenGLRenderer* mCanvas; |
| 88 | bool mHaveNewSurface; |
| 89 | |
| 90 | bool mInvokeFunctorsPending; |
| 91 | InvokeFunctorsTask mInvokeFunctorsTask; |
| 92 | |
John Reck | 23b797a | 2014-01-03 18:08:34 -0800 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | } /* namespace renderthread */ |
| 96 | } /* namespace uirenderer */ |
| 97 | } /* namespace android */ |
| 98 | #endif /* CANVASCONTEXT_H_ */ |