当前位置: 首页>>代码示例>>C++>>正文


C++ SkAutoTUnref::asRenderTarget方法代码示例

本文整理汇总了C++中SkAutoTUnref::asRenderTarget方法的典型用法代码示例。如果您正苦于以下问题:C++ SkAutoTUnref::asRenderTarget方法的具体用法?C++ SkAutoTUnref::asRenderTarget怎么用?C++ SkAutoTUnref::asRenderTarget使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SkAutoTUnref的用法示例。


在下文中一共展示了SkAutoTUnref::asRenderTarget方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: setupCanvas

SkCanvas* PictureRenderer::setupCanvas(int width, int height) {
    SkAutoTUnref<SkCanvas> canvas;

    switch(fDeviceType) {
        case kBitmap_DeviceType: {
            SkBitmap bitmap;
            sk_tools::setup_bitmap(&bitmap, width, height);
            canvas.reset(SkNEW_ARGS(SkCanvas, (bitmap)));
        }
        break;
#if SK_SUPPORT_GPU
#if SK_ANGLE
        case kAngle_DeviceType:
            // fall through
#endif
#if SK_MESA
        case kMesa_DeviceType:
            // fall through
#endif
        case kGPU_DeviceType:
        case kNVPR_DeviceType: {
            SkAutoTUnref<GrSurface> target;
            if (fGrContext) {
                // create a render target to back the device
                GrSurfaceDesc desc;
                desc.fConfig = kSkia8888_GrPixelConfig;
                desc.fFlags = kRenderTarget_GrSurfaceFlag;
                desc.fWidth = width;
                desc.fHeight = height;
                desc.fSampleCnt = fSampleCount;
                target.reset(fGrContext->textureProvider()->createTexture(desc, false, NULL, 0));
            }

            uint32_t flags = fUseDFText ? SkSurfaceProps::kUseDistanceFieldFonts_Flag : 0;
            SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType);
            SkAutoTUnref<SkGpuDevice> device(
                SkGpuDevice::Create(target->asRenderTarget(), &props,
                                    SkGpuDevice::kUninit_InitContents));
            if (!device) {
                return NULL;
            }
            canvas.reset(SkNEW_ARGS(SkCanvas, (device)));
            break;
        }
#endif
        default:
            SkASSERT(0);
            return NULL;
    }

    if (fHasDrawFilters) {
        if (fDrawFilters[0] & PictureRenderer::kAAClip_DrawFilterFlag) {
            canvas->setAllowSoftClip(false);
        }

        canvas.reset(SkNEW_ARGS(FlagsFilterCanvas, (canvas.get(), fDrawFilters)));
    }

    this->scaleToScaleFactor(canvas);

    // Pictures often lie about their extent (i.e., claim to be 100x100 but
    // only ever draw to 90x100). Clear here so the undrawn portion will have
    // a consistent color
    canvas->clear(SK_ColorTRANSPARENT);
    return canvas.detach();
}
开发者ID:mariospr,项目名称:chromium-browser,代码行数:66,代码来源:PictureRenderer.cpp

示例2: GrTextureToYUVPlanes

