Пример #1
0
bool GrClipMaskManager::drawClipShape(GrGpu* gpu,
                                      GrTexture* target,
                                      const GrClip& clipIn,
                                      int index) {
    GrDrawState* drawState = gpu->drawState();
    GrAssert(NULL != drawState);

    drawState->setRenderTarget(target->asRenderTarget());

    if (kRect_ClipType == clipIn.getElementType(index)) {
        if (clipIn.getDoAA(index)) {
            // convert the rect to a path for AA
            SkPath temp;
            temp.addRect(clipIn.getRect(index));

            return this->drawPath(gpu, temp,
                                  kEvenOdd_PathFill, clipIn.getDoAA(index));
        } else {
            gpu->drawSimpleRect(clipIn.getRect(index), NULL, 0);
        }
    } else {
        return this->drawPath(gpu,
                              clipIn.getPath(index),
                              clipIn.getPathFill(index),
                              clipIn.getDoAA(index));
    }
    return true;
}
/*
 * This method traverses the clip stack to see if the GrSoftwarePathRenderer
 * will be used on any element. If so, it returns true to indicate that the
 * entire clip should be rendered in SW and then uploaded en masse to the gpu.
 */
bool GrClipMaskManager::useSWOnlyPath(GrGpu* gpu, const GrClip& clipIn) {

    if (!clipIn.requiresAA()) {
        // The stencil buffer can handle this case
        return false;
    }

    // TODO: generalize this test so that when
    // a clip gets complex enough it can just be done in SW regardless
    // of whether it would invoke the GrSoftwarePathRenderer.
    bool useSW = false;

    for (int i = 0; i < clipIn.getElementCount(); ++i) {

        if (SkRegion::kReplace_Op == clipIn.getOp(i)) {
            // Everything before a replace op can be ignored so start
            // afresh w.r.t. determining if any element uses the SW path
            useSW = false;
        }

        if (!clipIn.getDoAA(i)) {
            // non-anti-aliased rects and paths can always be drawn either
            // directly or by the GrDefaultPathRenderer
            continue;
        }

        if (kRect_ClipType == clipIn.getElementType(i)) {
            // Antialiased rects are converted to paths and then drawn with
            // kEvenOdd_PathFill. 
            if (!GrAAConvexPathRenderer::staticCanDrawPath(
                                                    true,     // always convex
                                                    kEvenOdd_PathFill,
                                                    gpu, 
                                                    true)) {  // anti-aliased
                // if the GrAAConvexPathRenderer can't render this rect (due
                // to lack of derivative support in the shaders) then 
                // the GrSoftwarePathRenderer will be used
                useSW = true;
            }

            continue;
        }

        // only paths need to be considered in the rest of the loop body

        if (GrAAHairLinePathRenderer::staticCanDrawPath(clipIn.getPath(i),
                                                        clipIn.getPathFill(i),
                                                        gpu,
                                                        clipIn.getDoAA(i))) {
            // the hair line path renderer can handle this one
            continue;
        }

        if (GrAAConvexPathRenderer::staticCanDrawPath(
                                                clipIn.getPath(i).isConvex(),
                                                clipIn.getPathFill(i),
                                                gpu,
                                                clipIn.getDoAA(i))) {
            // the convex path renderer can handle this one
            continue;
        }

        // otherwise the GrSoftwarePathRenderer is going to be invoked
        useSW = true;
    }

    return useSW;
}