sk_sp<SkSurface> SkSurface::MakeFromBackendTexture(GrContext* context, const GrBackendTexture& tex, GrSurfaceOrigin origin, int sampleCnt, SkColorType colorType, sk_sp<SkColorSpace> colorSpace, const SkSurfaceProps* props) { if (!context) { return nullptr; } sampleCnt = SkTMax(1, sampleCnt); GrBackendTexture texCopy = tex; if (!validate_backend_texture(context, texCopy, &texCopy.fConfig, sampleCnt, colorType, colorSpace, true)) { return nullptr; } return MakeFromBackendTexture(context, texCopy, origin, sampleCnt, colorSpace, props); }
sk_sp<SkSurface> SkSurface::MakeFromBackendTexture(GrContext* context, const GrBackendTexture& tex, GrSurfaceOrigin origin, int sampleCnt, SkColorType colorType, sk_sp<SkColorSpace> colorSpace, const SkSurfaceProps* props) { if (!context) { return nullptr; } sampleCnt = SkTMax(1, sampleCnt); GrBackendTexture texCopy = tex; if (!validate_backend_texture(context, texCopy, &texCopy.fConfig, sampleCnt, colorType, colorSpace, true)) { return nullptr; } if (!context) { return nullptr; } if (!SkSurface_Gpu::Valid(context, texCopy.config(), colorSpace.get())) { return nullptr; } sampleCnt = SkTMax(1, sampleCnt); sk_sp<GrRenderTargetContext> rtc(context->contextPriv().makeBackendTextureRenderTargetContext( texCopy, origin, sampleCnt, std::move(colorSpace), props)); if (!rtc) { return nullptr; } sk_sp<SkGpuDevice> device(SkGpuDevice::Make(context, std::move(rtc), texCopy.width(), texCopy.height(), SkGpuDevice::kUninit_InitContents)); if (!device) { return nullptr; } return sk_make_sp<SkSurface_Gpu>(std::move(device)); }