bool GrTextureToYUVPlanes(GrTexture* texture, const SkISize sizes[3], void* const planes[3],
                          const size_t rowBytes[3], SkYUVColorSpace colorSpace) {
    if (GrContext* context = texture->getContext()) {
        // Depending on the relative sizes of the y, u, and v planes we may do 1 to 3 draws/
        // readbacks.
        SkAutoTUnref<GrTexture> yuvTex;
        SkAutoTUnref<GrTexture> yTex;
        SkAutoTUnref<GrTexture> uvTex;
        SkAutoTUnref<GrTexture> uTex;
        SkAutoTUnref<GrTexture> vTex;

        GrPixelConfig singleChannelPixelConfig;
        if (context->caps()->isConfigRenderable(kAlpha_8_GrPixelConfig, false)) {
            singleChannelPixelConfig = kAlpha_8_GrPixelConfig;
        } else {
            singleChannelPixelConfig = kRGBA_8888_GrPixelConfig;
        }

        // We issue draw(s) to convert from RGBA to Y, U, and V. All three planes may have different
        // sizes however we optimize for two other cases - all planes are the same (1 draw to YUV),
        // and U and V are the same but Y differs (2 draws, one for Y, one for UV).
        if (sizes[0] == sizes[1] && sizes[1] == sizes[2]) {
            GrSurfaceDesc yuvDesc;
            yuvDesc.fConfig = kRGBA_8888_GrPixelConfig;
            yuvDesc.fFlags = kRenderTarget_GrSurfaceFlag;
            yuvDesc.fWidth = sizes[0].fWidth;
            yuvDesc.fHeight = sizes[0].fHeight;
            yuvTex.reset(context->textureProvider()->createApproxTexture(yuvDesc));
            if (!yuvTex) {
                return false;
            }
        } else {
            GrSurfaceDesc yDesc;
            yDesc.fConfig = singleChannelPixelConfig;
            yDesc.fFlags = kRenderTarget_GrSurfaceFlag;
            yDesc.fWidth = sizes[0].fWidth;
            yDesc.fHeight = sizes[0].fHeight;
            yTex.reset(context->textureProvider()->createApproxTexture(yDesc));
            if (!yTex) {
                return false;
            }
            if (sizes[1] == sizes[2]) {
                GrSurfaceDesc uvDesc;
                // TODO: Add support for GL_RG when available.
                uvDesc.fConfig = kRGBA_8888_GrPixelConfig;
                uvDesc.fFlags = kRenderTarget_GrSurfaceFlag;
                uvDesc.fWidth = sizes[1].fWidth;
                uvDesc.fHeight = sizes[1].fHeight;
                uvTex.reset(context->textureProvider()->createApproxTexture(uvDesc));
                if (!uvTex) {
                    return false;
                }
            } else {
                GrSurfaceDesc uvDesc;
                uvDesc.fConfig = singleChannelPixelConfig;
                uvDesc.fFlags = kRenderTarget_GrSurfaceFlag;
                uvDesc.fWidth = sizes[1].fWidth;
                uvDesc.fHeight = sizes[1].fHeight;
                uTex.reset(context->textureProvider()->createApproxTexture(uvDesc));
                uvDesc.fWidth = sizes[2].fWidth;
                uvDesc.fHeight = sizes[2].fHeight;
                vTex.reset(context->textureProvider()->createApproxTexture(uvDesc));
                if (!uTex || !vTex) {
                    return false;
                }
            }
        }

        // Do all the draws before any readback.
        if (yuvTex) {
            SkAutoTUnref<GrDrawContext> dc(context->drawContext(yuvTex->asRenderTarget()));
            if (!dc) {
                return false;
            }
            if (!convert_texture(texture, dc, sizes[0].fWidth, sizes[0].fHeight, colorSpace,
                                 GrYUVEffect::CreateRGBToYUV)) {
                return false;
            }

        } else {
            SkASSERT(yTex);
            SkAutoTUnref<GrDrawContext> dc(context->drawContext(yTex->asRenderTarget()));
            if (!dc) {
                return false;
            }
            if (!convert_texture(texture, dc, sizes[0].fWidth, sizes[0].fHeight, colorSpace,
                                 GrYUVEffect::CreateRGBToY)) {
                return false;
            }
            if (uvTex) {
                dc.reset(context->drawContext(uvTex->asRenderTarget()));
                if (!dc) {
                    return false;
                }
                if (!convert_texture(texture, dc, sizes[1].fWidth, sizes[1].fHeight,
                                     colorSpace,  GrYUVEffect::CreateRGBToUV)) {
                    return false;
                }
            } else {
                SkASSERT(uTex && vTex);
//.........这里部分代码省略.........
开发者ID:BertiKarsunke,项目名称:skia,代码行数:101,代码来源:GrTextureToYUVPlanes.cpp


注:本文中的SkAutoTUnref::asRenderTarget方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。