aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Robert Phillips <robertphillips@google.com>2017-11-16 14:59:48 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-11-17 12:53:55 +0000
commit57e0828fade9270f1fd3abf32f4e27b108c4bc1a (patch)
tree36cd92d54369d52c615d9071cc0f6f57eb5e27f5
parentecd62a6cf65ad2a3dcdad8decbe8677f5a74e02a (diff)
Add backend GPU objects to fiddle app
TBR=bsalomon@google.com Change-Id: I8876a4657f837436322150925233e0f36c91e8f0 Reviewed-on: https://skia-review.googlesource.com/72641 Commit-Queue: Robert Phillips <robertphillips@google.com> Reviewed-by: Greg Daniel <egdaniel@google.com> Reviewed-by: Cary Clark <caryclark@google.com>
-rw-r--r--BUILD.gn1
-rw-r--r--include/gpu/GrBackendSurface.h6
-rw-r--r--tests/GrMipMappedTest.cpp2
-rw-r--r--tools/fiddle/draw.cpp26
-rw-r--r--tools/fiddle/fiddle_main.cpp125
-rw-r--r--tools/fiddle/fiddle_main.h3
-rw-r--r--tools/gpu/GrTest.cpp21
-rw-r--r--tools/gpu/GrTest.h4
8 files changed, 184 insertions, 4 deletions
diff --git a/BUILD.gn b/BUILD.gn
index 2a8b8d30c1..6e24d3dec0 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -904,6 +904,7 @@ if (skia_enable_tools) {
testonly = true
deps = [
":flags",
+ ":gpu_tool_utils",
":skia",
":skia.h",
]
diff --git a/include/gpu/GrBackendSurface.h b/include/gpu/GrBackendSurface.h
index c9d326bc36..ce6ad194ac 100644
--- a/include/gpu/GrBackendSurface.h
+++ b/include/gpu/GrBackendSurface.h
@@ -96,6 +96,9 @@ private:
class SK_API GrBackendRenderTarget {
public:
+ // Creates an invalid backend texture.
+ GrBackendRenderTarget() : fConfig(kUnknown_GrPixelConfig) {}
+
GrBackendRenderTarget(int width,
int height,
int sampleCnt,
@@ -127,6 +130,9 @@ public:
const GrVkImageInfo* getVkImageInfo() const;
#endif
+ // Returns true if the backend texture has been initialized.
+ bool isValid() const { return fConfig != kUnknown_GrPixelConfig; }
+
private:
// Friending for access to the GrPixelConfig
friend class SkSurface;
diff --git a/tests/GrMipMappedTest.cpp b/tests/GrMipMappedTest.cpp
index c2a0df2e5d..ff9d76d044 100644
--- a/tests/GrMipMappedTest.cpp
+++ b/tests/GrMipMappedTest.cpp
@@ -43,7 +43,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrWrappedMipMappedTest, reporter, ctxInfo) {
// so we don't send any. However, we pretend there is data for the checks below which is
// fine since we are never actually using these textures for any work on the gpu.
GrBackendObject backendHandle = context->getGpu()->createTestingOnlyBackendTexture(
- nullptr, 8, 8, kRGBA_8888_GrPixelConfig, isRT, mipMapped);
+ nullptr, kSize, kSize, kRGBA_8888_GrPixelConfig, isRT, mipMapped);
GrBackend backend = context->contextPriv().getBackend();
GrBackendTexture backendTex = GrTest::CreateBackendTexture(backend,
diff --git a/tools/fiddle/draw.cpp b/tools/fiddle/draw.cpp
index 8e94883313..31aa9d0a81 100644
--- a/tools/fiddle/draw.cpp
+++ b/tools/fiddle/draw.cpp
@@ -26,4 +26,30 @@ void draw(SkCanvas* canvas) {
&matrix));
canvas->drawPaint(paint);
SkDebugf("This is text output: %d", 2);
+
+ GrContext* context = canvas->getGrContext();
+ if (context) {
+ sk_sp<SkImage> tmp = SkImage::MakeFromTexture(context,
+ backEndTexture,
+ kTopLeft_GrSurfaceOrigin,
+ kOpaque_SkAlphaType,
+ nullptr);
+
+ sk_sp<SkSurface> tmp2 = SkSurface::MakeFromBackendTexture(context,
+ backEndTextureRenderTarget,
+ kTopLeft_GrSurfaceOrigin,
+ 0, nullptr, nullptr);
+
+ sk_sp<SkSurface> tmp3 = SkSurface::MakeFromBackendRenderTarget(context,
+ backEndRenderTarget,
+ kTopLeft_GrSurfaceOrigin,
+ nullptr, nullptr);
+
+ sk_sp<SkSurface> tmp4 = SkSurface::MakeFromBackendTextureAsRenderTarget(
+ context,
+ backEndTextureRenderTarget,
+ kTopLeft_GrSurfaceOrigin,
+ 0, nullptr, nullptr);
+ }
+
}
diff --git a/tools/fiddle/fiddle_main.cpp b/tools/fiddle/fiddle_main.cpp
index 6ceffc9b9c..b815be10f7 100644
--- a/tools/fiddle/fiddle_main.cpp
+++ b/tools/fiddle/fiddle_main.cpp
@@ -11,13 +11,30 @@
#include <string>
#include "SkCommandLineFlags.h"
+#include "SkUtils.h"
#include "fiddle_main.h"
DEFINE_double(duration, 1.0, "The total duration, in seconds, of the animation we are drawing.");
DEFINE_double(frame, 1.0, "A double value in [0, 1] that specifies the point in animation to draw.");
+#include "GrBackendSurface.h"
+#include "GrContextPriv.h"
+#include "GrGpu.h"
+
+#include "GrTest.h"
+
+
// Globals externed in fiddle_main.h
+sk_sp<GrTexture> backingTexture; // not externed
+GrBackendTexture backEndTexture;
+
+sk_sp<GrRenderTarget> backingRenderTarget; // not externed
+GrBackendRenderTarget backEndRenderTarget;
+
+sk_sp<GrTexture> backingTextureRenderTarget; // not externed
+GrBackendTexture backEndTextureRenderTarget;
+
SkBitmap source;
sk_sp<SkImage> image;
double duration; // The total duration of the animation in seconds.
@@ -98,6 +115,103 @@ static SkCanvas* prepare_canvas(SkCanvas * canvas) {
return canvas;
}
+static bool setup_backend_objects(GrContext* context, const SkBitmap& bm,
+ int width, int height, int sampleCnt) {
+ if (!context) {
+ return false;
+ }
+
+ GrBackend backend = context->contextPriv().getBackend();
+ const GrPixelConfig kConfig = kRGBA_8888_GrPixelConfig;
+
+ GrSurfaceDesc backingDesc;
+ backingDesc.fFlags = kNone_GrSurfaceFlags;
+ backingDesc.fOrigin = kTopLeft_GrSurfaceOrigin;
+ backingDesc.fWidth = bm.width();
+ backingDesc.fHeight = bm.height();
+ backingDesc.fConfig = kConfig;
+ backingDesc.fSampleCnt = 0;
+
+ if (!bm.empty()) {
+ GrMipLevel level0 = { bm.getPixels(), bm.rowBytes() };
+
+ backingTexture = context->resourceProvider()->createTexture(
+ backingDesc, SkBudgeted::kNo,
+ &level0, 1,
+ SkDestinationSurfaceColorMode::kLegacy);
+ if (!backingTexture) {
+ return false;
+ }
+
+ backEndTexture = GrTest::CreateBackendTexture(backend,
+ backingDesc.fWidth,
+ backingDesc.fHeight,
+ kConfig,
+ GrMipMapped::kNo,
+ backingTexture->getTextureHandle());
+ if (!backEndTexture.isValid()) {
+ return false;
+ }
+ }
+
+ backingDesc.fFlags = kRenderTarget_GrSurfaceFlag;
+ backingDesc.fWidth = width;
+ backingDesc.fHeight = height;
+ backingDesc.fSampleCnt = sampleCnt;
+
+ SkAutoTMalloc<uint32_t> data(width * height);
+ sk_memset32(data.get(), 0, width * height);
+
+ GrMipLevel level0 = { data.get(), width*sizeof(uint32_t) };
+
+ {
+ sk_sp<GrTexture> tmp = context->resourceProvider()->createTexture(
+ backingDesc, SkBudgeted::kNo,
+ &level0, 1,
+ SkDestinationSurfaceColorMode::kLegacy);
+ if (!tmp || !tmp->asRenderTarget()) {
+ return false;
+ }
+
+ backingRenderTarget = sk_ref_sp(tmp->asRenderTarget());
+
+ backEndRenderTarget = GrTest::CreateBackendRenderTarget(
+ backend,
+ backingDesc.fWidth,
+ backingDesc.fHeight,
+ backingDesc.fSampleCnt, 0,
+ kConfig,
+ backingRenderTarget->getRenderTargetHandle());
+ if (!backEndRenderTarget.isValid()) {
+ return false;
+ }
+ }
+
+ {
+ backingTextureRenderTarget = context->resourceProvider()->createTexture(
+ backingDesc, SkBudgeted::kNo,
+ &level0, 1,
+ SkDestinationSurfaceColorMode::kLegacy);
+ if (!backingTextureRenderTarget || !backingTextureRenderTarget->asRenderTarget()) {
+ return false;
+ }
+
+ backEndTextureRenderTarget = GrTest::CreateBackendTexture(
+ backend,
+ backingDesc.fWidth,
+ backingDesc.fHeight,
+ kConfig,
+ GrMipMapped::kNo,
+ backingTextureRenderTarget->getTextureHandle());
+ if (!backEndTextureRenderTarget.isValid()) {
+ return false;
+ }
+ }
+
+
+ return true;
+}
+
int main(int argc, char** argv) {
SkCommandLineFlags::Parse(argc, argv);
duration = FLAGS_duration;
@@ -122,8 +236,7 @@ int main(int argc, char** argv) {
perror("Unable to decode the source image.");
return 1;
}
- SkAssertResult(image->asLegacyBitmap(
- &source, SkImage::kRO_LegacyBitmapMode));
+ SkAssertResult(image->asLegacyBitmap(&source, SkImage::kRO_LegacyBitmapMode));
}
}
sk_sp<SkData> rasterData, gpuData, pdfData, skpData;
@@ -145,10 +258,16 @@ int main(int argc, char** argv) {
rasterData = encode_snapshot(rasterSurface);
}
if (options.gpu) {
- auto grContext = create_grcontext(gGLDriverInfo);
+ sk_sp<GrContext> grContext = create_grcontext(gGLDriverInfo);
if (!grContext) {
fputs("Unable to get GrContext.\n", stderr);
} else {
+ if (!setup_backend_objects(grContext.get(), source,
+ options.size.width(), options.size.height(), 0)) {
+ fputs("Unable to create backend objects.\n", stderr);
+ exit(1);
+ }
+
auto surface = SkSurface::MakeRenderTarget(grContext.get(), SkBudgeted::kNo, info);
if (!surface) {
fputs("Unable to get render surface.\n", stderr);
diff --git a/tools/fiddle/fiddle_main.h b/tools/fiddle/fiddle_main.h
index fb9d409482..97fa071913 100644
--- a/tools/fiddle/fiddle_main.h
+++ b/tools/fiddle/fiddle_main.h
@@ -22,6 +22,9 @@
#include <sstream>
+extern GrBackendTexture backEndTexture;
+extern GrBackendRenderTarget backEndRenderTarget;
+extern GrBackendTexture backEndTextureRenderTarget;
extern SkBitmap source;
extern sk_sp<SkImage> image;
extern double duration; // The total duration of the animation in seconds.
diff --git a/tools/gpu/GrTest.cpp b/tools/gpu/GrTest.cpp
index 32e2cfa91d..83e5aa7f3b 100644
--- a/tools/gpu/GrTest.cpp
+++ b/tools/gpu/GrTest.cpp
@@ -78,6 +78,27 @@ GrBackendTexture CreateBackendTexture(GrBackend backend, int width, int height,
}
}
+GrBackendRenderTarget CreateBackendRenderTarget(GrBackend backend, int width, int height,
+ int sampleCnt, int stencilBits,
+ GrPixelConfig config,
+ GrBackendObject handle) {
+ switch (backend) {
+#ifdef SK_VULKAN
+ case kVulkan_GrBackend: {
+ GrVkImageInfo* vkInfo = (GrVkImageInfo*)(handle);
+ return GrBackendRenderTarget(width, height, sampleCnt, stencilBits, *vkInfo);
+ }
+#endif
+ case kOpenGL_GrBackend: {
+ GrGLFramebufferInfo* glInfo = (GrGLFramebufferInfo*)(handle);
+ return GrBackendRenderTarget(width, height, sampleCnt, stencilBits, config, *glInfo);
+ }
+ case kMock_GrBackend: // fall through
+ default:
+ return GrBackendRenderTarget();
+ }
+}
+
} // namespace GrTest
bool GrSurfaceProxy::isWrapped_ForTesting() const {
diff --git a/tools/gpu/GrTest.h b/tools/gpu/GrTest.h
index 612245f07b..1134932ad9 100644
--- a/tools/gpu/GrTest.h
+++ b/tools/gpu/GrTest.h
@@ -20,6 +20,10 @@ namespace GrTest {
GrBackendTexture CreateBackendTexture(GrBackend, int width, int height,
GrPixelConfig, GrMipMapped, GrBackendObject);
+
+ GrBackendRenderTarget CreateBackendRenderTarget(GrBackend, int width, int height,
+ int sampleCnt, int stencilBits,
+ GrPixelConfig, GrBackendObject);
};
#endif