OSDN Git Service

Remove redundant checks in overlaylayer.
authorKalyan Kondapally <kalyan.kondapally@intel.com>
Sat, 23 Dec 2017 10:36:46 +0000 (02:36 -0800)
committerKalyan Kondapally <kalyan.kondapally@intel.com>
Sun, 24 Dec 2017 00:27:23 +0000 (16:27 -0800)
Jira: None.
Test: Build passes on Android.

Signed-off-by: Kalyan Kondapally <kalyan.kondapally@intel.com>
common/core/hwclayer.cpp
common/core/overlaylayer.cpp
common/core/overlaylayer.h
common/display/displayplanemanager.cpp
common/display/displayqueue.cpp
public/hwclayer.h

index 1fe2575..edb4fe9 100644 (file)
@@ -45,14 +45,12 @@ void HwcLayer::SetTransform(int32_t transform) {
 
 void HwcLayer::SetAlpha(uint8_t alpha) {
   if (alpha_ != alpha) {
-    layer_cache_ |= kDIsplayContentAttributesChanged;
     alpha_ = alpha;
   }
 }
 
 void HwcLayer::SetBlending(HWCBlending blending) {
   if (blending != blending_) {
-    layer_cache_ |= kDIsplayContentAttributesChanged;
     blending_ = blending;
   }
 }
@@ -190,7 +188,6 @@ void HwcLayer::Validate() {
   state_ &= ~kSurfaceDamageChanged;
   layer_cache_ &= ~kLayerAttributesChanged;
   layer_cache_ &= ~kDisplayFrameRectChanged;
-  layer_cache_ &= ~kDIsplayContentAttributesChanged;
   layer_cache_ &= ~kSourceRectChanged;
   if (left_constraint_.empty() && left_source_constraint_.empty())
     return;
index 809c29b..8990ae1 100644 (file)
@@ -228,8 +228,7 @@ void OverlayLayer::InitializeState(HwcLayer* layer,
     ValidatePreviousFrameState(previous_layer, layer);
   }
 
-  if (layer->HasContentAttributesChanged() ||
-      layer->HasLayerAttributesChanged() || !layer->IsValidated()) {
+  if (layer->HasLayerAttributesChanged() || !layer->IsValidated()) {
     state_ |= kClearSurface;
     state_ |= kLayerContentChanged;
   }
@@ -359,8 +358,18 @@ void OverlayLayer::ValidatePreviousFrameState(OverlayLayer* rhs,
   }
 
   // We expect cursor plane to support alpha always.
-  if (rhs->gpu_rendered_ || (type_ == kLayerCursor)) {
+  if (gpu_rendered_ || (type_ == kLayerCursor)) {
     content_changed = rect_changed || source_rect_changed;
+
+    if (!content_changed) {
+      if (alpha_ != rhs->alpha_) {
+        content_changed = true;
+      }
+
+      if (blending_ != rhs->blending_) {
+        content_changed = true;
+      }
+    }
   } else {
     // If previous layer was opaque and we have alpha now,
     // let's mark this layer for re-validation. Plane
@@ -378,23 +387,8 @@ void OverlayLayer::ValidatePreviousFrameState(OverlayLayer* rhs,
     }
 
     if (rect_changed || layer->HasLayerAttributesChanged()) {
-      if (layer->IsValidated()) {
-        state_ |= kNeedsReValidation;
-        return;
-      }
-
-      if (rhs->transform_ != transform_) {
-        state_ |= kNeedsReValidation;
-        return;
-      }
-
-      if ((rhs->display_frame_.left != display_frame_.left) ||
-          (rhs->display_frame_.right != display_frame_.right) ||
-          (rhs->display_frame_.top != display_frame_.top) ||
-          (rhs->display_frame_.bottom != display_frame_.bottom)) {
-        state_ |= kNeedsReValidation;
-        return;
-      }
+      state_ |= kNeedsReValidation;
+      return;
     }
 
     if (source_rect_changed) {
index a516265..fdcb2d2 100644 (file)
@@ -133,8 +133,10 @@ struct OverlayLayer {
     return !(state_ & kInvisible);
   }
 
-  void GPURendered() {
-    gpu_rendered_ = true;
+  // If value is true than it inidicates the
+  // layer needs to be gpu rendered.
+  void GPURendered(bool value) {
+    gpu_rendered_ = value;
   }
 
   bool IsCursorLayer() const {
index 2cef97c..50b9289 100644 (file)
@@ -64,10 +64,6 @@ bool DisplayPlaneManager::ValidateLayers(
     std::vector<OverlayLayer *> &cursor_layers, bool pending_modeset,
     bool disable_overlay, DisplayPlaneStateList &composition) {
   CTRACE();
-  // Let's mark all planes as free to be used.
-  for (auto j = overlay_planes_.begin(); j != overlay_planes_.end(); ++j) {
-    j->get()->SetInUse(false);
-  }
 
   bool force_gpu = disable_overlay || (pending_modeset && (layers.size() > 1));
 
@@ -78,6 +74,19 @@ bool DisplayPlaneManager::ValidateLayers(
     return true;
   }
 
+  // Let's mark all planes as free to be used.
+  for (auto j = overlay_planes_.begin(); j != overlay_planes_.end(); ++j) {
+    j->get()->SetInUse(false);
+  }
+
+  // Let's reset some of the layer's state.
+  size_t size = layers.size();
+  for (size_t i = 0; i != size; ++i) {
+    OverlayLayer &layer = layers.at(i);
+    layer.GPURendered(false);
+    layer.UsePlaneScalar(false);
+  }
+
   std::vector<OverlayPlane> commit_planes;
   auto layer_begin = layers.begin();
   auto layer_end = layers.end();
@@ -215,7 +224,7 @@ bool DisplayPlaneManager::ValidateLayers(
         for (size_t i = 0; i < layers_size; i++) {
           size_t source_index = source_layers.at(i);
           OverlayLayer &layer = layers.at(source_index);
-          layer.GPURendered();
+          layer.GPURendered(true);
           layer.UsePlaneScalar(useplanescalar);
         }
       }
@@ -243,21 +252,23 @@ bool DisplayPlaneManager::ReValidateLayers(std::vector<OverlayLayer> &layers,
   }
 
   bool render_layers = false;
-  // If this combination fails just fall back to 3D for all layers.
+  // If this combination fails just fall back to full validation.
   if (plane_handler_->TestCommit(commit_planes)) {
     *request_full_validation = false;
     for (DisplayPlaneState &plane : composition) {
-      if (plane.NeedsOffScreenComposition()) {
+      const std::vector<size_t> &source_layers = plane.GetSourceLayers();
+      size_t layers_size = source_layers.size();
+      bool useplanescalar = plane.IsUsingPlaneScalar();
+      bool use_gpu = plane.NeedsOffScreenComposition();
+      if (use_gpu) {
         render_layers = true;
-        const std::vector<size_t> &source_layers = plane.GetSourceLayers();
-        size_t layers_size = source_layers.size();
-        bool useplanescalar = plane.IsUsingPlaneScalar();
-        for (size_t i = 0; i < layers_size; i++) {
-          size_t source_index = source_layers.at(i);
-          OverlayLayer &layer = layers.at(source_index);
-          layer.GPURendered();
-          layer.UsePlaneScalar(useplanescalar);
-        }
+      }
+
+      for (size_t i = 0; i < layers_size; i++) {
+        size_t source_index = source_layers.at(i);
+        OverlayLayer &layer = layers.at(source_index);
+        layer.GPURendered(use_gpu);
+        layer.UsePlaneScalar(useplanescalar);
       }
     }
   } else {
@@ -346,7 +357,7 @@ bool DisplayPlaneManager::ValidateCursorLayer(
     // cursor layer cannot be scanned out directly.
     if (FallbacktoGPU(plane, cursor_layer, commit_planes)) {
       commit_planes.pop_back();
-      cursor_layer->GPURendered();
+      cursor_layer->GPURendered(true);
       last_plane->AddLayer(cursor_layer);
       bool reset_overlay = false;
       if (!last_plane->GetOffScreenTarget() || is_video)
@@ -382,7 +393,7 @@ bool DisplayPlaneManager::ValidateCursorLayer(
   for (uint32_t i = cursor_index; i < total_size; i++) {
     OverlayLayer *cursor_layer = cursor_layers.at(i);
     last_plane->AddLayer(cursor_layer);
-    cursor_layer->GPURendered();
+    cursor_layer->GPURendered(true);
     status = true;
     last_layer = cursor_layer;
   }
@@ -575,16 +586,7 @@ void DisplayPlaneManager::ValidateFinalLayers(
 
   // If this combination fails just fall back to 3D for all layers.
   if (!plane_handler_->TestCommit(commit_planes)) {
-    // We start off with Primary plane.
-    DisplayPlane *current_plane = overlay_planes_.at(0).get();
-    for (DisplayPlaneState &plane : composition) {
-      if (plane.GetOffScreenTarget()) {
-        plane.GetOffScreenTarget()->SetInUse(false);
-      }
-    }
-
     ForceGpuForAllLayers(composition, layers);
-    ReleaseFreeOffScreenTargets();
   }
 }
 
@@ -615,6 +617,21 @@ bool DisplayPlaneManager::CheckPlaneFormat(uint32_t format) {
 
 void DisplayPlaneManager::ForceGpuForAllLayers(
     DisplayPlaneStateList &composition, std::vector<OverlayLayer> &layers) {
+  // Let's mark all planes as free to be used.
+  for (auto j = overlay_planes_.begin(); j != overlay_planes_.end(); ++j) {
+    j->get()->SetInUse(false);
+  }
+
+  bool free_surfaces = !composition.empty();
+
+  if (free_surfaces) {
+    for (DisplayPlaneState &plane : composition) {
+      if (plane.GetOffScreenTarget()) {
+        plane.GetOffScreenTarget()->SetInUse(false);
+      }
+    }
+  }
+
   auto layer_begin = layers.begin();
   auto layer_end = layers.end();
   DisplayPlaneStateList().swap(composition);
@@ -628,11 +645,15 @@ void DisplayPlaneManager::ForceGpuForAllLayers(
 
   for (auto i = layer_begin; i != layer_end; ++i) {
     last_plane.AddLayer(&(*(i)));
-    i->GPURendered();
+    i->GPURendered(true);
   }
 
   EnsureOffScreenTarget(last_plane);
   current_plane->SetInUse(true);
+
+  if (free_surfaces) {
+    ReleaseFreeOffScreenTargets();
+  }
 }
 
 }  // namespace hwcomposer
index 813fd11..1c489cb 100644 (file)
@@ -250,7 +250,7 @@ void DisplayQueue::GetCachedLayers(const std::vector<OverlayLayer>& layers,
           &(*(layers.begin() + last_plane.GetSourceLayers().front()));
       OverlayBuffer* buffer = layer->GetBuffer();
       if (buffer->GetFb() == 0) {
-        layer->GetBuffer()->CreateFrameBuffer(gpu_fd_);
+        buffer->CreateFrameBuffer(gpu_fd_);
 
         // FB creation failed, we need to re-validate the
         // whole commit.
index e06b065..9c53231 100644 (file)
@@ -174,16 +174,6 @@ struct HwcLayer {
   }
 
   /**
-   * API for querying if layer attributes has
-   * changed from last Present call to NativeDisplay.
-   * This takes into consideration any changes to
-   * alpha and blending.
-   */
-  bool HasContentAttributesChanged() const {
-    return layer_cache_ & kDIsplayContentAttributesChanged;
-  }
-
-  /**
    * API for setting release fence for this layer.
    * @param fd will be populated with Native Fence object.
    *        When fd is signalled, any previous frame
@@ -266,8 +256,7 @@ struct HwcLayer {
   enum LayerCache {
     kLayerAttributesChanged = 1 << 0,
     kDisplayFrameRectChanged = 1 << 1,
-    kDIsplayContentAttributesChanged = 1 << 2,
-    kSourceRectChanged = 1 << 3
+    kSourceRectChanged = 1 << 2
   };
 
   int32_t transform_ = 0;
@@ -290,8 +279,7 @@ struct HwcLayer {
   std::vector<int32_t> right_source_constraint_;
   uint32_t z_order_ = 0;
   int state_ = kVisible | kSurfaceDamageChanged | kVisibleRegionChanged;
-  int layer_cache_ = kLayerAttributesChanged | kDisplayFrameRectChanged |
-                     kDIsplayContentAttributesChanged;
+  int layer_cache_ = kLayerAttributesChanged | kDisplayFrameRectChanged;
 };
 
 }  // namespace hwcomposer