aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/image
diff options
context:
space:
mode:
authorGravatar Robert Phillips <robertphillips@google.com>2018-04-05 09:30:38 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-04-05 14:21:07 +0000
commit8caf85f9f40f6bad38bf66bd02b87dcebe139a5c (patch)
tree46a2b1414601ca99f6c60bd3442e8075bc27173f /src/image
parent91749c82523c8b0b3f2b6f800d85893ca5386fbd (diff)
Add GrBackendTexture/RenderTarget accessors to SkSurface
Change-Id: I63477fd4b8d48dc50af72736f0f8df566cd96d4a Reviewed-on: https://skia-review.googlesource.com/85220 Reviewed-by: Brian Salomon <bsalomon@google.com> Reviewed-by: Cary Clark <caryclark@skia.org> Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'src/image')
-rw-r--r--src/image/SkImage.cpp6
-rw-r--r--src/image/SkImage_Base.h15
-rw-r--r--src/image/SkSurface.cpp26
-rw-r--r--src/image/SkSurface_Base.h3
-rw-r--r--src/image/SkSurface_Gpu.cpp21
-rw-r--r--src/image/SkSurface_Gpu.h4
6 files changed, 60 insertions, 15 deletions
diff --git a/src/image/SkImage.cpp b/src/image/SkImage.cpp
index 6c586c4466..fa04d99229 100644
--- a/src/image/SkImage.cpp
+++ b/src/image/SkImage.cpp
@@ -29,6 +29,7 @@
#include "GrContext.h"
#include "SkImage_Gpu.h"
#endif
+#include "GrBackendSurface.h"
SkImage::SkImage(int width, int height, uint32_t uniqueID)
: fWidth(width)
@@ -218,6 +219,11 @@ SkImage_Base::~SkImage_Base() {
}
}
+GrBackendTexture SkImage_Base::onGetBackendTexture(bool flushPendingGrContextIO,
+ GrSurfaceOrigin* origin) const {
+ return GrBackendTexture(); // invalid
+}
+
bool SkImage::readPixels(const SkPixmap& pmap, int srcX, int srcY, CachingHint chint) const {
return this->readPixels(pmap.info(), pmap.writable_addr(), pmap.rowBytes(), srcX, srcY, chint);
}
diff --git a/src/image/SkImage_Base.h b/src/image/SkImage_Base.h
index 950163a079..191cf0354e 100644
--- a/src/image/SkImage_Base.h
+++ b/src/image/SkImage_Base.h
@@ -13,17 +13,9 @@
#include "SkSurface.h"
#if SK_SUPPORT_GPU
- #include "GrBackendSurface.h"
#include "GrTextureProxy.h"
class GrTexture;
-#else
-class SK_API GrBackendTexture {
-public:
- GrBackendTexture() {}
-
- bool isValid() const { return false; }
-};
#endif
#include <new>
@@ -67,13 +59,12 @@ public:
GrSurfaceOrigin* origin) const {
return 0;
}
- virtual GrBackendTexture onGetBackendTexture(bool flushPendingGrContextIO,
- GrSurfaceOrigin* origin) const {
- return GrBackendTexture(); // invalid
- }
virtual GrTexture* onGetTexture() const { return nullptr; }
#endif
+ virtual GrBackendTexture onGetBackendTexture(bool flushPendingGrContextIO,
+ GrSurfaceOrigin* origin) const;
+
virtual SkImageCacherator* peekCacherator() const { return nullptr; }
// return a read-only copy of the pixels. We promise to not modify them,
diff --git a/src/image/SkSurface.cpp b/src/image/SkSurface.cpp
index 9444de7724..41bed215f5 100644
--- a/src/image/SkSurface.cpp
+++ b/src/image/SkSurface.cpp
@@ -6,11 +6,13 @@
*/
#include "SkAtomics.h"
-#include "SkSurface_Base.h"
-#include "SkImagePriv.h"
#include "SkCanvas.h"
-
#include "SkFontLCDConfig.h"
+#include "SkImagePriv.h"
+#include "SkSurface_Base.h"
+
+#include "GrBackendSurface.h"
+
static SkPixelGeometry compute_default_geometry() {
SkFontLCDConfig::LCDOrder order = SkFontLCDConfig::GetSubpixelOrder();
if (SkFontLCDConfig::kNONE_LCDOrder == order) {
@@ -70,6 +72,14 @@ SkSurface_Base::~SkSurface_Base() {
}
}
+GrBackendTexture SkSurface_Base::onGetBackendTexture(BackendHandleAccess) {
+ return GrBackendTexture(); // invalid
+}
+
+GrBackendRenderTarget SkSurface_Base::onGetBackendRenderTarget(BackendHandleAccess) {
+ return GrBackendRenderTarget(); // invalid
+}
+
void SkSurface_Base::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint) {
auto image = this->makeImageSnapshot();
if (image) {
@@ -216,6 +226,16 @@ bool SkSurface::getRenderTargetHandle(GrBackendObject* obj, BackendHandleAccess
return asSB(this)->onGetRenderTargetHandle(obj, access);
}
+#if GR_TEST_UTILS
+GrBackendTexture SkSurface::getBackendTexture(BackendHandleAccess access) {
+ return asSB(this)->onGetBackendTexture(access);
+}
+
+GrBackendRenderTarget SkSurface::getBackendRenderTarget(BackendHandleAccess access) {
+ return asSB(this)->onGetBackendRenderTarget(access);
+}
+#endif
+
void SkSurface::prepareForExternalIO() {
this->flush();
}
diff --git a/src/image/SkSurface_Base.h b/src/image/SkSurface_Base.h
index 56a09cf5e6..2771d5ff16 100644
--- a/src/image/SkSurface_Base.h
+++ b/src/image/SkSurface_Base.h
@@ -27,6 +27,9 @@ public:
return false;
}
+ virtual GrBackendTexture onGetBackendTexture(BackendHandleAccess);
+ virtual GrBackendRenderTarget onGetBackendRenderTarget(BackendHandleAccess);
+
/**
* Allocate a canvas that will draw into this surface. We will cache this
* canvas, to return the same object to the caller multiple times. We
diff --git a/src/image/SkSurface_Gpu.cpp b/src/image/SkSurface_Gpu.cpp
index d7a7018f57..b4a5aeed1c 100644
--- a/src/image/SkSurface_Gpu.cpp
+++ b/src/image/SkSurface_Gpu.cpp
@@ -72,6 +72,27 @@ bool SkSurface_Gpu::onGetRenderTargetHandle(GrBackendObject* obj, BackendHandleA
return true;
}
+GrBackendTexture SkSurface_Gpu::onGetBackendTexture(BackendHandleAccess access) {
+ GrRenderTarget* rt = prepare_rt_for_external_access(this, access);
+ if (!rt) {
+ return GrBackendTexture(); // invalid
+ }
+ GrTexture* texture = rt->asTexture();
+ if (texture) {
+ return texture->getBackendTexture();
+ }
+ return GrBackendTexture(); // invalid
+}
+
+GrBackendRenderTarget SkSurface_Gpu::onGetBackendRenderTarget(BackendHandleAccess access) {
+ GrRenderTarget* rt = prepare_rt_for_external_access(this, access);
+ if (!rt) {
+ return GrBackendRenderTarget(); // invalid
+ }
+
+ return rt->getBackendRenderTarget();
+}
+
SkCanvas* SkSurface_Gpu::onNewCanvas() {
SkCanvas::InitFlags flags = SkCanvas::kDefault_InitFlags;
flags = static_cast<SkCanvas::InitFlags>(flags | SkCanvas::kConservativeRasterClip_InitFlag);
diff --git a/src/image/SkSurface_Gpu.h b/src/image/SkSurface_Gpu.h
index c23da72248..ecb84a8c00 100644
--- a/src/image/SkSurface_Gpu.h
+++ b/src/image/SkSurface_Gpu.h
@@ -25,6 +25,10 @@ public:
GrBackendObject onGetTextureHandle(BackendHandleAccess) override;
bool onGetRenderTargetHandle(GrBackendObject*, BackendHandleAccess) override;
+
+ GrBackendTexture onGetBackendTexture(BackendHandleAccess) override;
+ GrBackendRenderTarget onGetBackendRenderTarget(BackendHandleAccess) override;
+
SkCanvas* onNewCanvas() override;
sk_sp<SkSurface> onNewSurface(const SkImageInfo&) override;
sk_sp<SkImage> onNewImageSnapshot() override;