SurfaceFlinger: add a crop to the layer state
This change adds a crop rectangle specified in window coordinates to the layer
state. The all window pixels outside this crop rectangle are treated as though
they were fully transparent. This change also adds the plumbing necessary for
WindowManager to set that crop.
Change-Id: I582bc445dc8c97d4c943d4db8d582a6ef5a66081
diff --git a/libs/gui/Surface.cpp b/libs/gui/Surface.cpp
index 059f313..d7590f0 100644
--- a/libs/gui/Surface.cpp
+++ b/libs/gui/Surface.cpp
@@ -164,6 +164,12 @@
const sp<SurfaceComposerClient>& client(mClient);
return client->setFreezeTint(mToken, tint);
}
+status_t SurfaceControl::setCrop(const Rect& crop) {
+ status_t err = validate();
+ if (err < 0) return err;
+ const sp<SurfaceComposerClient>& client(mClient);
+ return client->setCrop(mToken, crop);
+}
status_t SurfaceControl::validate() const
{
diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp
index ceb1ba6..8fa2167 100644
--- a/libs/gui/SurfaceComposerClient.cpp
+++ b/libs/gui/SurfaceComposerClient.cpp
@@ -125,6 +125,8 @@
const sp<SurfaceComposerClient>& client, SurfaceID id,
uint32_t tint);
status_t setOrientation(int orientation);
+ status_t setCrop(const sp<SurfaceComposerClient>& client, SurfaceID id,
+ const Rect& crop);
static void closeGlobalTransaction(bool synchronous) {
Composer::getInstance().closeGlobalTransactionImpl(synchronous);
@@ -290,6 +292,17 @@
return NO_ERROR;
}
+status_t Composer::setCrop(const sp<SurfaceComposerClient>& client,
+ SurfaceID id, const Rect& crop) {
+ Mutex::Autolock _l(mLock);
+ layer_state_t* s = getLayerStateLocked(client, id);
+ if (!s)
+ return BAD_INDEX;
+ s->what |= ISurfaceComposer::eCropChanged;
+ s->crop = crop;
+ return NO_ERROR;
+}
+
// ---------------------------------------------------------------------------
SurfaceComposerClient::SurfaceComposerClient()
@@ -398,6 +411,10 @@
// ----------------------------------------------------------------------------
+status_t SurfaceComposerClient::setCrop(SurfaceID id, const Rect& crop) {
+ return getComposer().setCrop(this, id, crop);
+}
+
status_t SurfaceComposerClient::setFreezeTint(SurfaceID id, uint32_t tint) {
return getComposer().setFreezeTint(this, id, tint);
}
diff --git a/libs/ui/Rect.cpp b/libs/ui/Rect.cpp
index 65fe5f9..c4dd55b 100644
--- a/libs/ui/Rect.cpp
+++ b/libs/ui/Rect.cpp
@@ -93,7 +93,7 @@
return !(result->isEmpty());
}
-Rect Rect::transform(uint32_t xform, int32_t width, int32_t height) {
+Rect Rect::transform(uint32_t xform, int32_t width, int32_t height) const {
Rect result(*this);
if (xform & HAL_TRANSFORM_FLIP_H) {
result = Rect(width - result.right, result.top,