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