示例#1
0
文件: GrGpu.cpp 项目: Igalia/skia
bool GrGpu::attachStencilBufferToRenderTarget(GrRenderTarget* rt) {
    SkASSERT(NULL == rt->renderTargetPriv().getStencilBuffer());
    GrUniqueKey sbKey;

    int width = rt->width();
    int height = rt->height();
    if (this->caps()->oversizedStencilSupport()) {
        width  = SkNextPow2(width);
        height = SkNextPow2(height);
    }

    GrStencilBuffer::ComputeSharedStencilBufferKey(width, height, rt->numSamples(), &sbKey);
    SkAutoTUnref<GrStencilBuffer> sb(static_cast<GrStencilBuffer*>(
        this->getContext()->getResourceCache()->findAndRefUniqueResource(sbKey)));
    if (sb) {
        if (this->attachStencilBufferToRenderTarget(sb, rt)) {
            rt->renderTargetPriv().didAttachStencilBuffer(sb);
            return true;
        }
        return false;
    }
    if (this->createStencilBufferForRenderTarget(rt, width, height)) {
        GrStencilBuffer* sb = rt->renderTargetPriv().getStencilBuffer();
        sb->resourcePriv().setUniqueKey(sbKey);
        return true;
    } else {
        return false;
    }
}
示例#2
0
文件: GrGpu.cpp 项目: merckhung/libui
bool GrGpu::attachStencilBufferToRenderTarget(GrRenderTarget* rt) {
    SkASSERT(NULL == rt->renderTargetPriv().getStencilBuffer());
    GrUniqueKey sbKey;

    int width = rt->width();
    int height = rt->height();
    if (this->caps()->oversizedStencilSupport()) {
        width  = SkNextPow2(width);
        height = SkNextPow2(height);
    }

    GrStencilBuffer::ComputeSharedStencilBufferKey(width, height, rt->numSamples(), &sbKey);
    SkAutoTUnref<GrStencilBuffer> sb(static_cast<GrStencilBuffer*>(
        this->getContext()->getResourceCache()->findAndRefUniqueResource(sbKey)));
    if (sb) {
        if (this->attachStencilBufferToRenderTarget(sb, rt)) {
            rt->renderTargetPriv().didAttachStencilBuffer(sb);
            return true;
        }
        return false;
    }
    if (this->createStencilBufferForRenderTarget(rt, width, height)) {
        // Right now we're clearing the stencil buffer here after it is
        // attached to an RT for the first time. When we start matching
        // stencil buffers with smaller color targets this will no longer
        // be correct because it won't be guaranteed to clear the entire
        // sb.
        // We used to clear down in the GL subclass using a special purpose
        // FBO. But iOS doesn't allow a stencil-only FBO. It reports unsupported
        // FBO status.
        this->clearStencil(rt);
        GrStencilBuffer* sb = rt->renderTargetPriv().getStencilBuffer();
        sb->resourcePriv().setUniqueKey(sbKey);
        return true;
    } else {
        return false;
    }
}