Home | History | Annotate | Download | only in renderthread
      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 <vector>
     20 
     21 #include <utils/Condition.h>
     22 #include <utils/Mutex.h>
     23 #include <utils/StrongPointer.h>
     24 
     25 #include "RenderTask.h"
     26 
     27 #include "../Rect.h"
     28 #include "../FrameInfo.h"
     29 #include "../TreeInfo.h"
     30 
     31 namespace android {
     32 namespace uirenderer {
     33 
     34 class DeferredLayerUpdater;
     35 class DisplayList;
     36 class RenderNode;
     37 
     38 namespace renderthread {
     39 
     40 class CanvasContext;
     41 class RenderThread;
     42 
     43 namespace SyncResult {
     44 enum {
     45     OK = 0,
     46     UIRedrawRequired = 1 << 0,
     47     LostSurfaceRewardIfFound = 1 << 1,
     48     ContextIsStopped = 1 << 2,
     49 };
     50 }
     51 
     52 /*
     53  * This is a special Super Task. It is re-used multiple times by RenderProxy,
     54  * and contains state (such as layer updaters & new DisplayLists) that is
     55  * tracked across many frames not just a single frame.
     56  * It is the sync-state task, and will kick off the post-sync draw
     57  */
     58 class DrawFrameTask : public RenderTask {
     59 public:
     60     DrawFrameTask();
     61     virtual ~DrawFrameTask();
     62 
     63     void setContext(RenderThread* thread, CanvasContext* context, RenderNode* targetNode);
     64 
     65     void pushLayerUpdate(DeferredLayerUpdater* layer);
     66     void removeLayerUpdate(DeferredLayerUpdater* layer);
     67 
     68     int drawFrame(TreeObserver* observer);
     69 
     70     int64_t* frameInfo() { return mFrameInfo; }
     71 
     72     virtual void run() override;
     73 
     74 private:
     75     void postAndWait();
     76     bool syncFrameState(TreeInfo& info);
     77     void unblockUiThread();
     78 
     79     Mutex mLock;
     80     Condition mSignal;
     81 
     82     RenderThread* mRenderThread;
     83     CanvasContext* mContext;
     84     RenderNode* mTargetNode = nullptr;
     85 
     86     /*********************************************
     87      *  Single frame data
     88      *********************************************/
     89     std::vector< sp<DeferredLayerUpdater> > mLayers;
     90 
     91     int mSyncResult;
     92     int64_t mSyncQueued;
     93     TreeObserver* mObserver;
     94 
     95     int64_t mFrameInfo[UI_THREAD_FRAME_INFO_SIZE];
     96 };
     97 
     98 } /* namespace renderthread */
     99 } /* namespace uirenderer */
    100 } /* namespace android */
    101 
    102 #endif /* DRAWFRAMETASK_H */
    103