Remove SkImage_Base::peekProxy.
This is the only place we provide a proxy from a SkImage other than
asView() and is only used in one place in the library. Add a utility
function to replace uses in tests based on asView().
Bug: skia:11208
Change-Id: Ica6eae6e5f153f208523331566acc0360925a20e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/373617
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
diff --git a/tools/gpu/ProxyUtils.cpp b/tools/gpu/ProxyUtils.cpp
index 7c65774..bf1d7b3 100644
--- a/tools/gpu/ProxyUtils.cpp
+++ b/tools/gpu/ProxyUtils.cpp
@@ -10,18 +10,45 @@
#include "include/core/SkColor.h"
#include "include/gpu/GrBackendSurface.h"
#include "include/gpu/GrDirectContext.h"
+#include "include/private/GrImageContext.h"
#include "src/gpu/GrDirectContextPriv.h"
#include "src/gpu/GrDrawingManager.h"
#include "src/gpu/GrGpu.h"
+#include "src/gpu/GrImageContextPriv.h"
#include "src/gpu/GrPixmap.h"
#include "src/gpu/GrProgramInfo.h"
#include "src/gpu/GrProxyProvider.h"
#include "src/gpu/GrSurfaceContext.h"
#include "src/gpu/SkGr.h"
#include "src/gpu/ops/GrSimpleMeshDrawOpHelper.h"
+#include "src/image/SkImage_Base.h"
namespace sk_gpu_test {
+GrTextureProxy* GetTextureImageProxy(SkImage* image, GrRecordingContext* rContext) {
+ if (!image->isTextureBacked() || as_IB(image)->isYUVA()) {
+ return nullptr;
+ }
+ if (!rContext) {
+ // If the image is backed by a recording context we'll use that.
+ GrImageContext* iContext = as_IB(image)->context();
+ SkASSERT(iContext);
+ rContext = iContext->priv().asRecordingContext();
+ if (!rContext) {
+ return nullptr;
+ }
+ }
+ auto [view, ct] = as_IB(image)->asView(rContext, GrMipmapped::kNo);
+ if (!view) {
+ // With the above checks we expect this to succeed unless there is a context mismatch.
+ SkASSERT(!image->isValid(rContext));
+ return nullptr;
+ }
+ GrSurfaceProxy* proxy = view.proxy();
+ SkASSERT(proxy->asTextureProxy());
+ return proxy->asTextureProxy();
+}
+
GrSurfaceProxyView MakeTextureProxyViewFromData(GrDirectContext* dContext,
GrRenderable renderable,
GrSurfaceOrigin origin,