Home | History | Annotate | Download | only in hwc2
      1 /*
      2  * Copyright (c) 2014-2016, The Linux Foundation. All rights reserved.
      3  * Not a Contribution.
      4  *
      5  * Copyright 2015 The Android Open Source Project
      6  *
      7  * Licensed under the Apache License, Version 2.0 (the "License");
      8  * you may not use this file except in compliance with the License.
      9  * You may obtain a copy of the License at
     10  *
     11  *      http://www.apache.org/licenses/LICENSE-2.0
     12  *
     13  * Unless required by applicable law or agreed to in writing, software
     14  * distributed under the License is distributed on an "AS IS" BASIS,
     15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     16  * See the License for the specific language governing permissions and
     17  * limitations under the License.
     18  */
     19 
     20 #ifndef __HWC_LAYERS_H__
     21 #define __HWC_LAYERS_H__
     22 
     23 /* This class translates HWC2 Layer functions to the SDM LayerStack
     24  */
     25 
     26 #include <gralloc_priv.h>
     27 #include <qdMetaData.h>
     28 #include <core/layer_stack.h>
     29 #define HWC2_INCLUDE_STRINGIFICATION
     30 #define HWC2_USE_CPP11
     31 #include <hardware/hwcomposer2.h>
     32 #undef HWC2_INCLUDE_STRINGIFICATION
     33 #undef HWC2_USE_CPP11
     34 #include <set>
     35 #include <map>
     36 #include <queue>
     37 
     38 namespace sdm {
     39 
     40 enum GeometryChanges {
     41   kNone         = 0x000,
     42   kBlendMode    = 0x001,
     43   kDataspace    = 0x002,
     44   kDisplayFrame = 0x004,
     45   kPlaneAlpha   = 0x008,
     46   kSourceCrop   = 0x010,
     47   kTransform    = 0x020,
     48   kZOrder       = 0x040,
     49   kAdded        = 0x080,
     50   kRemoved      = 0x100,
     51 };
     52 
     53 class HWCLayer {
     54  public:
     55   explicit HWCLayer(hwc2_display_t display_id);
     56   ~HWCLayer();
     57   uint32_t GetZ() const { return z_; }
     58   hwc2_layer_t GetId() const { return id_; }
     59   Layer *GetSDMLayer() { return layer_; }
     60 
     61   HWC2::Error SetLayerBlendMode(HWC2::BlendMode mode);
     62   HWC2::Error SetLayerBuffer(buffer_handle_t buffer, int32_t acquire_fence);
     63   HWC2::Error SetLayerColor(hwc_color_t color);
     64   HWC2::Error SetLayerCompositionType(HWC2::Composition type);
     65   HWC2::Error SetLayerDataspace(int32_t dataspace);
     66   HWC2::Error SetLayerDisplayFrame(hwc_rect_t frame);
     67   HWC2::Error SetLayerPlaneAlpha(float alpha);
     68   HWC2::Error SetLayerSourceCrop(hwc_frect_t crop);
     69   HWC2::Error SetLayerSurfaceDamage(hwc_region_t damage);
     70   HWC2::Error SetLayerTransform(HWC2::Transform transform);
     71   HWC2::Error SetLayerVisibleRegion(hwc_region_t visible);
     72   HWC2::Error SetLayerZOrder(uint32_t z);
     73   void SetComposition(const LayerComposition &sdm_composition);
     74   HWC2::Composition GetClientRequestedCompositionType() { return client_requested_; }
     75   void UpdateClientCompositionType(HWC2::Composition type) { client_requested_ = type; }
     76   HWC2::Composition GetDeviceSelectedCompositionType() { return device_selected_; }
     77   uint32_t GetGeometryChanges() { return geometry_changes_; }
     78   void ResetGeometryChanges() { geometry_changes_ = GeometryChanges::kNone; }
     79   void PushReleaseFence(int32_t fence);
     80   int32_t PopReleaseFence(void);
     81 
     82  private:
     83   Layer *layer_ = nullptr;
     84   uint32_t z_ = 0;
     85   const hwc2_layer_t id_;
     86   const hwc2_display_t display_id_;
     87   static std::atomic<hwc2_layer_t> next_id_;
     88   std::queue<int32_t> release_fences_;
     89   int ion_fd_ = -1;
     90 
     91   // Composition requested by client(SF)
     92   HWC2::Composition client_requested_ = HWC2::Composition::Device;
     93   // Composition selected by SDM
     94   HWC2::Composition device_selected_ = HWC2::Composition::Device;
     95   uint32_t geometry_changes_ = GeometryChanges::kNone;
     96 
     97   void SetRect(const hwc_rect_t &source, LayerRect *target);
     98   void SetRect(const hwc_frect_t &source, LayerRect *target);
     99   uint32_t GetUint32Color(const hwc_color_t &source);
    100   LayerBufferFormat GetSDMFormat(const int32_t &source, const int flags);
    101   LayerBufferS3DFormat GetS3DFormat(uint32_t s3d_format);
    102   DisplayError SetMetaData(const private_handle_t *pvt_handle, Layer *layer);
    103   DisplayError SetCSC(ColorSpace_t source, LayerCSC *target);
    104   DisplayError SetIGC(IGC_t source, LayerIGC *target);
    105   uint32_t RoundToStandardFPS(float fps);
    106 };
    107 
    108 struct SortLayersByZ {
    109   bool operator()(const HWCLayer *lhs, const HWCLayer *rhs) {
    110     return lhs->GetZ() < rhs->GetZ();
    111   }
    112 };
    113 
    114 }  // namespace sdm
    115 #endif  // __HWC_LAYERS_H__
    116