~loic.molinari/ubuntu-ui-toolkit/ubuntu-ui-toolkit-ubuntu-shape-icon

« back to all changes in this revision

Viewing changes to src/Ubuntu/Components/plugin/ucubuntushape.cpp

  • Committer: Loïc Molinari
  • Date: 2015-08-06 13:16:24 UTC
  • mfrom: (1568.1.24 staging)
  • Revision ID: loic.molinari@canonical.com-20150806131624-vbtvrvpu5z1bapd8
Merged lp:ubuntu-ui-toolkit/staging.

Show diffs side-by-side

added added

removed removed

Lines of Context:
74
74
 
75
75
    m_functions = QOpenGLContext::currentContext()->functions();
76
76
    m_matrixId = program()->uniformLocation("matrix");
77
 
    m_dfdtFactorsId = program()->uniformLocation("dfdtFactors");
78
77
    m_opacityFactorsId = program()->uniformLocation("opacityFactors");
 
78
    m_dfdtFactorId = program()->uniformLocation("dfdtFactor");
79
79
    m_sourceOpacityId = program()->uniformLocation("sourceOpacity");
80
80
    m_distanceAAId = program()->uniformLocation("distanceAA");
81
81
    m_texturedId = program()->uniformLocation("textured");
138
138
    const float distanceAA = (shapeTextureDistanceAA * distanceAApx) / (2.0 * 255.0f);
139
139
    program()->setUniformValue(m_distanceAAId, data->distanceAAFactor * distanceAA);
140
140
 
141
 
    // Send screen-space derivative factors. Note that when rendering is redirected to a
142
 
    // ShaderEffectSource (FBO), dFdy() sign is flipped.
143
 
    const float orientation = static_cast<float>(data->dfdtFactors & 0x4);
144
 
    const float flip = static_cast<float>(data->dfdtFactors & 0x3) - 1.0f;
145
 
    const bool flipped = orientation != 1.0f && state.projectionMatrix()(1, 3) < 0.0f;
146
 
    const QVector2D dfdtFactors(orientation, flipped ? -flip : flip);
147
 
    program()->setUniformValue(m_dfdtFactorsId, dfdtFactors);
 
141
    // When rendering is redirected to a ShaderEffectSource (FBO), dFdy() sign is flipped.
 
142
    const float dfdtFactor = (state.projectionMatrix()(1, 3) < 0.0f) ? -1.0f : 1.0f;
 
143
    program()->setUniformValue(m_dfdtFactorId, dfdtFactor);
148
144
 
149
145
    // Update QtQuick engine uniforms.
150
146
    if (state.isMatrixDirty()) {
252
248
 
253
249
static struct { QOpenGLContext* openglContext; quint32 textureId[shapeTextureCount]; }
254
250
    shapeTextures[maxShapeTextures];
255
 
static bool isPrimaryOrientationLandscape = false;
256
251
 
257
252
static int getShapeTexturesIndex(const QOpenGLContext* openglContext);
258
253
 
310
305
    , m_sourceOpacity(255)
311
306
    , m_flags(Stretched)
312
307
{
313
 
    static bool once = true;
314
 
    if (once) {
315
 
        // Stored statically as the primary orientation is fixed and we don't support multiple
316
 
        // screens for now.
317
 
        if (QGuiApplication::primaryScreen()->primaryOrientation() &
318
 
            (Qt::LandscapeOrientation | Qt::InvertedLandscapeOrientation)) {
319
 
            isPrimaryOrientationLandscape = true;
320
 
        }
321
 
        once = false;
322
 
    }
323
 
 
324
308
    setFlag(ItemHasContents);
325
309
    QObject::connect(&UCUnits::instance(), SIGNAL(gridUnitChanged()), this,
326
310
                     SLOT(_q_gridUnitChanged()));
1306
1290
    materialData->distanceAAFactor =
1307
1291
        qMin((radius / (end - start)) - (start / (end - start)), 1.0f) * 255.0f;
1308
1292
 
1309
 
    // Screen-space derivatives factors for fragment shaders depend on the primary orientation and
1310
 
    // content orientation. A flag indicating a 90° rotation around the primary orientation is
1311
 
    // stored on the 3rd bit of dfdtFactors, the flip factor is stored on the first 2 bits as 0 for
1312
 
    // -1 and as 2 for 1 (efficiently converted using: float(x & 0x3) - 1.0f).
1313
 
    const Qt::ScreenOrientation contentOrientation = window()->contentOrientation();
1314
 
    if (isPrimaryOrientationLandscape) {
1315
 
        const quint8 portraitMask = Qt::PortraitOrientation | Qt::InvertedPortraitOrientation;
1316
 
        const quint8 flipMask = Qt::InvertedLandscapeOrientation | Qt::InvertedPortraitOrientation;
1317
 
        quint8 factors = contentOrientation & portraitMask ? 0x4 : 0x0;
1318
 
        factors |= contentOrientation & flipMask ? 0x0 : 0x2;
1319
 
        materialData->dfdtFactors = factors;
1320
 
    } else {
1321
 
        const quint8 landscapeMask = Qt::LandscapeOrientation | Qt::InvertedLandscapeOrientation;
1322
 
        const quint8 flipMask = Qt::InvertedPortraitOrientation | Qt::LandscapeOrientation;
1323
 
        quint8 factors = contentOrientation & landscapeMask ? 0x4 : 0x0;
1324
 
        factors |= contentOrientation & flipMask ? 0x0 : 0x2;
1325
 
        materialData->dfdtFactors = factors;
1326
 
    }
1327
 
 
1328
1293
    // When the radius is equal to radiusSizeOffset (which means radius size is 0), no aspect is
1329
1294
    // flagged so that a dedicated (statically flow controlled) shaved off shader can be used for
1330
1295
    // optimal performance.