sk_sp<GrTexture> GrMockGpu::onWrapBackendTexture(const GrBackendTexture& tex, GrWrapOwnership ownership, GrWrapCacheable wrapType, GrIOType ioType) { GrSurfaceDesc desc; desc.fWidth = tex.width(); desc.fHeight = tex.height(); GrMockTextureInfo info; SkAssertResult(tex.getMockTextureInfo(&info)); desc.fConfig = info.fConfig; GrMipMapsStatus mipMapsStatus = tex.hasMipMaps() ? GrMipMapsStatus::kValid : GrMipMapsStatus::kNotAllocated; return sk_sp<GrTexture>(new GrMockTexture(this, desc, mipMapsStatus, info, wrapType, ioType)); }
sk_sp<GrTexture> GrGpu::wrapBackendTexture(const GrBackendTexture& backendTex, GrWrapOwnership ownership) { this->handleDirtyContext(); if (!this->caps()->isConfigTexturable(backendTex.config())) { return nullptr; } if (backendTex.width() > this->caps()->maxTextureSize() || backendTex.height() > this->caps()->maxTextureSize()) { return nullptr; } sk_sp<GrTexture> tex = this->onWrapBackendTexture(backendTex, ownership); if (tex && !backendTex.hasMipMaps()) { // Ganesh will not ever allocate mipmaps for a wrapped resource. By setting this flag here, // it will be propagated to any proxy that wraps this texture. tex->texturePriv().setDoesNotSupportMipMaps(); } return tex; }
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReimportImageTextureWithMipLevels, reporter, ctxInfo) { auto* ctx = ctxInfo.grContext(); if (!ctx->priv().caps()->mipMapSupport()) { return; } static constexpr auto kCreateWithMipMaps = true; auto surf = SkSurface::MakeRenderTarget( ctx, SkBudgeted::kYes, SkImageInfo::Make(100, 100, kRGBA_8888_SkColorType, kPremul_SkAlphaType), 1, kTopLeft_GrSurfaceOrigin, nullptr, kCreateWithMipMaps); if (!surf) { return; } surf->getCanvas()->drawColor(SK_ColorDKGRAY); auto img = surf->makeImageSnapshot(); if (!img) { return; } surf.reset(); GrBackendTexture btex; SkImage::BackendTextureReleaseProc texRelease; if (!SkImage::MakeBackendTextureFromSkImage(ctx, std::move(img), &btex, &texRelease)) { // Not all backends support stealing textures yet. // ERRORF(reporter, "Could not turn image into texture"); return; } REPORTER_ASSERT(reporter, btex.hasMipMaps()); // Reimport the texture as an image and perform a downsampling draw with medium quality which // should use the upper MIP levels. img = SkImage::MakeFromTexture(ctx, btex, kTopLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr); const auto singlePixelInfo = SkImageInfo::Make(1, 1, kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr); surf = SkSurface::MakeRenderTarget(ctx, SkBudgeted::kYes, singlePixelInfo, 1, kTopLeft_GrSurfaceOrigin, nullptr); SkPaint paint; paint.setFilterQuality(kMedium_SkFilterQuality); surf->getCanvas()->drawImageRect(img, SkRect::MakeWH(1, 1), &paint); uint32_t pixel; surf->readPixels(singlePixelInfo, &pixel, sizeof(uint32_t), 0, 0); REPORTER_ASSERT(reporter, pixel == SkPreMultiplyColor(SK_ColorDKGRAY)); img.reset(); texRelease(btex); }
sk_sp<GrTexture> GrMockGpu::onWrapRenderableBackendTexture(const GrBackendTexture& tex, int sampleCnt, GrWrapOwnership ownership) { GrSurfaceDesc desc; desc.fFlags = kRenderTarget_GrSurfaceFlag; desc.fWidth = tex.width(); desc.fHeight = tex.height(); GrMockTextureInfo texInfo; SkAssertResult(tex.getMockTextureInfo(&texInfo)); desc.fConfig = texInfo.fConfig; GrMipMapsStatus mipMapsStatus = tex.hasMipMaps() ? GrMipMapsStatus::kValid : GrMipMapsStatus::kNotAllocated; GrMockRenderTargetInfo rtInfo; rtInfo.fConfig = texInfo.fConfig; // The client gave us the texture ID but we supply the render target ID. rtInfo.fID = NextInternalRenderTargetID(); return sk_sp<GrTexture>( new GrMockTextureRenderTarget(this, desc, mipMapsStatus, texInfo, rtInfo)); }
sk_sp<GrTexture> GrGpu::wrapRenderableBackendTexture(const GrBackendTexture& backendTex, int sampleCnt, GrWrapOwnership ownership) { this->handleDirtyContext(); if (sampleCnt < 1) { return nullptr; } if (!this->caps()->isConfigTexturable(backendTex.config()) || !this->caps()->getRenderTargetSampleCount(sampleCnt, backendTex.config())) { return nullptr; } if (backendTex.width() > this->caps()->maxRenderTargetSize() || backendTex.height() > this->caps()->maxRenderTargetSize()) { return nullptr; } sk_sp<GrTexture> tex = this->onWrapRenderableBackendTexture(backendTex, sampleCnt, ownership); if (tex && !backendTex.hasMipMaps()) { // Ganesh will not ever allocate mipmaps for a wrapped resource. By setting this flag here, // it will be propagated to any proxy that wraps this texture. tex->texturePriv().setDoesNotSupportMipMaps(); } SkASSERT(!tex || tex->asRenderTarget()); return tex; }