Add display tracing to SurfaceInterceptor

Change-Id: Iaae5a840ca7dca7a9a70dde1ccab0fa3944cd863
diff --git a/services/surfaceflinger/DisplayDevice.cpp b/services/surfaceflinger/DisplayDevice.cpp
index 5c2c0ad..6c18ef7 100644
--- a/services/surfaceflinger/DisplayDevice.cpp
+++ b/services/surfaceflinger/DisplayDevice.cpp
@@ -613,3 +613,17 @@
     mDisplaySurface->dumpAsString(surfaceDump);
     result.append(surfaceDump);
 }
+
+std::atomic<int32_t> DisplayDeviceState::nextDisplayId(1);
+
+DisplayDeviceState::DisplayDeviceState(DisplayDevice::DisplayType type, bool isSecure)
+    : type(type),
+      layerStack(DisplayDevice::NO_LAYER_STACK),
+      orientation(0),
+      width(0),
+      height(0),
+      isSecure(isSecure)
+{
+    viewport.makeInvalid();
+    frame.makeInvalid();
+}
diff --git a/services/surfaceflinger/DisplayDevice.h b/services/surfaceflinger/DisplayDevice.h
index 105e980..92ede08 100644
--- a/services/surfaceflinger/DisplayDevice.h
+++ b/services/surfaceflinger/DisplayDevice.h
@@ -263,6 +263,28 @@
 #endif
 };
 
+struct DisplayDeviceState {
+    DisplayDeviceState() = default;
+    DisplayDeviceState(DisplayDevice::DisplayType type, bool isSecure);
+
+    bool isValid() const { return type >= 0; }
+    bool isMainDisplay() const { return type == DisplayDevice::DISPLAY_PRIMARY; }
+    bool isVirtualDisplay() const { return type >= DisplayDevice::DISPLAY_VIRTUAL; }
+
+    static std::atomic<int32_t> nextDisplayId;
+    int32_t displayId = nextDisplayId++;
+    DisplayDevice::DisplayType type = DisplayDevice::DISPLAY_ID_INVALID;
+    sp<IGraphicBufferProducer> surface;
+    uint32_t layerStack = DisplayDevice::NO_LAYER_STACK;
+    Rect viewport;
+    Rect frame;
+    uint8_t orientation = 0;
+    uint32_t width = 0;
+    uint32_t height = 0;
+    String8 displayName;
+    bool isSecure = false;
+};
+
 }; // namespace android
 
 #endif // ANDROID_DISPLAY_DEVICE_H
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index f3d31d9..af56a65 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -261,7 +261,7 @@
     DisplayDeviceState info(DisplayDevice::DISPLAY_VIRTUAL, secure);
     info.displayName = displayName;
     mCurrentState.displays.add(token, info);
-
+    mInterceptor.saveDisplayCreation(info);
     return token;
 }
 
@@ -279,7 +279,7 @@
         ALOGE("destroyDisplay called for non-virtual display");
         return;
     }
-
+    mInterceptor.saveDisplayDeletion(info.displayId);
     mCurrentState.displays.removeItemsAt(idx);
     setTransactionFlags(eDisplayTransactionNeeded);
 }
@@ -292,6 +292,7 @@
     // All non-virtual displays are currently considered secure.
     DisplayDeviceState info(type, true);
     mCurrentState.displays.add(mBuiltinDisplays[type], info);
+    mInterceptor.saveDisplayCreation(info);
 }
 
 sp<IBinder> SurfaceFlinger::getBuiltInDisplay(int32_t id) {
@@ -2371,7 +2372,9 @@
     }
 
     if (transactionFlags) {
-        mInterceptor.saveLayerUpdates(state, flags);
+        if (mInterceptor.isEnabled()) {
+            mInterceptor.saveTransaction(state, mCurrentState.displays, displays, flags);
+        }
 
         // this triggers the transaction
         setTransactionFlags(transactionFlags);
@@ -2567,7 +2570,7 @@
     if (result != NO_ERROR) {
         return result;
     }
-    mInterceptor.saveLayerCreate(layer);
+    mInterceptor.saveSurfaceCreation(layer);
 
     setTransactionFlags(eTransactionNeeded);
     return result;
@@ -2615,7 +2618,7 @@
     status_t err = NO_ERROR;
     sp<Layer> l(client->getLayerUser(handle));
     if (l != NULL) {
-        mInterceptor.saveLayerDelete(l);
+        mInterceptor.saveSurfaceDeletion(l);
         err = removeLayer(l);
         ALOGE_IF(err<0 && err != NAME_NOT_FOUND,
                 "error removing layer=%p (%s)", l.get(), strerror(-err));
@@ -2694,6 +2697,16 @@
         return;
     }
 
+    if (mInterceptor.isEnabled()) {
+        Mutex::Autolock _l(mStateLock);
+        ssize_t idx = mCurrentState.displays.indexOfKey(hw->getDisplayToken());
+        if (idx < 0) {
+            ALOGW("Surface Interceptor SavePowerMode: invalid display token");
+            return;
+        }
+        mInterceptor.savePowerModeUpdate(mCurrentState.displays.valueAt(idx).displayId, mode);
+    }
+
     if (currentMode == HWC_POWER_MODE_OFF) {
         // Turn on the display
         getHwComposer().setPowerMode(type, mode);
@@ -3363,7 +3376,7 @@
                 n = data.readInt32();
                 if (n) {
                     ALOGV("Interceptor enabled");
-                    mInterceptor.enable(mDrawingState.layersSortedByZ);
+                    mInterceptor.enable(mDrawingState.layersSortedByZ, mDrawingState.displays);
                 }
                 else{
                     ALOGV("Interceptor disabled");
@@ -3896,31 +3909,6 @@
     return l->sequence - r->sequence;
 }
 
-// ---------------------------------------------------------------------------
-
-SurfaceFlinger::DisplayDeviceState::DisplayDeviceState()
-    : type(DisplayDevice::DISPLAY_ID_INVALID),
-      layerStack(DisplayDevice::NO_LAYER_STACK),
-      orientation(0),
-      width(0),
-      height(0),
-      isSecure(false) {
-}
-
-SurfaceFlinger::DisplayDeviceState::DisplayDeviceState(
-    DisplayDevice::DisplayType type, bool isSecure)
-    : type(type),
-      layerStack(DisplayDevice::NO_LAYER_STACK),
-      orientation(0),
-      width(0),
-      height(0),
-      isSecure(isSecure) {
-    viewport.makeInvalid();
-    frame.makeInvalid();
-}
-
-// ---------------------------------------------------------------------------
-
 }; // namespace android
 
 
diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
index ed592a3..838eaa7 100644
--- a/services/surfaceflinger/SurfaceFlinger.h
+++ b/services/surfaceflinger/SurfaceFlinger.h
@@ -175,23 +175,6 @@
         virtual int do_compare(const void* lhs, const void* rhs) const;
     };
 
-    struct DisplayDeviceState {
-        DisplayDeviceState();
-        DisplayDeviceState(DisplayDevice::DisplayType type, bool isSecure);
-        bool isValid() const { return type >= 0; }
-        bool isMainDisplay() const { return type == DisplayDevice::DISPLAY_PRIMARY; }
-        bool isVirtualDisplay() const { return type >= DisplayDevice::DISPLAY_VIRTUAL; }
-        DisplayDevice::DisplayType type;
-        sp<IGraphicBufferProducer> surface;
-        uint32_t layerStack;
-        Rect viewport;
-        Rect frame;
-        uint8_t orientation;
-        uint32_t width, height;
-        String8 displayName;
-        bool isSecure;
-    };
-
     struct State {
         LayerVector layersSortedByZ;
         DefaultKeyedVector< wp<IBinder>, DisplayDeviceState> displays;
diff --git a/services/surfaceflinger/SurfaceFlinger_hwc1.cpp b/services/surfaceflinger/SurfaceFlinger_hwc1.cpp
index e4a4742..865dcc0 100644
--- a/services/surfaceflinger/SurfaceFlinger_hwc1.cpp
+++ b/services/surfaceflinger/SurfaceFlinger_hwc1.cpp
@@ -259,7 +259,7 @@
     DisplayDeviceState info(DisplayDevice::DISPLAY_VIRTUAL, secure);
     info.displayName = displayName;
     mCurrentState.displays.add(token, info);
-
+    mInterceptor.saveDisplayCreation(info);
     return token;
 }
 
@@ -277,7 +277,7 @@
         ALOGE("destroyDisplay called for non-virtual display");
         return;
     }
-
+    mInterceptor.saveDisplayDeletion(info.displayId);
     mCurrentState.displays.removeItemsAt(idx);
     setTransactionFlags(eDisplayTransactionNeeded);
 }
@@ -289,6 +289,7 @@
     // All non-virtual displays are currently considered secure.
     DisplayDeviceState info(type, true);
     mCurrentState.displays.add(mBuiltinDisplays[type], info);
