Warning, file /graphics/krita/sdk/tests/lod_override.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002  *  SPDX-FileCopyrightText: 2015 Dmitry Kazakov <dimula73@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #ifndef __LOD_OVERRIDE_H
0008 #define __LOD_OVERRIDE_H
0009 
0010 #include "kis_default_bounds_base.h"
0011 
0012 
0013 namespace TestUtil {
0014 
0015 class LodOverride
0016 {
0017 private:
0018 
0019     class LodDefaultBounds : public KisDefaultBoundsBase
0020     {
0021     public:
0022         LodDefaultBounds(int lod, KisDefaultBoundsBaseSP parent)
0023             : m_lod(lod), m_parent(parent)
0024         {
0025         }
0026 
0027         QRect bounds() const override {
0028             return m_parent->bounds();
0029         }
0030 
0031         virtual QRect imageBorderRect() const override {
0032             return m_parent->imageBorderRect();
0033         }
0034 
0035         bool wrapAroundMode() const override {
0036             return m_parent->wrapAroundMode();
0037         }
0038 
0039         int currentLevelOfDetail() const override {
0040             return m_lod;
0041         }
0042 
0043         int currentTime() const override {
0044             return m_parent->currentTime();
0045         }
0046 
0047         bool externalFrameActive() const override {
0048             return m_parent->externalFrameActive();
0049         }
0050 
0051         KisDefaultBoundsBaseSP parent() const {
0052             return m_parent;
0053         }
0054 
0055         void * sourceCookie() const override {
0056             return 0;
0057         }
0058 
0059     private:
0060         int m_lod;
0061         KisDefaultBoundsBaseSP m_parent;
0062     };
0063 
0064 public:
0065     explicit LodOverride(int lod, KisImageSP image)
0066         : m_lod(lod), m_image(image)
0067     {
0068         overrideBounds(m_image->root(), OverrideDevice(m_lod));
0069     }
0070 
0071     ~LodOverride()
0072     {
0073         overrideBounds(m_image->root(), RestoreDevice());
0074     }
0075 
0076 private:
0077 
0078     template <class OverrideOp>
0079     void overrideBounds(KisNodeSP root, OverrideOp op) {
0080         op(root->paintDevice());
0081 
0082         if (root->original() != root->paintDevice()) {
0083             op(root->original());
0084         }
0085 
0086         if (root->projection() != root->original()) {
0087             op(root->projection());
0088         }
0089 
0090         KisNodeSP node = root->firstChild();
0091         while (node) {
0092             overrideBounds(node, op);
0093             node = node->nextSibling();
0094         }
0095     }
0096 
0097     struct OverrideDevice {
0098         OverrideDevice(int lod) : m_lod(lod) {}
0099 
0100         void operator() (KisPaintDeviceSP device) {
0101             if (!device) return;
0102 
0103             LodDefaultBounds *bounds = dynamic_cast<LodDefaultBounds*>(device->defaultBounds().data());
0104             if (bounds) return;
0105 
0106             device->setDefaultBounds(new LodDefaultBounds(m_lod, device->defaultBounds()));
0107         }
0108 
0109         int m_lod;
0110     };
0111 
0112     struct RestoreDevice {
0113         void operator() (KisPaintDeviceSP device) {
0114             if (!device) return;
0115 
0116             LodDefaultBounds *bounds = dynamic_cast<LodDefaultBounds*>(device->defaultBounds().data());
0117             if (!bounds) return;
0118 
0119             device->setDefaultBounds(bounds->parent());
0120         }
0121     };
0122 
0123 private:
0124     int m_lod;
0125     KisImageSP m_image;
0126 };
0127 
0128 }
0129 
0130 #endif /* __LOD_OVERRIDE_H */