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>
This commit is contained in:
Robert Phillips 2017-11-16 14:59:48 -05:00 committed by Skia Commit-Bot
parent ecd62a6cf6
commit 57e0828fad
8 changed files with 184 additions and 4 deletions

View File

@ -904,6 +904,7 @@ if (skia_enable_tools) {
testonly = true testonly = true
deps = [ deps = [
":flags", ":flags",
":gpu_tool_utils",
":skia", ":skia",
":skia.h", ":skia.h",
] ]

View File

@ -96,6 +96,9 @@ private:
class SK_API GrBackendRenderTarget { class SK_API GrBackendRenderTarget {
public: public:
// Creates an invalid backend texture.
GrBackendRenderTarget() : fConfig(kUnknown_GrPixelConfig) {}
GrBackendRenderTarget(int width, GrBackendRenderTarget(int width,
int height, int height,
int sampleCnt, int sampleCnt,
@ -127,6 +130,9 @@ public:
const GrVkImageInfo* getVkImageInfo() const; const GrVkImageInfo* getVkImageInfo() const;
#endif #endif
// Returns true if the backend texture has been initialized.
bool isValid() const { return fConfig != kUnknown_GrPixelConfig; }
private: private:
// Friending for access to the GrPixelConfig // Friending for access to the GrPixelConfig
friend class SkSurface; friend class SkSurface;

View File

@ -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 // 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. // fine since we are never actually using these textures for any work on the gpu.
GrBackendObject backendHandle = context->getGpu()->createTestingOnlyBackendTexture( 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(); GrBackend backend = context->contextPriv().getBackend();
GrBackendTexture backendTex = GrTest::CreateBackendTexture(backend, GrBackendTexture backendTex = GrTest::CreateBackendTexture(backend,

View File

@ -26,4 +26,30 @@ void draw(SkCanvas* canvas) {
&matrix)); &matrix));
canvas->drawPaint(paint); canvas->drawPaint(paint);
SkDebugf("This is text output: %d", 2); 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);
}
} }

View File

@ -11,13 +11,30 @@
#include <string> #include <string>
#include "SkCommandLineFlags.h" #include "SkCommandLineFlags.h"
#include "SkUtils.h"
#include "fiddle_main.h" #include "fiddle_main.h"
DEFINE_double(duration, 1.0, "The total duration, in seconds, of the animation we are drawing."); 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."); 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 // 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; SkBitmap source;
sk_sp<SkImage> image; sk_sp<SkImage> image;
double duration; // The total duration of the animation in seconds. double duration; // The total duration of the animation in seconds.
@ -98,6 +115,103 @@ static SkCanvas* prepare_canvas(SkCanvas * canvas) {
return 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) { int main(int argc, char** argv) {
SkCommandLineFlags::Parse(argc, argv); SkCommandLineFlags::Parse(argc, argv);
duration = FLAGS_duration; duration = FLAGS_duration;
@ -122,8 +236,7 @@ int main(int argc, char** argv) {
perror("Unable to decode the source image."); perror("Unable to decode the source image.");
return 1; return 1;
} }
SkAssertResult(image->asLegacyBitmap( SkAssertResult(image->asLegacyBitmap(&source, SkImage::kRO_LegacyBitmapMode));
&source, SkImage::kRO_LegacyBitmapMode));
} }
} }
sk_sp<SkData> rasterData, gpuData, pdfData, skpData; sk_sp<SkData> rasterData, gpuData, pdfData, skpData;
@ -145,10 +258,16 @@ int main(int argc, char** argv) {
rasterData = encode_snapshot(rasterSurface); rasterData = encode_snapshot(rasterSurface);
} }
if (options.gpu) { if (options.gpu) {
auto grContext = create_grcontext(gGLDriverInfo); sk_sp<GrContext> grContext = create_grcontext(gGLDriverInfo);
if (!grContext) { if (!grContext) {
fputs("Unable to get GrContext.\n", stderr); fputs("Unable to get GrContext.\n", stderr);
} else { } 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); auto surface = SkSurface::MakeRenderTarget(grContext.get(), SkBudgeted::kNo, info);
if (!surface) { if (!surface) {
fputs("Unable to get render surface.\n", stderr); fputs("Unable to get render surface.\n", stderr);

View File

@ -22,6 +22,9 @@
#include <sstream> #include <sstream>
extern GrBackendTexture backEndTexture;
extern GrBackendRenderTarget backEndRenderTarget;
extern GrBackendTexture backEndTextureRenderTarget;
extern SkBitmap source; extern SkBitmap source;
extern sk_sp<SkImage> image; extern sk_sp<SkImage> image;
extern double duration; // The total duration of the animation in seconds. extern double duration; // The total duration of the animation in seconds.

View File

@ -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 } // namespace GrTest
bool GrSurfaceProxy::isWrapped_ForTesting() const { bool GrSurfaceProxy::isWrapped_ForTesting() const {

View File

@ -20,6 +20,10 @@ namespace GrTest {
GrBackendTexture CreateBackendTexture(GrBackend, int width, int height, GrBackendTexture CreateBackendTexture(GrBackend, int width, int height,
GrPixelConfig, GrMipMapped, GrBackendObject); GrPixelConfig, GrMipMapped, GrBackendObject);
GrBackendRenderTarget CreateBackendRenderTarget(GrBackend, int width, int height,
int sampleCnt, int stencilBits,
GrPixelConfig, GrBackendObject);
}; };
#endif #endif