+    mInterceptor.saveDisplayCreation(info);
 }
 
 sp<IBinder> SurfaceFlinger::getBuiltInDisplay(int32_t id) {
@@ -2287,7 +2288,9 @@
     }
 
     if (transactionFlags) {
-        mInterceptor.saveLayerUpdates(state, flags);
+        if (mInterceptor.isEnabled()) {
+            mInterceptor.saveTransaction(state, mCurrentState.displays, displays, flags);
+        }
 
         // this triggers the transaction
         setTransactionFlags(transactionFlags);
@@ -2483,7 +2486,7 @@
     if (result != NO_ERROR) {
         return result;
     }
-    mInterceptor.saveLayerCreate(layer);
+    mInterceptor.saveSurfaceCreation(layer);
 
     setTransactionFlags(eTransactionNeeded);
     return result;
@@ -2531,7 +2534,7 @@
     status_t err = NO_ERROR;
     sp<Layer> l(client->getLayerUser(handle));
     if (l != NULL) {
-        mInterceptor.saveLayerDelete(l);
+        mInterceptor.saveSurfaceDeletion(l);
         err = removeLayer(l);
         ALOGE_IF(err<0 && err != NAME_NOT_FOUND,
                 "error removing layer=%p (%s)", l.get(), strerror(-err));
@@ -2610,6 +2613,16 @@
         return;
     }
 
+    if (mInterceptor.isEnabled()) {
+        Mutex::Autolock _l(mStateLock);
+        ssize_t idx = mCurrentState.displays.indexOfKey(hw->getDisplayToken());
+        if (idx < 0) {
+            ALOGW("Surface Interceptor SavePowerMode: invalid display token");
+            return;
+        }
+        mInterceptor.savePowerModeUpdate(mCurrentState.displays.valueAt(idx).displayId, mode);
+    }
+
     if (currentMode == HWC_POWER_MODE_OFF) {
         // Turn on the display
         getHwComposer().setPowerMode(type, mode);
@@ -3276,7 +3289,7 @@
                 n = data.readInt32();
                 if (n) {
                     ALOGV("Interceptor enabled");
-                    mInterceptor.enable(mDrawingState.layersSortedByZ);
+                    mInterceptor.enable(mDrawingState.layersSortedByZ, mDrawingState.displays);
                 }
                 else{
                     ALOGV("Interceptor disabled");
@@ -3803,31 +3816,6 @@
     return l->sequence - r->sequence;
 }
 
-// ---------------------------------------------------------------------------
-
-SurfaceFlinger::DisplayDeviceState::DisplayDeviceState()
-    : type(DisplayDevice::DISPLAY_ID_INVALID),
-      layerStack(DisplayDevice::NO_LAYER_STACK),
-      orientation(0),
-      width(0),
-      height(0),
-      isSecure(false) {
-}
-
-SurfaceFlinger::DisplayDeviceState::DisplayDeviceState(
-    DisplayDevice::DisplayType type, bool isSecure)
-    : type(type),
-      layerStack(DisplayDevice::NO_LAYER_STACK),
-      orientation(0),
-      width(0),
-      height(0),
-      isSecure(isSecure) {
-    viewport.makeInvalid();
-    frame.makeInvalid();
-}
-
-// ---------------------------------------------------------------------------
-
 }; // namespace android
 
 
diff --git a/services/surfaceflinger/SurfaceInterceptor.cpp b/services/surfaceflinger/SurfaceInterceptor.cpp
index c860228..594b03a 100644
--- a/services/surfaceflinger/SurfaceInterceptor.cpp
+++ b/services/surfaceflinger/SurfaceInterceptor.cpp
@@ -13,7 +13,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 #undef LOG_TAG
 #define LOG_TAG "SurfaceInterceptor"
 #define ATRACE_TAG ATRACE_TAG_GRAPHICS
@@ -21,7 +20,6 @@
 #include "Layer.h"
 #include "SurfaceFlinger.h"
 #include "SurfaceInterceptor.h"
-
 #include <cutils/log.h>
 
 #include <utils/Trace.h>
@@ -32,20 +30,24 @@
 
 // ----------------------------------------------------------------------------
 
-void SurfaceInterceptor::enable(const SortedVector<sp<Layer>>& layers) {
-    ATRACE_CALL();
+void SurfaceInterceptor::enable(const SortedVector<sp<Layer>>& layers,
+        const DefaultKeyedVector< wp<IBinder>, DisplayDeviceState>& displays)
+{
     if (mEnabled) {
         return;
     }
+    ATRACE_CALL();
     mEnabled = true;
-    saveExistingLayers(layers);
+    std::lock_guard<std::mutex> protoGuard(mTraceMutex);
+    saveExistingDisplaysLocked(displays);
+    saveExistingSurfacesLocked(layers);
 }
 
 void SurfaceInterceptor::disable() {
-    ATRACE_CALL();
     if (!mEnabled) {
         return;
     }
+    ATRACE_CALL();
     std::lock_guard<std::mutex> protoGuard(mTraceMutex);
     mEnabled = false;
     status_t err(writeProtoFileLocked());
@@ -54,21 +56,32 @@
     mTrace.Clear();
 }
 
-void SurfaceInterceptor::saveExistingLayers(const SortedVector<sp<Layer>>& layers) {
+bool SurfaceInterceptor::isEnabled() {
+    return mEnabled;
+}
+
+void SurfaceInterceptor::saveExistingDisplaysLocked(
+        const DefaultKeyedVector< wp<IBinder>, DisplayDeviceState>& displays)
+{
+    // Caveat: The initial snapshot does not capture the power mode of the existing displays
     ATRACE_CALL();
-    std::lock_guard<std::mutex> protoGuard(mTraceMutex);
-    for (const auto& layer : layers) {
-        saveLayerCreateLocked(layer);
-        saveInitialLayerStateLocked(layer);
+    for (size_t i = 0 ; i < displays.size() ; i++) {
+        addDisplayCreationLocked(createTraceIncrementLocked(), displays[i]);
+        addInitialDisplayStateLocked(createTraceIncrementLocked(), displays[i]);
     }
 }
 
-void SurfaceInterceptor::saveInitialLayerStateLocked(const sp<const Layer>& layer) {
+void SurfaceInterceptor::saveExistingSurfacesLocked(const SortedVector<sp<Layer>>& layers) {
     ATRACE_CALL();
-    if (layer == nullptr) {
-        return;
+    for (const auto& layer : layers) {
+        addSurfaceCreationLocked(createTraceIncrementLocked(), layer);
+        addInitialSurfaceStateLocked(createTraceIncrementLocked(), layer);
     }
-    Increment* increment(addTraceIncrementLocked());
+}
+
+void SurfaceInterceptor::addInitialSurfaceStateLocked(Increment* increment,
+        const sp<const Layer>& layer)
+{
     Transaction* transaction(increment->mutable_transaction());
     transaction->set_synchronous(layer->mTransactionFlags & BnSurfaceComposer::eSynchronous);
     transaction->set_animation(layer->mTransactionFlags & BnSurfaceComposer::eAnimation);
@@ -77,13 +90,11 @@
     addPositionLocked(transaction, layerId, layer->mCurrentState.active.transform.tx(),
             layer->mCurrentState.active.transform.ty());
     addDepthLocked(transaction, layerId, layer->mCurrentState.z);
-    addSizeLocked(transaction, layerId, layer->mCurrentState.active.w,
-            layer->mCurrentState.active.h);
     addAlphaLocked(transaction, layerId, layer->mCurrentState.alpha);
     addTransparentRegionLocked(transaction, layerId, layer->mCurrentState.activeTransparentRegion);
     addLayerStackLocked(transaction, layerId, layer->mCurrentState.layerStack);
     addCropLocked(transaction, layerId, layer->mCurrentState.crop);
-    if (layer->mCurrentState.handle != NULL) {
+    if (layer->mCurrentState.handle != nullptr) {
         addDeferTransactionLocked(transaction, layerId, layer->mCurrentState.handle,
                 layer->mCurrentState.frameNumber);
     }
@@ -92,6 +103,20 @@
     addFlagsLocked(transaction, layerId, layer->mCurrentState.flags);
 }
 
+void SurfaceInterceptor::addInitialDisplayStateLocked(Increment* increment,
+        const DisplayDeviceState& display)
+{
+    Transaction* transaction(increment->mutable_transaction());
+    transaction->set_synchronous(false);
+    transaction->set_animation(false);
+
+    addDisplaySurfaceLocked(transaction, display.displayId, display.surface);
+    addDisplayLayerStackLocked(transaction, display.displayId, display.layerStack);
+    addDisplaySizeLocked(transaction, display.displayId, display.width, display.height);
+    addDisplayProjectionLocked(transaction, display.displayId, display.orientation,
+            display.viewport, display.frame);
+}
+
 status_t SurfaceInterceptor::writeProtoFileLocked() {
     ATRACE_CALL();
     std::ofstream output(mOutputFileName, std::ios::out | std::ios::trunc | std::ios::binary);
@@ -105,10 +130,6 @@
     return NO_ERROR;
 }
 
-void SurfaceInterceptor::setOutputFileName(const std::string& outputFileName) {
-    mOutputFileName = outputFileName;
-}
-
 const sp<const Layer> SurfaceInterceptor::getLayer(const sp<const IBinder>& handle) {
     const auto layerHandle(static_cast<const Layer::Handle*>(handle.get()));
     const sp<const Layer> layer(layerHandle->owner.promote());
@@ -124,18 +145,28 @@
     return layer->sequence;
 }
 
-Increment* SurfaceInterceptor::addTraceIncrementLocked() {
+Increment* SurfaceInterceptor::createTraceIncrementLocked() {
     Increment* increment(mTrace.add_increment());
     increment->set_time_stamp(systemTime());
     return increment;
 }
 
-Change* SurfaceInterceptor::addChangeLocked(Transaction* transaction, int32_t layerId) {
-    Change* change(transaction->add_change());
+SurfaceChange* SurfaceInterceptor::createSurfaceChangeLocked(Transaction* transaction,
+        int32_t layerId)
+{
+    SurfaceChange* change(transaction->add_surface_change());
     change->set_id(layerId);
     return change;
 }
 
+DisplayChange* SurfaceInterceptor::createDisplayChangeLocked(Transaction* transaction,
+        int32_t displayId)
+{
+    DisplayChange* dispChange(transaction->add_display_change());
+    dispChange->set_id(displayId);
+    return dispChange;
+}
+
 void SurfaceInterceptor::setProtoRectLocked(Rectangle* protoRect, const Rect& rect) {
     protoRect->set_left(rect.left);
     protoRect->set_top(rect.top);
@@ -143,17 +174,19 @@
     protoRect->set_bottom(rect.bottom);
 }
 
-void SurfaceInterceptor::addPositionLocked(Transaction* transaction, int32_t layerId, float x,
-        float y)
+void SurfaceInterceptor::addPositionLocked(Transaction* transaction, int32_t layerId,
+        float x, float y)
 {
-    Change* change(addChangeLocked(transaction, layerId));
+    SurfaceChange* change(createSurfaceChangeLocked(transaction, layerId));
     PositionChange* posChange(change->mutable_position());
     posChange->set_x(x);
     posChange->set_y(y);
 }
 
-void SurfaceInterceptor::addDepthLocked(Transaction* transaction, int32_t layerId, uint32_t z) {
-    Change* change(addChangeLocked(transaction, layerId));
+void SurfaceInterceptor::addDepthLocked(Transaction* transaction, int32_t layerId,
+        uint32_t z)
+{
+    SurfaceChange* change(createSurfaceChangeLocked(transaction, layerId));
     LayerChange* depthChange(change->mutable_layer());
     depthChange->set_layer(z);
 }
@@ -161,14 +194,16 @@
 void SurfaceInterceptor::addSizeLocked(Transaction* transaction, int32_t layerId, uint32_t w,
         uint32_t h)
 {
-    Change* change(addChangeLocked(transaction, layerId));
+    SurfaceChange* change(createSurfaceChangeLocked(transaction, layerId));
     SizeChange* sizeChange(change->mutable_size());
     sizeChange->set_w(w);
     sizeChange->set_h(h);
 }
 
-void SurfaceInterceptor::addAlphaLocked(Transaction* transaction, int32_t layerId, float alpha) {
-    Change* change(addChangeLocked(transaction, layerId));
+void SurfaceInterceptor::addAlphaLocked(Transaction* transaction, int32_t layerId,
+        float alpha)
+{
+    SurfaceChange* change(createSurfaceChangeLocked(transaction, layerId));
     AlphaChange* alphaChange(change->mutable_alpha());
     alphaChange->set_alpha(alpha);
 }
@@ -176,7 +211,7 @@
 void SurfaceInterceptor::addMatrixLocked(Transaction* transaction, int32_t layerId,
         const layer_state_t::matrix22_t& matrix)
 {
-    Change* change(addChangeLocked(transaction, layerId));
+    SurfaceChange* change(createSurfaceChangeLocked(transaction, layerId));
     MatrixChange* matrixChange(change->mutable_matrix());
     matrixChange->set_dsdx(matrix.dsdx);
     matrixChange->set_dtdx(matrix.dtdx);
@@ -184,10 +219,10 @@
     matrixChange->set_dtdy(matrix.dtdy);
 }
 
-void SurfaceInterceptor::addTransparentRegionLocked(Transaction* transaction, int32_t layerId,
-        const Region& transRegion)
+void SurfaceInterceptor::addTransparentRegionLocked(Transaction* transaction,
+        int32_t layerId, const Region& transRegion)
 {
-    Change* change(addChangeLocked(transaction, layerId));
+    SurfaceChange* change(createSurfaceChangeLocked(transaction, layerId));
     TransparentRegionHintChange* transparentChange(change->mutable_transparent_region_hint());
 
     for (const auto& rect : transRegion) {
@@ -196,20 +231,22 @@
     }
 }
 
-void SurfaceInterceptor::addFlagsLocked(Transaction* transaction, int32_t layerId, uint8_t flags) {
+void SurfaceInterceptor::addFlagsLocked(Transaction* transaction, int32_t layerId,
+        uint8_t flags)
+{
     // There can be multiple flags changed
     if (flags & layer_state_t::eLayerHidden) {
-        Change* change(addChangeLocked(transaction, layerId));
+        SurfaceChange* change(createSurfaceChangeLocked(transaction, layerId));
         HiddenFlagChange* flagChange(change->mutable_hidden_flag());
         flagChange->set_hidden_flag(true);
     }
     if (flags & layer_state_t::eLayerOpaque) {
-        Change* change(addChangeLocked(transaction, layerId));
+        SurfaceChange* change(createSurfaceChangeLocked(transaction, layerId));
         OpaqueFlagChange* flagChange(change->mutable_opaque_flag());
         flagChange->set_opaque_flag(true);
     }
     if (flags & layer_state_t::eLayerSecure) {
-        Change* change(addChangeLocked(transaction, layerId));
+        SurfaceChange* change(createSurfaceChangeLocked(transaction, layerId));
         SecureFlagChange* flagChange(change->mutable_secure_flag());
         flagChange->set_secure_flag(true);
     }
@@ -218,7 +255,7 @@
 void SurfaceInterceptor::addLayerStackLocked(Transaction* transaction, int32_t layerId,
         uint32_t layerStack)
 {
-    Change* change(addChangeLocked(transaction, layerId));
+    SurfaceChange* change(createSurfaceChangeLocked(transaction, layerId));
     LayerStackChange* layerStackChange(change->mutable_layer_stack());
     layerStackChange->set_layer_stack(layerStack);
 }
@@ -226,7 +263,7 @@
 void SurfaceInterceptor::addCropLocked(Transaction* transaction, int32_t layerId,
         const Rect& rect)
 {
-    Change* change(addChangeLocked(transaction, layerId));
+    SurfaceChange* change(createSurfaceChangeLocked(transaction, layerId));
     CropChange* cropChange(change->mutable_crop());
     Rectangle* protoRect(cropChange->mutable_rectangle());
     setProtoRectLocked(protoRect, rect);
@@ -235,7 +272,7 @@
 void SurfaceInterceptor::addFinalCropLocked(Transaction* transaction, int32_t layerId,
         const Rect& rect)
 {
-    Change* change(addChangeLocked(transaction, layerId));
+    SurfaceChange* change(createSurfaceChangeLocked(transaction, layerId));
     FinalCropChange* finalCropChange(change->mutable_final_crop());
     Rectangle* protoRect(finalCropChange->mutable_rectangle());
     setProtoRectLocked(protoRect, rect);
@@ -244,7 +281,7 @@
 void SurfaceInterceptor::addDeferTransactionLocked(Transaction* transaction, int32_t layerId,
         const sp<const IBinder>& handle, uint64_t frameNumber)
 {
-    Change* change(addChangeLocked(transaction, layerId));
+    SurfaceChange* change(createSurfaceChangeLocked(transaction, layerId));
     const sp<const Layer> layer(getLayer(handle));
     if (layer == nullptr) {
         ALOGE("An existing layer could not be retrieved with the handle"
@@ -256,15 +293,15 @@
     deferTransaction->set_frame_number(frameNumber);
 }
 
-void SurfaceInterceptor::addOverrideScalingModeLocked(Transaction* transaction, int32_t layerId,
-        int32_t overrideScalingMode)
+void SurfaceInterceptor::addOverrideScalingModeLocked(Transaction* transaction,
+        int32_t layerId, int32_t overrideScalingMode)
 {
-    Change* change(addChangeLocked(transaction, layerId));
+    SurfaceChange* change(createSurfaceChangeLocked(transaction, layerId));
     OverrideScalingModeChange* overrideChange(change->mutable_override_scaling_mode());
     overrideChange->set_override_scaling_mode(overrideScalingMode);
 }
 
-void SurfaceInterceptor::addChangedPropertiesLocked(Transaction* transaction,
+void SurfaceInterceptor::addSurfaceChangesLocked(Transaction* transaction,
         const layer_state_t& state)
 {
     const sp<const Layer> layer(getLayer(state.surface));
@@ -314,31 +351,62 @@
     }
 }
 
-void SurfaceInterceptor::addUpdatedLayersLocked(Increment* increment, uint32_t flags,
-        const Vector<ComposerState>& stateUpdates)
+void SurfaceInterceptor::addDisplayChangesLocked(Transaction* transaction,
+        const DisplayState& state, int32_t displayId)
 {
-    Transaction* transaction(increment->mutable_transaction());
-    transaction->set_synchronous(flags & BnSurfaceComposer::eSynchronous);
-    transaction->set_animation(flags & BnSurfaceComposer::eAnimation);
-    for (const auto& compState: stateUpdates) {
-        addChangedPropertiesLocked(transaction, compState.state);
+    if (state.what & DisplayState::eSurfaceChanged) {
+        addDisplaySurfaceLocked(transaction, displayId, state.surface);
+    }
+    if (state.what & DisplayState::eLayerStackChanged) {
+        addDisplayLayerStackLocked(transaction, displayId, state.layerStack);
+    }
+    if (state.what & DisplayState::eDisplaySizeChanged) {
+        addDisplaySizeLocked(transaction, displayId, state.width, state.height);
+    }
+    if (state.what & DisplayState::eDisplayProjectionChanged) {
+        addDisplayProjectionLocked(transaction, displayId, state.orientation, state.viewport,
+                state.frame);
     }
 }
 
-void SurfaceInterceptor::addCreatedLayerLocked(Increment* increment, const sp<const Layer>& layer) {
-    Create* create(increment->mutable_create());
-    create->set_id(getLayerId(layer));
-    create->set_name(getLayerName(layer));
-    create->set_w(layer->mCurrentState.active.w);
-    create->set_h(layer->mCurrentState.active.h);
+void SurfaceInterceptor::addTransactionLocked(Increment* increment,
+        const Vector<ComposerState>& stateUpdates,
+        const DefaultKeyedVector< wp<IBinder>, DisplayDeviceState>& displays,
+        const Vector<DisplayState>& changedDisplays, uint32_t transactionFlags)
+{
+    Transaction* transaction(increment->mutable_transaction());
+    transaction->set_synchronous(transactionFlags & BnSurfaceComposer::eSynchronous);
+    transaction->set_animation(transactionFlags & BnSurfaceComposer::eAnimation);
+    for (const auto& compState: stateUpdates) {
+        addSurfaceChangesLocked(transaction, compState.state);
+    }
+    for (const auto& disp: changedDisplays) {
+        ssize_t dpyIdx = displays.indexOfKey(disp.token);
+        if (dpyIdx >= 0) {
+            const DisplayDeviceState& dispState(displays.valueAt(dpyIdx));
+            addDisplayChangesLocked(transaction, disp, dispState.displayId);
+        }
+    }
 }
 
-void SurfaceInterceptor::addDeletedLayerLocked(Increment* increment, const sp<const Layer>& layer) {
-    Delete* deleteLayer(increment->mutable_delete_());
-    deleteLayer->set_id(getLayerId(layer));
+void SurfaceInterceptor::addSurfaceCreationLocked(Increment* increment,
+        const sp<const Layer>& layer)
+{
+    SurfaceCreation* creation(increment->mutable_surface_creation());
+    creation->set_id(getLayerId(layer));
+    creation->set_name(getLayerName(layer));
+    creation->set_w(layer->mCurrentState.active.w);
+    creation->set_h(layer->mCurrentState.active.h);
 }
 
-void SurfaceInterceptor::addUpdatedBufferLocked(Increment* increment, const sp<const Layer>& layer,
+void SurfaceInterceptor::addSurfaceDeletionLocked(Increment* increment,
+        const sp<const Layer>& layer)
+{
+    SurfaceDeletion* deletion(increment->mutable_surface_deletion());
+    deletion->set_id(getLayerId(layer));
+}
+
+void SurfaceInterceptor::addBufferUpdateLocked(Increment* increment, const sp<const Layer>& layer,
         uint32_t width, uint32_t height, uint64_t frameNumber)
 {
     BufferUpdate* update(increment->mutable_buffer_update());
@@ -348,56 +416,123 @@
     update->set_frame_number(frameNumber);
 }
 
-void SurfaceInterceptor::addUpdatedVsyncLocked(Increment* increment, nsecs_t timestamp) {
+void SurfaceInterceptor::addVSyncUpdateLocked(Increment* increment, nsecs_t timestamp) {
     VSyncEvent* event(increment->mutable_vsync_event());
     event->set_when(timestamp);
 }
 
-void SurfaceInterceptor::saveLayerUpdates(const Vector<ComposerState>& stateUpdates,
-        uint32_t flags)
+void SurfaceInterceptor::addDisplaySurfaceLocked(Transaction* transaction, int32_t displayId,
+        const sp<const IGraphicBufferProducer>& surface)
 {
-    ATRACE_CALL();
-    if (!mEnabled || stateUpdates.size() <= 0) {
+    if (surface == nullptr) {
         return;
     }
-    std::lock_guard<std::mutex> protoGuard(mTraceMutex);
-    addUpdatedLayersLocked(addTraceIncrementLocked(), flags, stateUpdates);
+    uint64_t bufferQueueId = 0;
+    status_t err(surface->getUniqueId(&bufferQueueId));
+    if (err == NO_ERROR) {
+        DisplayChange* dispChange(createDisplayChangeLocked(transaction, displayId));
+        DispSurfaceChange* surfaceChange(dispChange->mutable_surface());
+        surfaceChange->set_buffer_queue_id(bufferQueueId);
+        surfaceChange->set_buffer_queue_name(surface->getConsumerName().string());
+    }
+    else {
+        ALOGE("invalid graphic buffer producer received while tracing a display change (%s)",
+                strerror(-err));
+    }
 }
 
-void SurfaceInterceptor::saveLayerCreate(const sp<const Layer>& layer) {
+void SurfaceInterceptor::addDisplayLayerStackLocked(Transaction* transaction,
+        int32_t displayId, uint32_t layerStack)
+{
+    DisplayChange* dispChange(createDisplayChangeLocked(transaction, displayId));
+    LayerStackChange* layerStackChange(dispChange->mutable_layer_stack());
+    layerStackChange->set_layer_stack(layerStack);
+}
+
+void SurfaceInterceptor::addDisplaySizeLocked(Transaction* transaction, int32_t displayId,
+        uint32_t w, uint32_t h)
+{
+    DisplayChange* dispChange(createDisplayChangeLocked(transaction, displayId));
+    SizeChange* sizeChange(dispChange->mutable_size());
+    sizeChange->set_w(w);
+    sizeChange->set_h(h);
+}
+
+void SurfaceInterceptor::addDisplayProjectionLocked(Transaction* transaction,
+        int32_t displayId, int32_t orientation, const Rect& viewport, const Rect& frame)
+{
+    DisplayChange* dispChange(createDisplayChangeLocked(transaction, displayId));
+    ProjectionChange* projectionChange(dispChange->mutable_projection());
+    projectionChange->set_orientation(orientation);
+    Rectangle* viewportRect(projectionChange->mutable_viewport());
+    setProtoRectLocked(viewportRect, viewport);
+    Rectangle* frameRect(projectionChange->mutable_frame());
+    setProtoRectLocked(frameRect, frame);
+}
+
+void SurfaceInterceptor::addDisplayCreationLocked(Increment* increment,
+        const DisplayDeviceState& info)
+{
+    DisplayCreation* creation(increment->mutable_display_creation());
+    creation->set_id(info.displayId);
+    creation->set_name(info.displayName);
+    creation->set_type(info.type);
+    creation->set_is_secure(info.isSecure);
+}
+
+void SurfaceInterceptor::addDisplayDeletionLocked(Increment* increment, int32_t displayId) {
+    DisplayDeletion* deletion(increment->mutable_display_deletion());
+    deletion->set_id(displayId);
+}
+
+void SurfaceInterceptor::addPowerModeUpdateLocked(Increment* increment, int32_t displayId,
+        int32_t mode)
+{
+    PowerModeUpdate* powerModeUpdate(increment->mutable_power_mode_update());
+    powerModeUpdate->set_id(displayId);
+    powerModeUpdate->set_mode(mode);
+}
+
+void SurfaceInterceptor::saveTransaction(const Vector<ComposerState>& stateUpdates,
+        const DefaultKeyedVector< wp<IBinder>, DisplayDeviceState>& displays,
+        const Vector<DisplayState>& changedDisplays, uint32_t flags)
+{
+    if (!mEnabled || (stateUpdates.size() <= 0 && changedDisplays.size() <= 0)) {
+        return;
+    }
     ATRACE_CALL();
+    std::lock_guard<std::mutex> protoGuard(mTraceMutex);
+    addTransactionLocked(createTraceIncrementLocked(), stateUpdates, displays, changedDisplays,
+            flags);
+}
+
+void SurfaceInterceptor::saveSurfaceCreation(const sp<const Layer>& layer) {
     if (!mEnabled || layer == nullptr) {
         return;
     }
-    std::lock_guard<std::mutex> protoGuard(mTraceMutex);
-    addCreatedLayerLocked(addTraceIncrementLocked(), layer);
-}
-
-void SurfaceInterceptor::saveLayerCreateLocked(const sp<const Layer>& layer) {
-    if (!mEnabled || layer == nullptr) {
-        return;
-    }
-    addCreatedLayerLocked(addTraceIncrementLocked(), layer);
-}
-
-void SurfaceInterceptor::saveLayerDelete(const sp<const Layer>& layer) {
     ATRACE_CALL();
+    std::lock_guard<std::mutex> protoGuard(mTraceMutex);
+    addSurfaceCreationLocked(createTraceIncrementLocked(), layer);
+}
+
+void SurfaceInterceptor::saveSurfaceDeletion(const sp<const Layer>& layer) {
     if (!mEnabled || layer == nullptr) {
         return;
     }
+    ATRACE_CALL();
     std::lock_guard<std::mutex> protoGuard(mTraceMutex);
-    addDeletedLayerLocked(addTraceIncrementLocked(), layer);
+    addSurfaceDeletionLocked(createTraceIncrementLocked(), layer);
 }
 
 void SurfaceInterceptor::saveBufferUpdate(const sp<const Layer>& layer, uint32_t width,
         uint32_t height, uint64_t frameNumber)
 {
-    ATRACE_CALL();
     if (!mEnabled || layer == nullptr) {
         return;
     }
+    ATRACE_CALL();
     std::lock_guard<std::mutex> protoGuard(mTraceMutex);
-    addUpdatedBufferLocked(addTraceIncrementLocked(), layer, width, height, frameNumber);
+    addBufferUpdateLocked(createTraceIncrementLocked(), layer, width, height, frameNumber);
 }
 
 void SurfaceInterceptor::saveVSyncEvent(nsecs_t timestamp) {
@@ -405,7 +540,35 @@
         return;
     }
     std::lock_guard<std::mutex> protoGuard(mTraceMutex);
-    addUpdatedVsyncLocked(addTraceIncrementLocked(), timestamp);
+    addVSyncUpdateLocked(createTraceIncrementLocked(), timestamp);
 }
 
+void SurfaceInterceptor::saveDisplayCreation(const DisplayDeviceState& info) {
+    if (!mEnabled) {
+        return;
+    }
+    ATRACE_CALL();
+    std::lock_guard<std::mutex> protoGuard(mTraceMutex);
+    addDisplayCreationLocked(createTraceIncrementLocked(), info);
+}
+
+void SurfaceInterceptor::saveDisplayDeletion(int32_t displayId) {
+    if (!mEnabled) {
+        return;
+    }
+    ATRACE_CALL();
+    std::lock_guard<std::mutex> protoGuard(mTraceMutex);
+    addDisplayDeletionLocked(createTraceIncrementLocked(), displayId);
+}
+
+void SurfaceInterceptor::savePowerModeUpdate(int32_t displayId, int32_t mode) {
+    if (!mEnabled) {
+        return;
+    }
+    ATRACE_CALL();
+    std::lock_guard<std::mutex> protoGuard(mTraceMutex);
+    addPowerModeUpdateLocked(createTraceIncrementLocked(), displayId, mode);
+}
+
+
 } // namespace android
diff --git a/services/surfaceflinger/SurfaceInterceptor.h b/services/surfaceflinger/SurfaceInterceptor.h
index bc8174c..02d4288 100644
--- a/services/surfaceflinger/SurfaceInterceptor.h
+++ b/services/surfaceflinger/SurfaceInterceptor.h
@@ -25,6 +25,7 @@
 
 class BufferItem;
 class Layer;
+struct DisplayState;
 struct layer_state_t;
 
 constexpr auto DEFAULT_FILENAME = "/data/SurfaceTrace.dat";
@@ -35,37 +36,56 @@
  */
 class SurfaceInterceptor {
 public:
-    // The layer vector is used to capture the inital snapshot in the trace
-    void enable(const SortedVector<sp<Layer>>& layers);
+    // Both vectors are used to capture the current state of SF as the initial snapshot in the trace
+    void enable(const SortedVector<sp<Layer>>& layers,
+            const DefaultKeyedVector< wp<IBinder>, DisplayDeviceState>& displays);
     void disable();
-    void setOutputFileName(const std::string& OutputFileName);
+    bool isEnabled();
 
-    void saveLayerUpdates(const Vector<ComposerState>& state, uint32_t flags);
-    void saveLayerCreate(const sp<const Layer>& layer);
-    void saveLayerDelete(const sp<const Layer>& layer);
+    // Intercept display and surface transactions
+    void saveTransaction(const Vector<ComposerState>& stateUpdates,
+            const DefaultKeyedVector< wp<IBinder>, DisplayDeviceState>& displays,
+            const Vector<DisplayState>& changedDisplays, uint32_t flags);
+
+    // Intercept surface data
+    void saveSurfaceCreation(const sp<const Layer>& layer);
+    void saveSurfaceDeletion(const sp<const Layer>& layer);
     void saveBufferUpdate(const sp<const Layer>& layer, uint32_t width, uint32_t height,
             uint64_t frameNumber);
+
+    // Intercept display data
+    void saveDisplayCreation(const DisplayDeviceState& info);
+    void saveDisplayDeletion(int32_t displayId);
+    void savePowerModeUpdate(int32_t displayId, int32_t mode);
     void saveVSyncEvent(nsecs_t timestamp);
 
 private:
-    void saveExistingLayers(const SortedVector<sp<Layer>>& layers);
-    void saveInitialLayerStateLocked(const sp<const Layer>& layer);
-    void saveLayerCreateLocked(const sp<const Layer>& layer);
+    // The creation increments of Surfaces and Displays do not contain enough information to capture
+    // the initial state of each object, so a transaction with all of the missing properties is
+    // performed at the initial snapshot for each display and surface.
+    void saveExistingDisplaysLocked(
+            const DefaultKeyedVector< wp<IBinder>, DisplayDeviceState>& displays);
+    void saveExistingSurfacesLocked(const SortedVector<sp<Layer>>& layers);
+    void addInitialSurfaceStateLocked(Increment* increment, const sp<const Layer>& layer);
+    void addInitialDisplayStateLocked(Increment* increment, const DisplayDeviceState& display);
+
     status_t writeProtoFileLocked();
     const sp<const Layer> getLayer(const sp<const IBinder>& handle);
     const std::string getLayerName(const sp<const Layer>& layer);
     int32_t getLayerId(const sp<const Layer>& layer);
-    Increment* addTraceIncrementLocked();
 
-    void addUpdatedLayersLocked(Increment* increment, uint32_t flags,
-            const Vector<ComposerState>& stateUpdates);
-    void addCreatedLayerLocked(Increment* increment, const sp<const Layer>& layer);
-    void addDeletedLayerLocked(Increment* increment, const sp<const Layer>& layer);
-    void addUpdatedBufferLocked(Increment* increment, const sp<const Layer>& layer, uint32_t width,
+    Increment* createTraceIncrementLocked();
+    void addSurfaceCreationLocked(Increment* increment, const sp<const Layer>& layer);
+    void addSurfaceDeletionLocked(Increment* increment, const sp<const Layer>& layer);
+    void addBufferUpdateLocked(Increment* increment, const sp<const Layer>& layer, uint32_t width,
             uint32_t height, uint64_t frameNumber);
-    void addUpdatedVsyncLocked(Increment* increment, nsecs_t timestamp);
+    void addVSyncUpdateLocked(Increment* increment, nsecs_t timestamp);
+    void addDisplayCreationLocked(Increment* increment, const DisplayDeviceState& info);
+    void addDisplayDeletionLocked(Increment* increment, int32_t displayId);
+    void addPowerModeUpdateLocked(Increment* increment, int32_t displayId, int32_t mode);
 
-    Change* addChangeLocked(Transaction* transaction, int32_t layerId);
+    // Add surface transactions to the trace
+    SurfaceChange* createSurfaceChangeLocked(Transaction* transaction, int32_t layerId);
     void setProtoRectLocked(Rectangle* protoRect, const Rect& rect);
     void addPositionLocked(Transaction* transaction, int32_t layerId, float x, float y);
     void addDepthLocked(Transaction* transaction, int32_t layerId, uint32_t z);
@@ -83,7 +103,24 @@
     void addFinalCropLocked(Transaction* transaction, int32_t layerId, const Rect& rect);
     void addOverrideScalingModeLocked(Transaction* transaction, int32_t layerId,
             int32_t overrideScalingMode);
-    void addChangedPropertiesLocked(Transaction* transaction, const layer_state_t& state);
+    void addSurfaceChangesLocked(Transaction* transaction, const layer_state_t& state);
+    void addTransactionLocked(Increment* increment, const Vector<ComposerState>& stateUpdates,
+            const DefaultKeyedVector< wp<IBinder>, DisplayDeviceState>& displays,
+            const Vector<DisplayState>& changedDisplays, uint32_t transactionFlags);
+
+    // Add display transactions to the trace
+    DisplayChange* createDisplayChangeLocked(Transaction* transaction, int32_t displayId);
+    void addDisplaySurfaceLocked(Transaction* transaction, int32_t displayId,
+            const sp<const IGraphicBufferProducer>& surface);
+    void addDisplayLayerStackLocked(Transaction* transaction, int32_t displayId,
+            uint32_t layerStack);
+    void addDisplaySizeLocked(Transaction* transaction, int32_t displayId, uint32_t w,
+            uint32_t h);
+    void addDisplayProjectionLocked(Transaction* transaction, int32_t displayId,
+            int32_t orientation, const Rect& viewport, const Rect& frame);
+    void addDisplayChangesLocked(Transaction* transaction,
+            const DisplayState& state, int32_t displayId);
+
 
     bool mEnabled {false};
     std::string mOutputFileName {DEFAULT_FILENAME};
diff --git a/services/surfaceflinger/tests/SurfaceInterceptor_test.cpp b/services/surfaceflinger/tests/SurfaceInterceptor_test.cpp
index ebc4dd1..1a3f89f 100644
--- a/services/surfaceflinger/tests/SurfaceInterceptor_test.cpp
+++ b/services/surfaceflinger/tests/SurfaceInterceptor_test.cpp
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-#include <frameworks/native/cmds/surfacecapturereplay/proto/src/trace.pb.h>
+#include <frameworks/native/cmds/surfacereplayer/proto/src/trace.pb.h>
 
 #include <gtest/gtest.h>
 
@@ -23,6 +23,7 @@
 #include <gui/ISurfaceComposer.h>
 #include <gui/Surface.h>
 #include <gui/SurfaceComposerClient.h>
+#include <private/gui/ComposerService.h>
 #include <private/gui/LayerState.h>
 #include <ui/DisplayInfo.h>
 
@@ -42,6 +43,7 @@
 constexpr float POSITION_UPDATE = 121;
 const Rect CROP_UPDATE(16, 16, 32, 32);
 
+const String8 DISPLAY_NAME("SurfaceInterceptor Display Test");
 constexpr auto LAYER_NAME = "Layer Create and Delete Test";
 
 constexpr auto DEFAULT_FILENAME = "/data/SurfaceTrace.dat";
@@ -81,16 +83,16 @@
     system("service call SurfaceFlinger 1020 i32 0 > /dev/null");
 }
 
-uint32_t getLayerId(const std::string& layerName) {
+int32_t getSurfaceId(const std::string& surfaceName) {
     enableInterceptor();
     disableInterceptor();
     Trace capturedTrace;
     readProtoFile(&capturedTrace);
-    uint32_t layerId = 0;
+    int32_t layerId = 0;
     for (const auto& increment : *capturedTrace.mutable_increment()) {
-        if (increment.increment_case() == increment.kCreate) {
-            if (increment.create().name() == layerName) {
-                layerId = increment.create().id();
+        if (increment.increment_case() == increment.kSurfaceCreation) {
+            if (increment.surface_creation().name() == surfaceName) {
+                layerId = increment.surface_creation().id();
                 break;
             }
         }
@@ -98,6 +100,23 @@
     return layerId;
 }
 
+int32_t getDisplayId(const std::string& displayName) {
+    enableInterceptor();
+    disableInterceptor();
+    Trace capturedTrace;
+    readProtoFile(&capturedTrace);
+    int32_t displayId = 0;
+    for (const auto& increment : *capturedTrace.mutable_increment()) {
+        if (increment.increment_case() == increment.kDisplayCreation) {
+            if (increment.display_creation().name() == displayName) {
+                displayId = increment.display_creation().id();
+                break;
+            }
+        }
+    }
+    return displayId;
+}
+
 class SurfaceInterceptorTest : public ::testing::Test {
 protected:
     virtual void SetUp() {
@@ -120,7 +139,7 @@
                 PIXEL_FORMAT_RGBA_8888, 0);
         ASSERT_TRUE(mBGSurfaceControl != NULL);
         ASSERT_TRUE(mBGSurfaceControl->isValid());
-        mBGLayerId = getLayerId("BG Interceptor Test Surface");
+        mBGLayerId = getSurfaceId("BG Interceptor Test Surface");
 
         SurfaceComposerClient::openGlobalTransaction();
         mComposerClient->setDisplayLayerStack(display, 0);
@@ -137,35 +156,43 @@
 
     sp<SurfaceComposerClient> mComposerClient;
     sp<SurfaceControl> mBGSurfaceControl;
-    uint32_t mBGLayerId;
+    int32_t mBGLayerId;
+    // Used to verify creation and destruction of surfaces and displays
+    int32_t mTargetId;
 
 public:
     void captureTest(void (SurfaceInterceptorTest::* action)(void),
             bool (SurfaceInterceptorTest::* verification)(Trace *));
-    void captureTest(void (SurfaceInterceptorTest::* action)(void), Change::ChangeCase changeCase);
+    void captureTest(void (SurfaceInterceptorTest::* action)(void),
+            SurfaceChange::SurfaceChangeCase changeCase);
+    void captureTest(void (SurfaceInterceptorTest::* action)(void),
+            Increment::IncrementCase incrementCase);
     void runInTransaction(void (SurfaceInterceptorTest::* action)(void), bool intercepted = false);
 
     // Verification of changes to a surface
-    bool positionUpdateFound(const Change& change, bool foundPosition);
-    bool sizeUpdateFound(const Change& change, bool foundSize);
-    bool alphaUpdateFound(const Change& change, bool foundAlpha);
-    bool layerUpdateFound(const Change& change, bool foundLayer);
-    bool cropUpdateFound(const Change& change, bool foundCrop);
-    bool finalCropUpdateFound(const Change& change, bool foundFinalCrop);
-    bool matrixUpdateFound(const Change& change, bool foundMatrix);
-    bool scalingModeUpdateFound(const Change& change, bool foundScalingMode);
-    bool transparentRegionHintUpdateFound(const Change& change, bool foundTransparentRegion);
-    bool layerStackUpdateFound(const Change& change, bool foundLayerStack);
-    bool hiddenFlagUpdateFound(const Change& change, bool foundHiddenFlag);
-    bool opaqueFlagUpdateFound(const Change& change, bool foundOpaqueFlag);
-    bool secureFlagUpdateFound(const Change& change, bool foundSecureFlag);
-    bool deferredTransactionUpdateFound(const Change& change, bool foundDeferred);
-    bool surfaceUpdateFound(Trace* trace, Change::ChangeCase changeCase);
+    bool positionUpdateFound(const SurfaceChange& change, bool foundPosition);
+    bool sizeUpdateFound(const SurfaceChange& change, bool foundSize);
+    bool alphaUpdateFound(const SurfaceChange& change, bool foundAlpha);
+    bool layerUpdateFound(const SurfaceChange& change, bool foundLayer);
+    bool cropUpdateFound(const SurfaceChange& change, bool foundCrop);
+    bool finalCropUpdateFound(const SurfaceChange& change, bool foundFinalCrop);
+    bool matrixUpdateFound(const SurfaceChange& change, bool foundMatrix);
+    bool scalingModeUpdateFound(const SurfaceChange& change, bool foundScalingMode);
+    bool transparentRegionHintUpdateFound(const SurfaceChange& change, bool foundTransparentRegion);
+    bool layerStackUpdateFound(const SurfaceChange& change, bool foundLayerStack);
+    bool hiddenFlagUpdateFound(const SurfaceChange& change, bool foundHiddenFlag);
+    bool opaqueFlagUpdateFound(const SurfaceChange& change, bool foundOpaqueFlag);
+    bool secureFlagUpdateFound(const SurfaceChange& change, bool foundSecureFlag);
+    bool deferredTransactionUpdateFound(const SurfaceChange& change, bool foundDeferred);
+    bool surfaceUpdateFound(Trace* trace, SurfaceChange::SurfaceChangeCase changeCase);
     void assertAllUpdatesFound(Trace* trace);
 
     // Verification of creation and deletion of a surface
-    bool surfaceCreateFound(Trace* trace);
-    bool surfaceDeleteFound(Trace* trace, uint32_t targetLayerId);
+    bool surfaceCreationFound(const Increment& increment, bool foundSurface);
+    bool surfaceDeletionFound(const Increment& increment, bool foundSurface);
+    bool displayCreationFound(const Increment& increment, bool foundDisplay);
+    bool displayDeletionFound(const Increment& increment, bool foundDisplay);
+    bool singleIncrementFound(Trace* trace, Increment::IncrementCase incrementCase);
 
     // Verification of buffer updates
     bool bufferUpdatesFound(Trace* trace);
@@ -186,8 +213,10 @@
     void secureFlagUpdate();
     void deferredTransactionUpdate();
     void runAllUpdates();
-    void surfaceCreate();
+    void surfaceCreation();
     void nBufferUpdates();
+    void displayCreation();
+    void displayDeletion();
 };
 
 void SurfaceInterceptorTest::captureTest(void (SurfaceInterceptorTest::* action)(void),
@@ -200,7 +229,16 @@
 }
 
 void SurfaceInterceptorTest::captureTest(void (SurfaceInterceptorTest::* action)(void),
-        Change::ChangeCase changeCase)
+        Increment::IncrementCase incrementCase)
+{
+    runInTransaction(action, true);
+    Trace capturedTrace;
+    ASSERT_EQ(NO_ERROR, readProtoFile(&capturedTrace));
+    ASSERT_TRUE(singleIncrementFound(&capturedTrace, incrementCase));
+}
+
+void SurfaceInterceptorTest::captureTest(void (SurfaceInterceptorTest::* action)(void),
+        SurfaceChange::SurfaceChangeCase changeCase)
 {
     runInTransaction(action, true);
     Trace capturedTrace;
@@ -279,6 +317,17 @@
     mBGSurfaceControl->deferTransactionUntil(mBGSurfaceControl->getHandle(), DEFERRED_UPDATE);
 }
 
+void SurfaceInterceptorTest::displayCreation() {
+    sp<IBinder> testDisplay = SurfaceComposerClient::createDisplay(DISPLAY_NAME, true);
+    SurfaceComposerClient::destroyDisplay(testDisplay);
+}
+
+void SurfaceInterceptorTest::displayDeletion() {
+    sp<IBinder> testDisplay = SurfaceComposerClient::createDisplay(DISPLAY_NAME, false);
+    mTargetId = getDisplayId(DISPLAY_NAME.string());
+    SurfaceComposerClient::destroyDisplay(testDisplay);
+}
+
 void SurfaceInterceptorTest::runAllUpdates() {
     runInTransaction(&SurfaceInterceptorTest::positionUpdate);
     runInTransaction(&SurfaceInterceptorTest::sizeUpdate);
@@ -296,7 +345,7 @@
     runInTransaction(&SurfaceInterceptorTest::deferredTransactionUpdate);
 }
 
-void SurfaceInterceptorTest::surfaceCreate() {
+void SurfaceInterceptorTest::surfaceCreation() {
     mComposerClient->createSurface(String8(LAYER_NAME), SIZE_UPDATE, SIZE_UPDATE,
             PIXEL_FORMAT_RGBA_8888, 0);
 }
@@ -311,7 +360,7 @@
     }
 }
 
-bool SurfaceInterceptorTest::positionUpdateFound(const Change& change, bool foundPosition) {
+bool SurfaceInterceptorTest::positionUpdateFound(const SurfaceChange& change, bool foundPosition) {
     // There should only be one position transaction with x and y = POSITION_UPDATE
     bool hasX(change.position().x() == POSITION_UPDATE);
     bool hasY(change.position().y() == POSITION_UPDATE);
@@ -325,7 +374,7 @@
     return foundPosition;
 }
 
-bool SurfaceInterceptorTest::sizeUpdateFound(const Change& change, bool foundSize) {
+bool SurfaceInterceptorTest::sizeUpdateFound(const SurfaceChange& change, bool foundSize) {
     bool hasWidth(change.size().h() == SIZE_UPDATE);
     bool hasHeight(change.size().w() == SIZE_UPDATE);
     if (hasWidth && hasHeight && !foundSize) {
@@ -337,7 +386,7 @@
     return foundSize;
 }
 
-bool SurfaceInterceptorTest::alphaUpdateFound(const Change& change, bool foundAlpha) {
+bool SurfaceInterceptorTest::alphaUpdateFound(const SurfaceChange& change, bool foundAlpha) {
     bool hasAlpha(change.alpha().alpha() == ALPHA_UPDATE);
     if (hasAlpha && !foundAlpha) {
         foundAlpha = true;
@@ -348,7 +397,7 @@
     return foundAlpha;
 }
 
-bool SurfaceInterceptorTest::layerUpdateFound(const Change& change, bool foundLayer) {
+bool SurfaceInterceptorTest::layerUpdateFound(const SurfaceChange& change, bool foundLayer) {
     bool hasLayer(change.layer().layer() == LAYER_UPDATE);
     if (hasLayer && !foundLayer) {
         foundLayer = true;
@@ -359,7 +408,7 @@
     return foundLayer;
 }
 
-bool SurfaceInterceptorTest::cropUpdateFound(const Change& change, bool foundCrop) {
+bool SurfaceInterceptorTest::cropUpdateFound(const SurfaceChange& change, bool foundCrop) {
     bool hasLeft(change.crop().rectangle().left() == CROP_UPDATE.left);
     bool hasTop(change.crop().rectangle().top() == CROP_UPDATE.top);
     bool hasRight(change.crop().rectangle().right() == CROP_UPDATE.right);
@@ -373,7 +422,9 @@
     return foundCrop;
 }
 
-bool SurfaceInterceptorTest::finalCropUpdateFound(const Change& change, bool foundFinalCrop) {
+bool SurfaceInterceptorTest::finalCropUpdateFound(const SurfaceChange& change,
+        bool foundFinalCrop)
+{
     bool hasLeft(change.final_crop().rectangle().left() == CROP_UPDATE.left);
     bool hasTop(change.final_crop().rectangle().top() == CROP_UPDATE.top);
     bool hasRight(change.final_crop().rectangle().right() == CROP_UPDATE.right);
@@ -387,7 +438,7 @@
     return foundFinalCrop;
 }
 
-bool SurfaceInterceptorTest::matrixUpdateFound(const Change& change, bool foundMatrix) {
+bool SurfaceInterceptorTest::matrixUpdateFound(const SurfaceChange& change, bool foundMatrix) {
     bool hasSx((float)change.matrix().dsdx() == (float)M_SQRT1_2);
     bool hasTx((float)change.matrix().dtdx() == (float)M_SQRT1_2);
     bool hasSy((float)change.matrix().dsdy() == (float)-M_SQRT1_2);
@@ -401,7 +452,9 @@
     return foundMatrix;
 }
 
-bool SurfaceInterceptorTest::scalingModeUpdateFound(const Change& change, bool foundScalingMode) {
+bool SurfaceInterceptorTest::scalingModeUpdateFound(const SurfaceChange& change,
+        bool foundScalingMode)
+{
     bool hasScalingUpdate(change.override_scaling_mode().override_scaling_mode() == SCALING_UPDATE);
     if (hasScalingUpdate && !foundScalingMode) {
         foundScalingMode = true;
@@ -412,7 +465,7 @@
     return foundScalingMode;
 }
 
-bool SurfaceInterceptorTest::transparentRegionHintUpdateFound(const Change& change,
+bool SurfaceInterceptorTest::transparentRegionHintUpdateFound(const SurfaceChange& change,
         bool foundTransparentRegion)
 {
     auto traceRegion = change.transparent_region_hint().region(0);
@@ -429,7 +482,9 @@
     return foundTransparentRegion;
 }
 
-bool SurfaceInterceptorTest::layerStackUpdateFound(const Change& change, bool foundLayerStack) {
+bool SurfaceInterceptorTest::layerStackUpdateFound(const SurfaceChange& change,
+        bool foundLayerStack)
+{
     bool hasLayerStackUpdate(change.layer_stack().layer_stack() == STACK_UPDATE);
     if (hasLayerStackUpdate && !foundLayerStack) {
         foundLayerStack = true;
@@ -440,7 +495,9 @@
     return foundLayerStack;
 }
 
-bool SurfaceInterceptorTest::hiddenFlagUpdateFound(const Change& change, bool foundHiddenFlag) {
+bool SurfaceInterceptorTest::hiddenFlagUpdateFound(const SurfaceChange& change,
+        bool foundHiddenFlag)
+{
     bool hasHiddenFlag(change.hidden_flag().hidden_flag());
     if (hasHiddenFlag && !foundHiddenFlag) {
         foundHiddenFlag = true;
@@ -451,7 +508,9 @@
     return foundHiddenFlag;
 }
 
-bool SurfaceInterceptorTest::opaqueFlagUpdateFound(const Change& change, bool foundOpaqueFlag) {
+bool SurfaceInterceptorTest::opaqueFlagUpdateFound(const SurfaceChange& change,
+        bool foundOpaqueFlag)
+{
     bool hasOpaqueFlag(change.opaque_flag().opaque_flag());
     if (hasOpaqueFlag && !foundOpaqueFlag) {
         foundOpaqueFlag = true;
@@ -462,7 +521,9 @@
     return foundOpaqueFlag;
 }
 
-bool SurfaceInterceptorTest::secureFlagUpdateFound(const Change& change, bool foundSecureFlag) {
+bool SurfaceInterceptorTest::secureFlagUpdateFound(const SurfaceChange& change,
+        bool foundSecureFlag)
+{
     bool hasSecureFlag(change.secure_flag().secure_flag());
     if (hasSecureFlag && !foundSecureFlag) {
         foundSecureFlag = true;
@@ -473,12 +534,11 @@
     return foundSecureFlag;
 }
 
-bool SurfaceInterceptorTest::deferredTransactionUpdateFound(const Change& change,
+bool SurfaceInterceptorTest::deferredTransactionUpdateFound(const SurfaceChange& change,
         bool foundDeferred)
 {
     bool hasId(change.deferred_transaction().layer_id() == mBGLayerId);
-    bool hasFrameNumber(change.deferred_transaction().frame_number() ==
-            DEFERRED_UPDATE);
+    bool hasFrameNumber(change.deferred_transaction().frame_number() == DEFERRED_UPDATE);
     if (hasId && hasFrameNumber && !foundDeferred) {
         foundDeferred = true;
     }
@@ -488,114 +548,158 @@
     return foundDeferred;
 }
 
-bool SurfaceInterceptorTest::surfaceUpdateFound(Trace* trace, Change::ChangeCase changeCase) {
-    bool updateFound = false;
+bool SurfaceInterceptorTest::surfaceUpdateFound(Trace* trace,
+        SurfaceChange::SurfaceChangeCase changeCase)
+{
+    bool foundUpdate = false;
     for (const auto& increment : *trace->mutable_increment()) {
         if (increment.increment_case() == increment.kTransaction) {
-            for (const auto& change : increment.transaction().change()) {
-                if (change.id() == mBGLayerId && change.Change_case() == changeCase) {
+            for (const auto& change : increment.transaction().surface_change()) {
+                if (change.id() == mBGLayerId && change.SurfaceChange_case() == changeCase) {
                     switch (changeCase) {
-                        case Change::ChangeCase::kPosition:
-                            // updateFound is sent for the tests to fail on duplicated increments
-                            updateFound = positionUpdateFound(change, updateFound);
+                        case SurfaceChange::SurfaceChangeCase::kPosition:
+                            // foundUpdate is sent for the tests to fail on duplicated increments
+                            foundUpdate = positionUpdateFound(change, foundUpdate);
                             break;
-                        case Change::ChangeCase::kSize:
-                            updateFound = sizeUpdateFound(change, updateFound);
+                        case SurfaceChange::SurfaceChangeCase::kSize:
+                            foundUpdate = sizeUpdateFound(change, foundUpdate);
                             break;
-                        case Change::ChangeCase::kAlpha:
-                            updateFound = alphaUpdateFound(change, updateFound);
+                        case SurfaceChange::SurfaceChangeCase::kAlpha:
+                            foundUpdate = alphaUpdateFound(change, foundUpdate);
                             break;
-                        case Change::ChangeCase::kLayer:
-                            updateFound = layerUpdateFound(change, updateFound);
+                        case SurfaceChange::SurfaceChangeCase::kLayer:
+                            foundUpdate = layerUpdateFound(change, foundUpdate);
                             break;
-                        case Change::ChangeCase::kCrop:
-                            updateFound = cropUpdateFound(change, updateFound);
+                        case SurfaceChange::SurfaceChangeCase::kCrop:
+                            foundUpdate = cropUpdateFound(change, foundUpdate);
                             break;
-                        case Change::ChangeCase::kFinalCrop:
-                            updateFound = finalCropUpdateFound(change, updateFound);
+                        case SurfaceChange::SurfaceChangeCase::kFinalCrop:
+                            foundUpdate = finalCropUpdateFound(change, foundUpdate);
                             break;
-                        case Change::ChangeCase::kMatrix:
-                            updateFound = matrixUpdateFound(change, updateFound);
+                        case SurfaceChange::SurfaceChangeCase::kMatrix:
+                            foundUpdate = matrixUpdateFound(change, foundUpdate);
                             break;
-                        case Change::ChangeCase::kOverrideScalingMode:
-                            updateFound = scalingModeUpdateFound(change, updateFound);
+                        case SurfaceChange::SurfaceChangeCase::kOverrideScalingMode:
+                            foundUpdate = scalingModeUpdateFound(change, foundUpdate);
                             break;
-                        case Change::ChangeCase::kTransparentRegionHint:
-                            updateFound = transparentRegionHintUpdateFound(change, updateFound);
+                        case SurfaceChange::SurfaceChangeCase::kTransparentRegionHint:
+                            foundUpdate = transparentRegionHintUpdateFound(change, foundUpdate);
                             break;
-                        case Change::ChangeCase::kLayerStack:
-                            updateFound = layerStackUpdateFound(change, updateFound);
+                        case SurfaceChange::SurfaceChangeCase::kLayerStack:
+                            foundUpdate = layerStackUpdateFound(change, foundUpdate);
                             break;
-                        case Change::ChangeCase::kHiddenFlag:
-                            updateFound = hiddenFlagUpdateFound(change, updateFound);
+                        case SurfaceChange::SurfaceChangeCase::kHiddenFlag:
+                            foundUpdate = hiddenFlagUpdateFound(change, foundUpdate);
                             break;
-                        case Change::ChangeCase::kOpaqueFlag:
-                            updateFound = opaqueFlagUpdateFound(change, updateFound);
+                        case SurfaceChange::SurfaceChangeCase::kOpaqueFlag:
+                            foundUpdate = opaqueFlagUpdateFound(change, foundUpdate);
                             break;
-                        case Change::ChangeCase::kSecureFlag:
-                            updateFound = secureFlagUpdateFound(change, updateFound);
+                        case SurfaceChange::SurfaceChangeCase::kSecureFlag:
+                            foundUpdate = secureFlagUpdateFound(change, foundUpdate);
                             break;
-                        case Change::ChangeCase::kDeferredTransaction:
-                            updateFound = deferredTransactionUpdateFound(change, updateFound);
+                        case SurfaceChange::SurfaceChangeCase::kDeferredTransaction:
+                            foundUpdate = deferredTransactionUpdateFound(change, foundUpdate);
                             break;
-                        case Change::ChangeCase::CHANGE_NOT_SET:
+                        case SurfaceChange::SurfaceChangeCase::SURFACECHANGE_NOT_SET:
                             break;
                     }
                 }
             }
         }
     }
-    return updateFound;
+    return foundUpdate;
 }
 
 void SurfaceInterceptorTest::assertAllUpdatesFound(Trace* trace) {
-    ASSERT_TRUE(surfaceUpdateFound(trace, Change::ChangeCase::kPosition));
-    ASSERT_TRUE(surfaceUpdateFound(trace, Change::ChangeCase::kSize));
-    ASSERT_TRUE(surfaceUpdateFound(trace, Change::ChangeCase::kAlpha));
-    ASSERT_TRUE(surfaceUpdateFound(trace, Change::ChangeCase::kLayer));
-    ASSERT_TRUE(surfaceUpdateFound(trace, Change::ChangeCase::kCrop));
-    ASSERT_TRUE(surfaceUpdateFound(trace, Change::ChangeCase::kFinalCrop));
-    ASSERT_TRUE(surfaceUpdateFound(trace, Change::ChangeCase::kMatrix));
-    ASSERT_TRUE(surfaceUpdateFound(trace, Change::ChangeCase::kOverrideScalingMode));
-    ASSERT_TRUE(surfaceUpdateFound(trace, Change::ChangeCase::kTransparentRegionHint));
-    ASSERT_TRUE(surfaceUpdateFound(trace, Change::ChangeCase::kLayerStack));
-    ASSERT_TRUE(surfaceUpdateFound(trace, Change::ChangeCase::kHiddenFlag));
-    ASSERT_TRUE(surfaceUpdateFound(trace, Change::ChangeCase::kOpaqueFlag));
-    ASSERT_TRUE(surfaceUpdateFound(trace, Change::ChangeCase::kSecureFlag));
-    ASSERT_TRUE(surfaceUpdateFound(trace, Change::ChangeCase::kDeferredTransaction));
+    ASSERT_TRUE(surfaceUpdateFound(trace, SurfaceChange::SurfaceChangeCase::kPosition));
+    ASSERT_TRUE(surfaceUpdateFound(trace, SurfaceChange::SurfaceChangeCase::kSize));
+    ASSERT_TRUE(surfaceUpdateFound(trace, SurfaceChange::SurfaceChangeCase::kAlpha));
+    ASSERT_TRUE(surfaceUpdateFound(trace, SurfaceChange::SurfaceChangeCase::kLayer));
+    ASSERT_TRUE(surfaceUpdateFound(trace, SurfaceChange::SurfaceChangeCase::kCrop));
+    ASSERT_TRUE(surfaceUpdateFound(trace, SurfaceChange::SurfaceChangeCase::kFinalCrop));
+    ASSERT_TRUE(surfaceUpdateFound(trace, SurfaceChange::SurfaceChangeCase::kMatrix));
+    ASSERT_TRUE(surfaceUpdateFound(trace, SurfaceChange::SurfaceChangeCase::kOverrideScalingMode));
+    ASSERT_TRUE(surfaceUpdateFound(trace, SurfaceChange::SurfaceChangeCase::kTransparentRegionHint));
+    ASSERT_TRUE(surfaceUpdateFound(trace, SurfaceChange::SurfaceChangeCase::kLayerStack));
+    ASSERT_TRUE(surfaceUpdateFound(trace, SurfaceChange::SurfaceChangeCase::kHiddenFlag));
+    ASSERT_TRUE(surfaceUpdateFound(trace, SurfaceChange::SurfaceChangeCase::kOpaqueFlag));
+    ASSERT_TRUE(surfaceUpdateFound(trace, SurfaceChange::SurfaceChangeCase::kSecureFlag));
+    ASSERT_TRUE(surfaceUpdateFound(trace, SurfaceChange::SurfaceChangeCase::kDeferredTransaction));
 }
 
-bool SurfaceInterceptorTest::surfaceCreateFound(Trace* trace) {
-    bool foundLayer = false;
-    for (const auto& inc : *trace->mutable_increment()) {
-        if (inc.increment_case() == inc.kCreate) {
-            bool isMatch(inc.create().name() == LAYER_NAME && inc.create().w() == SIZE_UPDATE &&
-                    inc.create().h() == SIZE_UPDATE);
-            if (isMatch && !foundLayer) {
-                foundLayer = true;
-            }
-            else if (isMatch && foundLayer) {
-                return false;
-            }
-        }
+bool SurfaceInterceptorTest::surfaceCreationFound(const Increment& increment, bool foundSurface) {
+    bool isMatch(increment.surface_creation().name() == LAYER_NAME &&
+            increment.surface_creation().w() == SIZE_UPDATE &&
+            increment.surface_creation().h() == SIZE_UPDATE);
+    if (isMatch && !foundSurface) {
+        foundSurface = true;
     }
-    return foundLayer;
+    else if (isMatch && foundSurface) {
+        [] () { FAIL(); }();
+    }
+    return foundSurface;
 }
 
-bool SurfaceInterceptorTest::surfaceDeleteFound(Trace* trace, uint32_t targetLayerId) {
-    bool foundLayer = false;
+bool SurfaceInterceptorTest::surfaceDeletionFound(const Increment& increment, bool foundSurface) {
+    bool isMatch(increment.surface_deletion().id() == mTargetId);
+    if (isMatch && !foundSurface) {
+        foundSurface = true;
+    }
+    else if (isMatch && foundSurface) {
+        [] () { FAIL(); }();
+    }
+    return foundSurface;
+}
+
+bool SurfaceInterceptorTest::displayCreationFound(const Increment& increment, bool foundDisplay) {
+    bool isMatch(increment.display_creation().name() == DISPLAY_NAME.string() &&
+            increment.display_creation().is_secure());
+    if (isMatch && !foundDisplay) {
+        foundDisplay = true;
+    }
+    else if (isMatch && foundDisplay) {
+        [] () { FAIL(); }();
+    }
+    return foundDisplay;
+}
+
+bool SurfaceInterceptorTest::displayDeletionFound(const Increment& increment, bool foundDisplay) {
+    bool isMatch(increment.display_deletion().id() == mTargetId);
+    if (isMatch && !foundDisplay) {
+        foundDisplay = true;
+    }
+    else if (isMatch && foundDisplay) {
+        [] () { FAIL(); }();
+    }
+    return foundDisplay;
+}
+
+bool SurfaceInterceptorTest::singleIncrementFound(Trace* trace,
+        Increment::IncrementCase incrementCase)
+{
+    bool foundIncrement = false;
     for (const auto& increment : *trace->mutable_increment()) {
-        if (increment.increment_case() == increment.kDelete) {
-            bool isMatch(increment.delete_().id() == targetLayerId);
-            if (isMatch && !foundLayer) {
-                foundLayer = true;
-            }
-            else if (isMatch && foundLayer) {
-                return false;
+        if (increment.increment_case() == incrementCase) {
+            switch (incrementCase) {
+                case Increment::IncrementCase::kSurfaceCreation:
+                    foundIncrement = surfaceCreationFound(increment, foundIncrement);
+                    break;
+                case Increment::IncrementCase::kSurfaceDeletion:
+                    foundIncrement = surfaceDeletionFound(increment, foundIncrement);
+                    break;
+                case Increment::IncrementCase::kDisplayCreation:
+                    foundIncrement = displayCreationFound(increment, foundIncrement);
+                    break;
+                case Increment::IncrementCase::kDisplayDeletion:
+                    foundIncrement = displayDeletionFound(increment, foundIncrement);
+                    break;
+                default:
+                    /* code */
+                    break;
             }
         }
     }
-    return foundLayer;
+    return foundIncrement;
 }
 
 bool SurfaceInterceptorTest::bufferUpdatesFound(Trace* trace) {
@@ -609,62 +713,68 @@
 }
 
 TEST_F(SurfaceInterceptorTest, InterceptPositionUpdateWorks) {
-    captureTest(&SurfaceInterceptorTest::positionUpdate, Change::ChangeCase::kPosition);
+    captureTest(&SurfaceInterceptorTest::positionUpdate,
+            SurfaceChange::SurfaceChangeCase::kPosition);
 }
 
 TEST_F(SurfaceInterceptorTest, InterceptSizeUpdateWorks) {
-    captureTest(&SurfaceInterceptorTest::sizeUpdate, Change::ChangeCase::kSize);
+    captureTest(&SurfaceInterceptorTest::sizeUpdate, SurfaceChange::SurfaceChangeCase::kSize);
 }
 
 TEST_F(SurfaceInterceptorTest, InterceptAlphaUpdateWorks) {
-    captureTest(&SurfaceInterceptorTest::alphaUpdate, Change::ChangeCase::kAlpha);
+    captureTest(&SurfaceInterceptorTest::alphaUpdate, SurfaceChange::SurfaceChangeCase::kAlpha);
 }
 
 TEST_F(SurfaceInterceptorTest, InterceptLayerUpdateWorks) {
-    captureTest(&SurfaceInterceptorTest::layerUpdate, Change::ChangeCase::kLayer);
+    captureTest(&SurfaceInterceptorTest::layerUpdate, SurfaceChange::SurfaceChangeCase::kLayer);
 }
 
 TEST_F(SurfaceInterceptorTest, InterceptCropUpdateWorks) {
-    captureTest(&SurfaceInterceptorTest::cropUpdate, Change::ChangeCase::kCrop);
+    captureTest(&SurfaceInterceptorTest::cropUpdate, SurfaceChange::SurfaceChangeCase::kCrop);
 }
 
 TEST_F(SurfaceInterceptorTest, InterceptFinalCropUpdateWorks) {
-    captureTest(&SurfaceInterceptorTest::finalCropUpdate, Change::ChangeCase::kFinalCrop);
+    captureTest(&SurfaceInterceptorTest::finalCropUpdate,
+            SurfaceChange::SurfaceChangeCase::kFinalCrop);
 }
 
 TEST_F(SurfaceInterceptorTest, InterceptMatrixUpdateWorks) {
-    captureTest(&SurfaceInterceptorTest::matrixUpdate, Change::ChangeCase::kMatrix);
+    captureTest(&SurfaceInterceptorTest::matrixUpdate, SurfaceChange::SurfaceChangeCase::kMatrix);
 }
 
 TEST_F(SurfaceInterceptorTest, InterceptOverrideScalingModeUpdateWorks) {
     captureTest(&SurfaceInterceptorTest::overrideScalingModeUpdate,
-            Change::ChangeCase::kOverrideScalingMode);
+            SurfaceChange::SurfaceChangeCase::kOverrideScalingMode);
 }
 
 TEST_F(SurfaceInterceptorTest, InterceptTransparentRegionHintUpdateWorks) {
     captureTest(&SurfaceInterceptorTest::transparentRegionHintUpdate,
-            Change::ChangeCase::kTransparentRegionHint);
+            SurfaceChange::SurfaceChangeCase::kTransparentRegionHint);
 }
 
 TEST_F(SurfaceInterceptorTest, InterceptLayerStackUpdateWorks) {
-    captureTest(&SurfaceInterceptorTest::layerStackUpdate, Change::ChangeCase::kLayerStack);
+    captureTest(&SurfaceInterceptorTest::layerStackUpdate,
+            SurfaceChange::SurfaceChangeCase::kLayerStack);
 }
 
 TEST_F(SurfaceInterceptorTest, InterceptHiddenFlagUpdateWorks) {
-    captureTest(&SurfaceInterceptorTest::hiddenFlagUpdate, Change::ChangeCase::kHiddenFlag);
+    captureTest(&SurfaceInterceptorTest::hiddenFlagUpdate,
+            SurfaceChange::SurfaceChangeCase::kHiddenFlag);
 }
 
 TEST_F(SurfaceInterceptorTest, InterceptOpaqueFlagUpdateWorks) {
-    captureTest(&SurfaceInterceptorTest::opaqueFlagUpdate, Change::ChangeCase::kOpaqueFlag);
+    captureTest(&SurfaceInterceptorTest::opaqueFlagUpdate,
+            SurfaceChange::SurfaceChangeCase::kOpaqueFlag);
 }
 
 TEST_F(SurfaceInterceptorTest, InterceptSecureFlagUpdateWorks) {
-    captureTest(&SurfaceInterceptorTest::secureFlagUpdate, Change::ChangeCase::kSecureFlag);
+    captureTest(&SurfaceInterceptorTest::secureFlagUpdate,
+            SurfaceChange::SurfaceChangeCase::kSecureFlag);
 }
 
 TEST_F(SurfaceInterceptorTest, InterceptDeferredTransactionUpdateWorks) {
     captureTest(&SurfaceInterceptorTest::deferredTransactionUpdate,
-            Change::ChangeCase::kDeferredTransaction);
+            SurfaceChange::SurfaceChangeCase::kDeferredTransaction);
 }
 
 TEST_F(SurfaceInterceptorTest, InterceptAllUpdatesWorks) {
@@ -678,21 +788,32 @@
     assertAllUpdatesFound(&capturedTrace);
 }
 
-TEST_F(SurfaceInterceptorTest, InterceptLayerCreateWorks) {
-    captureTest(&SurfaceInterceptorTest::surfaceCreate, &SurfaceInterceptorTest::surfaceCreateFound);
+TEST_F(SurfaceInterceptorTest, InterceptSurfaceCreationWorks) {
+    captureTest(&SurfaceInterceptorTest::surfaceCreation,
+            Increment::IncrementCase::kSurfaceCreation);
 }
 
-TEST_F(SurfaceInterceptorTest, InterceptLayerDeleteWorks) {
+TEST_F(SurfaceInterceptorTest, InterceptSurfaceDeletionWorks) {
     sp<SurfaceControl> layerToDelete = mComposerClient->createSurface(String8(LAYER_NAME),
             SIZE_UPDATE, SIZE_UPDATE, PIXEL_FORMAT_RGBA_8888, 0);
-    uint32_t targetLayerId = getLayerId(LAYER_NAME);
+    this->mTargetId = getSurfaceId(LAYER_NAME);
     enableInterceptor();
     mComposerClient->destroySurface(layerToDelete->getHandle());
     disableInterceptor();
 
     Trace capturedTrace;
     ASSERT_EQ(NO_ERROR, readProtoFile(&capturedTrace));
-    ASSERT_TRUE(surfaceDeleteFound(&capturedTrace, targetLayerId));
+    ASSERT_TRUE(singleIncrementFound(&capturedTrace, Increment::IncrementCase::kSurfaceDeletion));
+}
+
+TEST_F(SurfaceInterceptorTest, InterceptDisplayCreationWorks) {
+    captureTest(&SurfaceInterceptorTest::displayCreation,
+            Increment::IncrementCase::kDisplayCreation);
+}
+
+TEST_F(SurfaceInterceptorTest, InterceptDisplayDeletionWorks) {
+    captureTest(&SurfaceInterceptorTest::displayDeletion,
+            Increment::IncrementCase::kDisplayDeletion);
 }
 
 TEST_F(SurfaceInterceptorTest, InterceptBufferUpdateWorks) {
@@ -701,7 +822,8 @@
 }
 
 // If the interceptor is enabled while buffer updates are being pushed, the interceptor should
-// first create a snapshot of the existing surfaces and then start capturing the buffer updates
+// first create a snapshot of the existing displays and surfaces and then start capturing
+// the buffer updates
 TEST_F(SurfaceInterceptorTest, InterceptWhileBufferUpdatesWorks) {
     std::thread bufferUpdates(&SurfaceInterceptorTest::nBufferUpdates, this);
     enableInterceptor();
@@ -711,14 +833,14 @@
     Trace capturedTrace;
     ASSERT_EQ(NO_ERROR, readProtoFile(&capturedTrace));
     const auto& firstIncrement = capturedTrace.mutable_increment(0);
-    ASSERT_EQ(firstIncrement->increment_case(), Increment::IncrementCase::kCreate);
+    ASSERT_EQ(firstIncrement->increment_case(), Increment::IncrementCase::kDisplayCreation);
 }
 
 TEST_F(SurfaceInterceptorTest, InterceptSimultaneousUpdatesWorks) {
     enableInterceptor();
     std::thread bufferUpdates(&SurfaceInterceptorTest::nBufferUpdates, this);
     std::thread surfaceUpdates(&SurfaceInterceptorTest::runAllUpdates, this);
-    runInTransaction(&SurfaceInterceptorTest::surfaceCreate);
+    runInTransaction(&SurfaceInterceptorTest::surfaceCreation);
     bufferUpdates.join();
     surfaceUpdates.join();
     disableInterceptor();
@@ -728,7 +850,7 @@
 
     assertAllUpdatesFound(&capturedTrace);
     ASSERT_TRUE(bufferUpdatesFound(&capturedTrace));
-    ASSERT_TRUE(surfaceCreateFound(&capturedTrace));
+    ASSERT_TRUE(singleIncrementFound(&capturedTrace, Increment::IncrementCase::kSurfaceCreation));
 }
 
 }