1 /*
2  * Copyright (C) 2016 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 #pragma once
18 
19 #include <memory>
20 
21 #include "guest/hals/hwcomposer/common/gralloc_utils.h"
22 #include "guest/hals/hwcomposer/common/hwcomposer.h"
23 #include "guest/hals/hwcomposer/common/screen_view.h"
24 
25 namespace cuttlefish {
26 
27 class BaseComposer {
28  public:
29   BaseComposer(std::unique_ptr<ScreenView> screen_view);
30   virtual ~BaseComposer() = default;
31 
32   virtual bool IsValidLayer(const hwc_layer_1_t& layer);
33   // Sets the composition type of each layer and returns the number of layers
34   // to be composited by the hwcomposer.
35   virtual int PrepareLayers(size_t num_layers, hwc_layer_1_t* layers);
36   // Returns 0 if successful.
37   virtual int SetLayers(size_t num_layers, hwc_layer_1_t* layers);
38   virtual void Dump(char* buff, int buff_len);
39 
x_res()40   int32_t x_res() { return screen_view_->x_res(); }
y_res()41   int32_t y_res() { return screen_view_->y_res(); }
dpi()42   int32_t dpi() { return screen_view_->dpi(); }
refresh_rate()43   int32_t refresh_rate() { return screen_view_->refresh_rate(); }
44 
45  protected:
46   std::unique_ptr<ScreenView> screen_view_;
47   Gralloc gralloc_;
48 
49  private:
50   // Returns buffer offset or negative on error.
51   int PostFrameBufferTarget(buffer_handle_t handle);
52 };
53 }  // namespace cuttlefish
54