Refactor drawContext/RenderTarget creation
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1914883002
Committed: https://skia.googlesource.com/skia/+/2f1c42e8448bbbadeb3df1c626faa90aa33f8907
Review-Url: https://codereview.chromium.org/1914883002
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 5ebb2e9..a186bd8 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -615,6 +615,37 @@
return fDrawingManager->drawContext(std::move(rt), surfaceProps);
}
+sk_sp<GrDrawContext> GrContext::newDrawContext(BackingFit fit,
+ int width, int height,
+ GrPixelConfig config,
+ int sampleCnt,
+ GrSurfaceOrigin origin) {
+ GrSurfaceDesc desc;
+ desc.fFlags = kRenderTarget_GrSurfaceFlag;
+ desc.fOrigin = origin;
+ desc.fWidth = width;
+ desc.fHeight = height;
+ desc.fConfig = config;
+ desc.fSampleCnt = sampleCnt;
+
+ sk_sp<GrTexture> tex;
+ if (kTight_BackingFit == fit) {
+ tex.reset(this->textureProvider()->createTexture(desc, SkBudgeted::kYes));
+ } else {
+ tex.reset(this->textureProvider()->createApproxTexture(desc));
+ }
+ if (!tex) {
+ return nullptr;
+ }
+
+ sk_sp<GrDrawContext> drawContext(this->drawContext(sk_ref_sp(tex->asRenderTarget())));
+ if (!drawContext) {
+ return nullptr;
+ }
+
+ return drawContext;
+}
+
bool GrContext::abandoned() const {
ASSERT_SINGLE_OWNER
return fDrawingManager->abandoned();