Move draw on upload decision in GrGpu
BUG=skia:
Committed: https://skia.googlesource.com/skia/+/0341b4427e5f037e3b501ed6e57dfdb7b40f150e
Review URL: https://codereview.chromium.org/1257073003
diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp
index 728fb88..c61979b 100644
--- a/src/gpu/GrGpu.cpp
+++ b/src/gpu/GrGpu.cpp
@@ -232,6 +232,61 @@
this->onClearStencilClip(renderTarget, rect, insideClip);
}
+bool GrGpu::getReadPixelsInfo(GrSurface* srcSurface, int width, int height, size_t rowBytes,
+ GrPixelConfig readConfig, DrawPreference* drawPreference,
+ ReadPixelTempDrawInfo* tempDrawInfo) {
+ SkASSERT(drawPreference);
+ SkASSERT(tempDrawInfo);
+ SkASSERT(kGpuPrefersDraw_DrawPreference != *drawPreference);
+
+ if (!this->onGetReadPixelsInfo(srcSurface, width, height, rowBytes, readConfig, drawPreference,
+ tempDrawInfo)) {
+ return false;
+ }
+
+ // Check to see if we're going to request that the caller draw when drawing is not possible.
+ if (!srcSurface->asTexture() ||
+ !this->caps()->isConfigRenderable(tempDrawInfo->fTempSurfaceDesc.fConfig, false)) {
+ // If we don't have a fallback to a straight read then fail.
+ if (kRequireDraw_DrawPreference == *drawPreference) {
+ return false;
+ }
+ *drawPreference = kNoDraw_DrawPreference;
+ }
+
+ return true;
+}
+bool GrGpu::getWritePixelsInfo(GrSurface* dstSurface, int width, int height, size_t rowBytes,
+ GrPixelConfig srcConfig, DrawPreference* drawPreference,
+ WritePixelTempDrawInfo* tempDrawInfo) {
+ SkASSERT(drawPreference);
+ SkASSERT(tempDrawInfo);
+ SkASSERT(kGpuPrefersDraw_DrawPreference != *drawPreference);
+
+ if (this->caps()->useDrawInsteadOfPartialRenderTargetWrite() &&
+ SkToBool(dstSurface->asRenderTarget()) &&
+ (width < dstSurface->width() || height < dstSurface->height())) {
+ ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference);
+ }
+
+ if (!this->onGetWritePixelsInfo(dstSurface, width, height, rowBytes, srcConfig, drawPreference,
+ tempDrawInfo)) {
+ return false;
+ }
+
+ // Check to see if we're going to request that the caller draw when drawing is not possible.
+ if (!dstSurface->asRenderTarget() ||
+ !this->caps()->isConfigTexturable(tempDrawInfo->fTempSurfaceDesc.fConfig)) {
+ // If we don't have a fallback to a straight upload then fail.
+ if (kRequireDraw_DrawPreference == *drawPreference ||
+ !this->caps()->isConfigTexturable(srcConfig)) {
+ return false;
+ }
+ *drawPreference = kNoDraw_DrawPreference;
+ }
+ return true;
+}
+
bool GrGpu::readPixels(GrRenderTarget* target,
int left, int top, int width, int height,
GrPixelConfig config, void* buffer,