/////////////////////////////////////////////////////////////////////////////// // Copyright (C) 2002-2025, Open Design Alliance (the "Alliance"). // All rights reserved. // // This software and its documentation and related materials are owned by // the Alliance. The software may only be incorporated into application // programs owned by members of the Alliance, subject to a signed // Membership Agreement and Supplemental Software License Agreement with the // Alliance. The structure and organization of this software are the valuable // trade secrets of the Alliance and its suppliers. The software is also // protected by copyright law and international treaty provisions. Application // programs incorporating this software must include the following statement // with their copyright notices: // // This application incorporates Open Design Alliance software pursuant to a license // agreement with Open Design Alliance. // Open Design Alliance Copyright (C) 2002-2025 by Open Design Alliance. // All rights reserved. // // By use of this software, its documentation or related materials, you // acknowledge and accept the above terms. /////////////////////////////////////////////////////////////////////////////// #ifndef OD_SR_UPDATE_MANAGER #define OD_SR_UPDATE_MANAGER #include "Gs/Gs.h" #include "Gs/GsBaseInclude.h" #include "Gs/GsBaseModel.h" #include "SrCameraMovementRecognizer.h" class OdGsSrVectorizerDevice; class OdGsSrVectorizeView; class OdSrCameraMovementRecognizer; enum OdSrViewFlagBits { kViewDirty = 0, // View needs updating kViewPreviouslyVisible = 1 // View was visible in the previous frame // Additional flags can be added here }; /** * Interface for view update strategies. * Each strategy implements a specific approach for updating views and their regions. */ class OdSrUpdateStrategyBase { public: OdSrUpdateStrategyBase(OdGsSrVectorizerDevice* pDevice) : m_device(pDevice) {} /** * Updates a specific region of the rendering device. * * @param region The rectangle defining the region to update * @param views List of views that overlap with this region * @param outInvalidRects Output parameter for invalid rectangles generated during update */ virtual void updateRegion(const OdGsDCRect& region, const OdArray& views, OdGsDCRectArray& outInvalidRects) = 0; /** * Performs post-update operations, such as restoring view visibility. * This is called after all regions have been updated. * * @param views List of views processed by this strategy */ virtual void postUpdate(const OdArray& /*views*/) {} virtual ~OdSrUpdateStrategyBase() {} protected: OdGsSrVectorizerDevice* m_device; }; /** * Strategy for standard background filling and redrawing. */ class OdSrDefaultUpdateStrategy : public OdSrUpdateStrategyBase { public: OdSrDefaultUpdateStrategy(OdGsSrVectorizerDevice* pDevice) : OdSrUpdateStrategyBase(pDevice) {} void updateRegion(const OdGsDCRect& region, const OdArray& views, OdGsDCRectArray& outInvalidRects) override; }; /** * Strategy for panning operations that moves existing pixels and only redraws * the newly exposed areas. */ class OdSrPanUpdateStrategy : public OdSrUpdateStrategyBase { public: struct ViewVisibilityState { OdGsSrVectorizeView* pView; bool wasVisible; }; OdSrPanUpdateStrategy(OdGsSrVectorizerDevice* pDevice) : OdSrUpdateStrategyBase(pDevice), m_sdx(0), m_sdy(0) {} void updateRegion(const OdGsDCRect& region, const OdArray& views, OdGsDCRectArray& outInvalidRects) override; void setPanData(const CameraMovementType::PanData& data); virtual void postUpdate(const OdArray& views) override; OdGsDCRectArray calculateInvalidRects(const OdGsDCRect& dcRect); protected: OdInt32 m_sdx; OdInt32 m_sdy; /** * List of views that were hidden during the update. */ OdArray m_hiddenViews; }; class OdSrEmptyUpdateStrategy : public OdSrUpdateStrategyBase { public: OdSrEmptyUpdateStrategy(OdGsSrVectorizerDevice* pDevice) : OdSrUpdateStrategyBase(pDevice) {} void updateRegion(const OdGsDCRect& /*region*/, const OdArray& /*views*/, OdGsDCRectArray& /*outInvalidRects*/) override { // Do absolutely nothing // No background filling, no pixel movement, no invalid rectangles } }; /** * Represents a region of the screen that will be updated with a specific strategy. * Regions are created by analyzing view boundaries and intersections. */ struct OdSrRenderingRegion { OdGsDCRect rect; // Region boundaries OdArray views; // Views that overlap this region OdSrUpdateStrategyBase* strategy; // Strategy to apply to this region }; // Track which strategy was used for which views struct OdSrStrategyViewsMap { OdSrUpdateStrategyBase* strategy; OdArray views; }; /** * Enhanced update manager that uses a region-based approach to handle overlapping views. */ class OdSrUpdateManager { public: OdSrUpdateManager(OdGsSrVectorizerDevice* device); ~OdSrUpdateManager(); /** * Main method to update all views with proper handling of intersections. */ void updateViews(OdGsDCRect* pRect); private: void initializeDirtyViews(); OdGsDCRectArray applyStrategies(const OdArray renderingRegions, OdArray& strategyViewsMap); bool viewNeedsUpdate(OdGsSrVectorizeView* pView) const; bool isFullscreenView(OdGsSrVectorizeView* pView) const; /** * Checks if a view is eligible for panning operations. * * @param pView The view to check * @return true if the view can be panned */ bool checkViewForPanning(OdGsSrVectorizeView* pView) const; /** * Checks if two rectangles intersect. * * @param rect1 First rectangle * @param rect2 Second rectangle * @return true if rectangles intersect */ static bool rectsIntersect(const OdGsDCRect& rect1, const OdGsDCRect& rect2); static bool calculateIntersection(const OdGsDCRect& rect1, const OdGsDCRect& rect2, OdGsDCRect& intersection); static OdArray splitRect(const OdGsDCRect& rect, const OdGsDCRect& obstacle); /** * Creates a union of two rectangles. * * @param rect1 First rectangle * @param rect2 Second rectangle * @return The union rectangle */ static OdGsDCRect unionRects(const OdGsDCRect& rect1, const OdGsDCRect& rect2); /** * Merges overlapping rectangles to optimize rendering performance. * * @param inputRects Input collection of rectangles * @param outputRects Output collection of optimized rectangles */ static void mergeOverlappingRects(const OdGsDCRectArray& inputRects, OdGsDCRectArray& outputRects); /** * Analyzes all views to determine their movement types and store necessary information. */ void analyzeViewMovements(); /** * Builds a set of non-overlapping rendering regions based on view boundaries. * Each region contains a list of views that overlap with it. * * @return Array of rendering regions that cover the entire rendering area */ OdArray buildRenderingRegions(); OdArray buildRenderingRegions_old(); OdArray resolveOverlappingRegions(const OdArray& baseRegions); OdArray mergeCompatibleRegions(const OdArray& regions); /** * Determines the optimal strategy for a rendering region based on the views it contains. * * @param region The rendering region to determine strategy for */ bool determineOptimalStrategy(OdSrRenderingRegion& region); /** * Finalizes the update process by optimizing invalid rectangles and updating the device. * * @param invalidRects Collection of invalid rectangles to process */ void finalizeUpdate(OdGsDCRectArray& invalidRects); /** * Gets the index of a view in the device's view collection. * * @param pView Pointer to the view * @return Index of the view, or -1 if not found */ int getViewIndex(OdGsSrVectorizeView* pView) const; OdArray m_isDirty; // Member variables to track view information OdArray m_viewMovementTypes; OdArray m_viewRects; // Device and recognizer references OdGsSrVectorizerDevice* m_device; // Strategy instances (owned) OdSrUpdateStrategyBase* m_defaultStrategy; OdSrUpdateStrategyBase* m_emptyStrategy; OdSrPanUpdateStrategy* m_panStrategy; OdSrCameraMovementRecognizer* m_cameraMovementRecognizer; // Not owned // Other strategy pointers as needed }; #endif //OD_SR_UPDATE_MANAGER