Migrate texture update methods to GrDirectContext
Cut & paste job, but I did replace some cases of just calling
inherited implementations with using-statements. There are
other methods on this class that are using-statements and
that pattern is cleaner.
Change-Id: Ie369c643e44bdb8f82dfffcf45c1f65d48606899
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/325660
Reviewed-by: Brian Salomon <bsalomon@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
Auto-Submit: Adlai Holler <adlai@google.com>
diff --git a/src/gpu/GrDirectContext.cpp b/src/gpu/GrDirectContext.cpp
index ac5722a..eec6059 100644
--- a/src/gpu/GrDirectContext.cpp
+++ b/src/gpu/GrDirectContext.cpp
@@ -602,6 +602,81 @@
std::move(finishedCallback), &data);
}
+bool GrDirectContext::updateBackendTexture(const GrBackendTexture& backendTexture,
+ const SkColor4f& color,
+ GrGpuFinishedProc finishedProc,
+ GrGpuFinishedContext finishedContext) {
+ sk_sp<GrRefCntedCallback> finishedCallback;
+ if (finishedProc) {
+ finishedCallback.reset(new GrRefCntedCallback(finishedProc, finishedContext));
+ }
+
+ if (this->abandoned()) {
+ return false;
+ }
+
+ GrGpu::BackendTextureData data(color);
+ return fGpu->updateBackendTexture(backendTexture, std::move(finishedCallback), &data);
+}
+
+bool GrDirectContext::updateBackendTexture(const GrBackendTexture& backendTexture,
+ SkColorType skColorType,
+ const SkColor4f& color,
+ GrGpuFinishedProc finishedProc,
+ GrGpuFinishedContext finishedContext) {
+ sk_sp<GrRefCntedCallback> finishedCallback;
+ if (finishedProc) {
+ finishedCallback.reset(new GrRefCntedCallback(finishedProc, finishedContext));
+ }
+
+ if (this->abandoned()) {
+ return false;
+ }
+
+ GrBackendFormat format = backendTexture.getBackendFormat();
+ GrColorType grColorType = SkColorTypeAndFormatToGrColorType(this->caps(), skColorType, format);
+
+ if (!this->caps()->areColorTypeAndFormatCompatible(grColorType, format)) {
+ return false;
+ }
+
+ GrSwizzle swizzle = this->caps()->getWriteSwizzle(format, grColorType);
+ GrGpu::BackendTextureData data(swizzle.applyTo(color));
+
+ return fGpu->updateBackendTexture(backendTexture, std::move(finishedCallback), &data);
+}
+
+bool GrDirectContext::updateBackendTexture(const GrBackendTexture& backendTexture,
+ const SkPixmap srcData[],
+ int numLevels,
+ GrGpuFinishedProc finishedProc,
+ GrGpuFinishedContext finishedContext) {
+ sk_sp<GrRefCntedCallback> finishedCallback;
+ if (finishedProc) {
+ finishedCallback.reset(new GrRefCntedCallback(finishedProc, finishedContext));
+ }
+
+ if (this->abandoned()) {
+ return false;
+ }
+
+ if (!srcData || numLevels <= 0) {
+ return false;
+ }
+
+ int numExpectedLevels = 1;
+ if (backendTexture.hasMipmaps()) {
+ numExpectedLevels = SkMipmap::ComputeLevelCount(backendTexture.width(),
+ backendTexture.height()) + 1;
+ }
+ if (numLevels != numExpectedLevels) {
+ return false;
+ }
+
+ GrGpu::BackendTextureData data(srcData);
+ return fGpu->updateBackendTexture(backendTexture, std::move(finishedCallback), &data);
+}
+
#ifdef SK_GL
/*************************************************************************************************/