sk_sp<SkSurface> SkSurface::MakeFromBackendRenderTarget(GrContext* context, const GrBackendRenderTarget& backendRT, GrSurfaceOrigin origin, sk_sp<SkColorSpace> colorSpace, const SkSurfaceProps* props) { if (!context) { return nullptr; } if (!SkSurface_Gpu::Valid(context, backendRT.config(), colorSpace.get())) { return nullptr; } sk_sp<GrRenderTargetContext> rtc( context->contextPriv().makeBackendRenderTargetRenderTargetContext(backendRT, origin, std::move(colorSpace), props)); if (!rtc) { return nullptr; } sk_sp<SkGpuDevice> device(SkGpuDevice::Make(context, std::move(rtc), backendRT.width(), backendRT.height(), SkGpuDevice::kUninit_InitContents)); if (!device) { return nullptr; } return sk_make_sp<SkSurface_Gpu>(std::move(device)); }
sk_sp<GrRenderTarget> GrMockGpu::onWrapBackendRenderTarget(const GrBackendRenderTarget& rt) { GrSurfaceDesc desc; desc.fFlags = kRenderTarget_GrSurfaceFlag; desc.fWidth = rt.width(); desc.fHeight = rt.height(); GrMockRenderTargetInfo info; SkAssertResult(rt.getMockRenderTargetInfo(&info)); desc.fConfig = info.fConfig; return sk_sp<GrRenderTarget>( new GrMockRenderTarget(this, GrMockRenderTarget::kWrapped, desc, info)); }
sk_sp<SkSurface> SkSurface::MakeFromBackendRenderTarget(GrContext* context, const GrBackendRenderTarget& rt, GrSurfaceOrigin origin, SkColorType colorType, sk_sp<SkColorSpace> colorSpace, const SkSurfaceProps* props) { if (!context) { return nullptr; } GrBackendRenderTarget rtCopy = rt; if (!validate_backend_render_target(context, rtCopy, &rtCopy.fConfig, colorType, colorSpace)) { return nullptr; } if (!SkSurface_Gpu::Valid(context, rtCopy.config(), colorSpace.get())) { return nullptr; } if (!context) { return nullptr; } sk_sp<GrRenderTargetContext> rtc( context->contextPriv().makeBackendRenderTargetRenderTargetContext( rtCopy, origin, std::move(colorSpace), props)); if (!rtc) { return nullptr; } sk_sp<SkGpuDevice> device(SkGpuDevice::Make(context, std::move(rtc), rtCopy.width(), rtCopy.height(), SkGpuDevice::kUninit_InitContents)); if (!device) { return nullptr; } return sk_make_sp<SkSurface_Gpu>(std::move(device)); }