Retract GrRenderTarget a bit within SkGpuDevice
Split off of: https://codereview.chromium.org/1930013002/ ((Mostly) Retract GrRenderTarget from SkGpuDevice)
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1956473002
Committed: https://skia.googlesource.com/skia/+/d215a95882485026d176a81bf58871276b21c89c
Review-Url: https://codereview.chromium.org/1956473002
diff --git a/include/gpu/GrDrawContext.h b/include/gpu/GrDrawContext.h
index 04b03d4..1ffa987 100644
--- a/include/gpu/GrDrawContext.h
+++ b/include/gpu/GrDrawContext.h
@@ -258,6 +258,7 @@
*/
void drawBatch(const GrClip&, const GrPaint&, GrDrawBatch*);
+ const GrSurfaceDesc& desc() const { return fRenderTarget->desc(); }
int width() const { return fRenderTarget->width(); }
int height() const { return fRenderTarget->height(); }
int numColorSamples() const { return fRenderTarget->numColorSamples(); }
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index a5af472..5206c63 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -740,13 +740,13 @@
// Given a bitmap, an optional src rect, and a context with a clip and matrix determine what
// pixels from the bitmap are necessary.
-static void determine_clipped_src_rect(const GrRenderTarget* rt,
+static void determine_clipped_src_rect(int width, int height,
const GrClip& clip,
const SkMatrix& viewMatrix,
const SkISize& imageSize,
const SkRect* srcRectPtr,
SkIRect* clippedSrcIRect) {
- clip.getConservativeBounds(rt->width(), rt->height(), clippedSrcIRect, nullptr);
+ clip.getConservativeBounds(width, height, clippedSrcIRect, nullptr);
SkMatrix inv;
if (!viewMatrix.invert(&inv)) {
clippedSrcIRect->setEmpty();
@@ -779,7 +779,8 @@
ASSERT_SINGLE_OWNER
// if it's larger than the max tile size, then we have no choice but tiling.
if (imageRect.width() > maxTileSize || imageRect.height() > maxTileSize) {
- determine_clipped_src_rect(fRenderTarget, fClip, viewMatrix, imageRect.size(),
+ determine_clipped_src_rect(fDrawContext->width(), fDrawContext->height(),
+ fClip, viewMatrix, imageRect.size(),
srcRectPtr, clippedSubset);
*tileSize = determine_tile_size(*clippedSubset, maxTileSize);
return true;
@@ -807,7 +808,8 @@
// Figure out how much of the src we will need based on the src rect and clipping. Reject if
// tiling memory savings would be < 50%.
- determine_clipped_src_rect(fRenderTarget, fClip, viewMatrix, imageRect.size(), srcRectPtr,
+ determine_clipped_src_rect(fDrawContext->width(), fDrawContext->height(),
+ fClip, viewMatrix, imageRect.size(), srcRectPtr,
clippedSubset);
*tileSize = kBmpSmallTileSize; // already know whole bitmap fits in one max sized tile.
size_t usedTileBytes = get_tile_count(*clippedSubset, kBmpSmallTileSize) *
@@ -1769,7 +1771,7 @@
ASSERT_SINGLE_OWNER
// TODO: Change the signature of newSurface to take a budgeted parameter.
static const SkBudgeted kBudgeted = SkBudgeted::kNo;
- return SkSurface::MakeRenderTarget(fContext, kBudgeted, info, fRenderTarget->desc().fSampleCnt,
+ return SkSurface::MakeRenderTarget(fContext, kBudgeted, info, fDrawContext->desc().fSampleCnt,
&props);
}
@@ -1814,7 +1816,7 @@
initialMatrix,
clipBounds,
&atlasedNeedRendering, &atlasedRecycled,
- fRenderTarget->numColorSamples());
+ fDrawContext->numColorSamples());
GrLayerHoister::DrawLayersToAtlas(fContext, atlasedNeedRendering);
@@ -1826,7 +1828,7 @@
initialMatrix,
clipBounds,
&needRendering, &recycled,
- fRenderTarget->numColorSamples());
+ fDrawContext->numColorSamples());
GrLayerHoister::DrawLayers(fContext, needRendering);
diff --git a/src/image/SkSurface_Gpu.cpp b/src/image/SkSurface_Gpu.cpp
index 110d614..1e4bd87 100644
--- a/src/image/SkSurface_Gpu.cpp
+++ b/src/image/SkSurface_Gpu.cpp
@@ -68,8 +68,7 @@
}
sk_sp<SkSurface> SkSurface_Gpu::onNewSurface(const SkImageInfo& info) {
- GrRenderTarget* rt = fDevice->accessRenderTarget();
- int sampleCount = rt->numColorSamples();
+ int sampleCount = fDevice->accessDrawContext()->numColorSamples();
// TODO: Make caller specify this (change virtual signature of onNewSurface).
static const SkBudgeted kBudgeted = SkBudgeted::kNo;
return SkSurface::MakeRenderTarget(fDevice->context(), kBudgeted, info, sampleCount,
@@ -85,7 +84,7 @@
// want to ever retarget the SkSurface at another buffer we create. Force a copy now to avoid
// copy-on-write.
if (kYes_ForceCopyMode == forceCopyMode || !tex || rt->resourcePriv().refsWrappedObjects()) {
- GrSurfaceDesc desc = fDevice->accessRenderTarget()->desc();
+ GrSurfaceDesc desc = fDevice->accessDrawContext()->desc();
GrContext* ctx = fDevice->context();
desc.fFlags = desc.fFlags & ~kRenderTarget_GrSurfaceFlag;
copy.reset(ctx->textureProvider()->createTexture(desc, budgeted));