+ ClippingBox intersectionBox;
+
+ // First calculate the largest starting positions in X and Y.
+ intersectionBox.x = std::max( aabbA.x, aabbB.x );
+ intersectionBox.y = std::max( aabbA.y, aabbB.y );
+
+ // Now calculate the smallest ending positions, and take the largest starting
+ // positions from the result, to get the width and height respectively.
+ // If the two boxes do not intersect at all, then we need a 0 width and height clipping area.
+ // We use max here to clamp both width and height to >= 0 for this use-case.
+ intersectionBox.width = std::max( std::min( aabbA.x + aabbA.width, aabbB.x + aabbB.width ) - intersectionBox.x, 0 );
+ intersectionBox.height = std::max( std::min( aabbA.y + aabbA.height, aabbB.y + aabbB.height ) - intersectionBox.y, 0 );
+
+ return intersectionBox;
+}
+
+/**
+ * @brief Set up the stencil and color buffer for automatic clipping (StencilMode::AUTO).
+ * @param[in] item The current RenderItem about to be rendered
+ * @param[in] context The context
+ * @param[in/out] lastClippingDepth The stencil depth of the last renderer drawn.
+ * @param[in/out] lastClippingId The clipping ID of the last renderer drawn.
+ */
+inline void SetupStencilClipping( const RenderItem& item, Context& context, uint32_t& lastClippingDepth, uint32_t& lastClippingId )
+{
+ const Dali::Internal::SceneGraph::Node* node = item.mNode;
+ const uint32_t clippingId = node->GetClippingId();
+ // If there is no clipping Id, then either we haven't reached a clipping Node yet, or there aren't any.
+ // Either way we can skip clipping setup for this renderer.
+ if( clippingId == 0u )