From: Kalyan Kondapally Date: Fri, 25 Aug 2017 05:03:49 +0000 (-0700) Subject: Allocate buffers of needed size only. X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=9c9c704;p=android-x86%2Fexternal-IA-Hardware-Composer.git Allocate buffers of needed size only. Currently, when falling back to 3D Composition, we allocate buffers equal to that of resolution. Instead, let's allocate buffer equal to size of the display rect of plane. Change-Id: Ifb26a9d45af47926e0b0791aac191ad08243bddc Jira: None. Test: No graphics regressions on Android. Signed-off-by: Kalyan Kondapally --- diff --git a/common/compositor/nativesurface.cpp b/common/compositor/nativesurface.cpp index 3358a23..10d33bd 100644 --- a/common/compositor/nativesurface.cpp +++ b/common/compositor/nativesurface.cpp @@ -77,12 +77,12 @@ void NativeSurface::SetPlaneTarget(DisplayPlaneState &plane, uint32_t gpu_fd) { plane.plane()->GetFormatForFrameBuffer(layer_.GetBuffer()->GetFormat()); const HwcRect &display_rect = plane.GetDisplayFrame(); - layer_.SetSourceCrop(HwcRect(display_rect)); - layer_.SetDisplayFrame(HwcRect(display_rect)); surface_damage_ = display_rect; last_surface_damage_ = surface_damage_; width_ = display_rect.right - display_rect.left; height_ = display_rect.bottom - display_rect.top; + layer_.SetSourceCrop(HwcRect(0, 0, width_, height_)); + layer_.SetDisplayFrame(HwcRect(display_rect)); plane.SetOverlayLayer(&layer_); SetInUse(true); @@ -99,10 +99,10 @@ void NativeSurface::RecycleSurface(DisplayPlaneState &plane) { SetInUse(true); layer_.SetAcquireFence(-1); const HwcRect &display_rect = plane.GetDisplayFrame(); - layer_.SetSourceCrop(HwcRect(display_rect)); - layer_.SetDisplayFrame(HwcRect(display_rect)); width_ = display_rect.right - display_rect.left; height_ = display_rect.bottom - display_rect.top; + layer_.SetSourceCrop(HwcRect(0, 0, width_, height_)); + layer_.SetDisplayFrame(HwcRect(display_rect)); } void NativeSurface::UpdateSurfaceDamage( diff --git a/common/core/overlaylayer.cpp b/common/core/overlaylayer.cpp index c301058..09338b5 100644 --- a/common/core/overlaylayer.cpp +++ b/common/core/overlaylayer.cpp @@ -125,6 +125,7 @@ void OverlayLayer::ValidatePreviousFrameState(const OverlayLayer& rhs, HwcLayer* layer) { OverlayBuffer* buffer = imported_buffer_->buffer_.get(); surface_damage_ = layer->GetSurfaceDamage(); + gpu_rendered_ = rhs.gpu_rendered_; if (!prefer_separate_plane_) prefer_separate_plane_ = rhs.prefer_separate_plane_; @@ -132,14 +133,14 @@ void OverlayLayer::ValidatePreviousFrameState(const OverlayLayer& rhs, return; bool content_changed = false; + bool rect_changed = layer->HasDisplayRectChanged(); // We expect cursor plane to support alpha always. - if (rhs.gpu_rendered_ || (buffer->GetUsage() & kLayerCursor)) { - content_changed = alpha_ != rhs.alpha_ || layer->HasDisplayRectChanged() || + if ((gpu_rendered_ && !rect_changed) || (buffer->GetUsage() & kLayerCursor)) { + content_changed = (alpha_ != rhs.alpha_) || rect_changed || layer->HasContentAttributesChanged() || layer->HasLayerAttributesChanged(); - gpu_rendered_ = rhs.gpu_rendered_; } else { - if (alpha_ != rhs.alpha_ || layer->HasDisplayRectChanged() || + if (alpha_ != rhs.alpha_ || rect_changed || layer->HasContentAttributesChanged() || layer->HasLayerAttributesChanged()) return; @@ -147,7 +148,7 @@ void OverlayLayer::ValidatePreviousFrameState(const OverlayLayer& rhs, state_ &= ~kLayerAttributesChanged; - if (!layer->HasDisplayRectChanged()) { + if (!rect_changed) { state_ &= ~kDimensionsChanged; } diff --git a/common/display/displayplanemanager.cpp b/common/display/displayplanemanager.cpp index d6ceade..db3ef12 100644 --- a/common/display/displayplanemanager.cpp +++ b/common/display/displayplanemanager.cpp @@ -289,15 +289,19 @@ void DisplayPlaneManager::ReleaseFreeOffScreenTargets() { void DisplayPlaneManager::EnsureOffScreenTarget(DisplayPlaneState &plane) { NativeSurface *surface = NULL; + const HwcRect &rect = plane.GetDisplayFrame(); + int width = rect.right - rect.left; + int height = rect.bottom - rect.top; for (auto &fb : surfaces_) { - if (!fb->InUse()) { + if (!fb->InUse() && (width == fb->GetWidth()) && + (height == fb->GetHeight())) { surface = fb.get(); break; } } if (!surface) { - NativeSurface *new_surface = CreateBackBuffer(width_, height_); + NativeSurface *new_surface = CreateBackBuffer(width, height); new_surface->Init(buffer_handler_); surfaces_.emplace_back(std::move(new_surface)); surface = surfaces_.back().get(); diff --git a/common/display/displayqueue.cpp b/common/display/displayqueue.cpp index 6caf8c9..5d6fbc3 100644 --- a/common/display/displayqueue.cpp +++ b/common/display/displayqueue.cpp @@ -170,8 +170,14 @@ void DisplayQueue::GetCachedLayers(const std::vector& layers, } } - plane.TransferSurfaces( - last_plane, content_changed || region_changed || reset_regions); + if (!region_changed && !reset_regions) { + plane.TransferSurfaces(last_plane, content_changed); + const std::vector& comp_regions = + plane.GetCompositionRegion(); + last_plane.GetCompositionRegion().assign(comp_regions.begin(), + comp_regions.end()); + } + if (content_changed || region_changed || reset_regions) { if (last_plane.GetSurfaces().size() == 3) { NativeSurface* surface = last_plane.GetOffScreenTarget(); @@ -192,13 +198,6 @@ void DisplayQueue::GetCachedLayers(const std::vector& layers, surface->RecycleSurface(last_plane); last_plane.ReUseOffScreenTarget(); } - - if (!region_changed && !reset_regions) { - const std::vector& comp_regions = - plane.GetCompositionRegion(); - last_plane.GetCompositionRegion().assign(comp_regions.begin(), - comp_regions.end()); - } } else { const OverlayLayer* layer = &(*(layers.begin() + last_plane.source_layers().front())); diff --git a/common/display/vblankeventhandler.cpp b/common/display/vblankeventhandler.cpp index a034cfe..1b15b9b 100644 --- a/common/display/vblankeventhandler.cpp +++ b/common/display/vblankeventhandler.cpp @@ -88,7 +88,7 @@ int VblankEventHandler::VSyncControl(bool enabled) { void VblankEventHandler::HandlePageFlipEvent(unsigned int sec, unsigned int usec) { - int64_t timestamp = (int64_t)sec * kOneSecondNs + (int64_t)usec * 1000; + int64_t timestamp = ((int64_t)sec * kOneSecondNs) + ((int64_t)usec * 1000); IPAGEFLIPEVENTTRACE("HandleVblankCallBack Frame Time %f", static_cast(timestamp - last_timestamp_) / (1000)); last_timestamp_ = timestamp;