John Reck | 668f0e3 | 2014-03-26 15:10:40 -0700 | [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 | #ifndef DRAWFRAMETASK_H |
| 17 | #define DRAWFRAMETASK_H |
| 18 | |
| 19 | #include <utils/Condition.h> |
| 20 | #include <utils/Mutex.h> |
John Reck | 087bc0c | 2014-04-04 16:20:08 -0700 | [diff] [blame] | 21 | #include <utils/StrongPointer.h> |
John Reck | 668f0e3 | 2014-03-26 15:10:40 -0700 | [diff] [blame] | 22 | #include <utils/Vector.h> |
| 23 | |
| 24 | #include "RenderTask.h" |
| 25 | |
| 26 | #include "../Rect.h" |
| 27 | |
| 28 | namespace android { |
| 29 | namespace uirenderer { |
| 30 | |
| 31 | class DeferredLayerUpdater; |
| 32 | class DisplayListData; |
| 33 | class RenderNode; |
| 34 | |
| 35 | namespace renderthread { |
| 36 | |
| 37 | class CanvasContext; |
| 38 | class RenderThread; |
| 39 | |
John Reck | f9be779 | 2014-05-02 18:21:16 -0700 | [diff] [blame^] | 40 | enum SyncResult { |
| 41 | kSync_OK = 0, |
| 42 | kSync_UIRedrawRequired = 1 << 1, |
| 43 | }; |
| 44 | |
John Reck | 668f0e3 | 2014-03-26 15:10:40 -0700 | [diff] [blame] | 45 | /* |
| 46 | * This is a special Super Task. It is re-used multiple times by RenderProxy, |
| 47 | * and contains state (such as layer updaters & new DisplayListDatas) that is |
| 48 | * tracked across many frames not just a single frame. |
| 49 | * It is the sync-state task, and will kick off the post-sync draw |
| 50 | */ |
| 51 | class DrawFrameTask : public RenderTask { |
| 52 | public: |
| 53 | DrawFrameTask(); |
| 54 | virtual ~DrawFrameTask(); |
| 55 | |
John Reck | 18f16e6 | 2014-05-02 16:46:41 -0700 | [diff] [blame] | 56 | void setContext(RenderThread* thread, CanvasContext* context); |
John Reck | 668f0e3 | 2014-03-26 15:10:40 -0700 | [diff] [blame] | 57 | |
John Reck | 668f0e3 | 2014-03-26 15:10:40 -0700 | [diff] [blame] | 58 | void addLayer(DeferredLayerUpdater* layer); |
| 59 | void removeLayer(DeferredLayerUpdater* layer); |
| 60 | |
John Reck | 668f0e3 | 2014-03-26 15:10:40 -0700 | [diff] [blame] | 61 | void setDirty(int left, int top, int right, int bottom); |
John Reck | f9be779 | 2014-05-02 18:21:16 -0700 | [diff] [blame^] | 62 | int drawFrame(nsecs_t frameTimeNanos); |
John Reck | 668f0e3 | 2014-03-26 15:10:40 -0700 | [diff] [blame] | 63 | |
| 64 | virtual void run(); |
| 65 | |
| 66 | private: |
John Reck | 18f16e6 | 2014-05-02 16:46:41 -0700 | [diff] [blame] | 67 | void postAndWait(); |
John Reck | f4198b7 | 2014-04-09 17:00:04 -0700 | [diff] [blame] | 68 | bool syncFrameState(); |
John Reck | 668f0e3 | 2014-03-26 15:10:40 -0700 | [diff] [blame] | 69 | void unblockUiThread(); |
John Reck | 668f0e3 | 2014-03-26 15:10:40 -0700 | [diff] [blame] | 70 | |
John Reck | 668f0e3 | 2014-03-26 15:10:40 -0700 | [diff] [blame] | 71 | Mutex mLock; |
| 72 | Condition mSignal; |
| 73 | |
John Reck | 18f16e6 | 2014-05-02 16:46:41 -0700 | [diff] [blame] | 74 | RenderThread* mRenderThread; |
John Reck | 668f0e3 | 2014-03-26 15:10:40 -0700 | [diff] [blame] | 75 | CanvasContext* mContext; |
| 76 | |
| 77 | /********************************************* |
| 78 | * Single frame data |
| 79 | *********************************************/ |
John Reck | 668f0e3 | 2014-03-26 15:10:40 -0700 | [diff] [blame] | 80 | Rect mDirty; |
John Reck | 18f16e6 | 2014-05-02 16:46:41 -0700 | [diff] [blame] | 81 | nsecs_t mFrameTimeNanos; |
John Reck | 668f0e3 | 2014-03-26 15:10:40 -0700 | [diff] [blame] | 82 | |
John Reck | f9be779 | 2014-05-02 18:21:16 -0700 | [diff] [blame^] | 83 | int mSyncResult; |
| 84 | |
John Reck | 668f0e3 | 2014-03-26 15:10:40 -0700 | [diff] [blame] | 85 | /********************************************* |
| 86 | * Multi frame data |
| 87 | *********************************************/ |
| 88 | Vector<DeferredLayerUpdater*> mLayers; |
| 89 | }; |
| 90 | |
| 91 | } /* namespace renderthread */ |
| 92 | } /* namespace uirenderer */ |
| 93 | } /* namespace android */ |
| 94 | |
| 95 | #endif /* DRAWFRAMETASK_H */ |