Skip to content

Commit

Permalink
::Huawei:: Fix damage for Huawei compositor
Browse files Browse the repository at this point in the history
For Huawei compositor, the damage area is a region on the screen.
But for SurfaceFlinger, this is a region on the source surface.
On Huawei devices, do the plane conversion.

This fixes several UI glitches, most notably GBoard.

Change-Id: I99b6035d9a3338619d16575e43388ad490af90a2
  • Loading branch information
phhusson committed Jan 13, 2018
1 parent 632d84f commit cdc0f4b
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
38 changes: 34 additions & 4 deletions services/surfaceflinger/Layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -812,10 +812,40 @@ void Layer::setPerFrameData(const sp<const DisplayDevice>& displayDevice) {
visible.dump(LOG_TAG);
}

if(surfaceDamageRegion.getBounds() == Rect::INVALID_RECT)
error = hwcLayer->setSurfaceDamage(visible);
else
error = hwcLayer->setSurfaceDamage(surfaceDamageRegion);
if(mFlinger->mDamageUsesScreenReference) {
const Rect& frame = hwcInfo.displayFrame;
int32_t left = frame.left;
int32_t top = frame.top;
int32_t right = frame.right;
int32_t bottom = frame.bottom;
if(surfaceDamageRegion.getBounds() == Rect::INVALID_RECT) {
auto fullSource = Region(Rect(left, top, right, bottom));
error = hwcLayer->setSurfaceDamage(fullSource);
} else {
//There is no easy way to scale, so just scale the bounds
const Rect& preDamageRect = surfaceDamageRegion.bounds();
const FloatRect& crop = hwcInfo.sourceCrop;

float frameWidth = right - left;
float frameHeight = bottom - top;

float cropWidth = crop.right - crop.left;
float cropHeight = crop.bottom - crop.top;

float wFactor = frameWidth / cropWidth;
float hFactor = frameHeight / cropHeight;

Rect scaledDamageRect = Rect(
(int)(preDamageRect.left * wFactor),
(int)(preDamageRect.top * hFactor),
(int)(preDamageRect.right * wFactor),
(int)(preDamageRect.bottom * hFactor));
Region realDamage = Region(scaledDamageRect).translate(frame.left, frame.top);
error = hwcLayer->setSurfaceDamage(realDamage);
}
} else {
error = hwcLayer->setSurfaceDamage(surfaceDamageRegion);
}
if (error != HWC2::Error::None) {
ALOGE("[%s] Failed to set surface damage: %s (%d)", mName.string(),
to_string(error).c_str(), static_cast<int32_t>(error));
Expand Down
7 changes: 7 additions & 0 deletions services/surfaceflinger/SurfaceFlinger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,13 @@ SurfaceFlinger::SurfaceFlinger()
property_get("ro.sf.disable_triple_buffer", value, "1");
mLayerTripleBufferingDisabled = atoi(value);
ALOGI_IF(mLayerTripleBufferingDisabled, "Disabling Triple Buffering");

property_get("ro.hardware", value, "");
if(strstr(value, "hi3660")||
strstr(value, "hi6250") ||
strstr(value, "hi3670")) {
mDamageUsesScreenReference = true;
}
}

void SurfaceFlinger::onFirstRef()
Expand Down
3 changes: 3 additions & 0 deletions services/surfaceflinger/SurfaceFlinger.h
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,9 @@ class SurfaceFlinger : public BnSurfaceComposer,
// Restrict layers to use two buffers in their bufferqueues.
bool mLayerTripleBufferingDisabled = false;

bool mDamageUsesScreenReference;


// these are thread safe
mutable MessageQueue mEventQueue;
FrameTracker mAnimFrameTracker;
Expand Down

0 comments on commit cdc0f4b

Please sign in to comment.