aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/fiddle
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 /tools/fiddle
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>
Diffstat (limited to 'tools/fiddle')
-rw-r--r--tools/fiddle/draw.cpp26
-rw-r--r--tools/fiddle/fiddle_main.cpp125
-rw-r--r--tools/fiddle/fiddle_main.h3
3 files changed, 151 insertions, 3 deletions
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.