Home | History | Annotate | Download | only in legacy
      1 #pragma once
      2 /*
      3  * Copyright (C) 2016 The Android Open Source Project
      4  *
      5  * Licensed under the Apache License, Version 2.0 (the "License");
      6  * you may not use this file except in compliance with the License.
      7  * You may obtain a copy of the License at
      8  *
      9  *      http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  * Unless required by applicable law or agreed to in writing, software
     12  * distributed under the License is distributed on an "AS IS" BASIS,
     13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  * See the License for the specific language governing permissions and
     15  * limitations under the License.
     16  */
     17 
     18 #include <functional>
     19 
     20 #include <hardware/gralloc.h>
     21 #include "hwcomposer_common.h"
     22 
     23 namespace cvd {
     24 
     25 using FbBroadcaster = std::function<void(int)>;
     26 
     27 class BaseComposer {
     28  public:
     29   BaseComposer(int64_t vsync_base_timestamp, int32_t vsync_period_ns);
     30   ~BaseComposer();
     31 
     32   // Sets the composition type of each layer and returns the number of layers
     33   // to be composited by the hwcomposer.
     34   int PrepareLayers(size_t num_layers, vsoc_hwc_layer* layers);
     35   // Returns 0 if successful.
     36   int SetLayers(size_t num_layers, vsoc_hwc_layer* layers);
     37   // Changes the broadcaster, gives the ability to report more than just the
     38   // offset by using a wrapper like the StatsKeepingComposer. Returns the old
     39   // broadcaster. Passing a NULL pointer will cause the composer to not
     40   // broadcast at all.
     41   FbBroadcaster ReplaceFbBroadcaster(FbBroadcaster);
     42   void Dump(char* buff, int buff_len);
     43 
     44  protected:
     45   void Broadcast(int32_t offset);
     46   int NextScreenBuffer();
     47 
     48   const gralloc_module_t* gralloc_module_;
     49   int64_t vsync_base_timestamp_;
     50   int32_t vsync_period_ns_;
     51   int last_frame_buffer_ = -1; // The first index will be 0
     52 
     53  private:
     54   // Returns buffer offset or negative on error.
     55   int PostFrameBufferTarget(buffer_handle_t handle);
     56   FbBroadcaster fb_broadcaster_;
     57 };
     58 
     59 }  // namespace cvd
     60