aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/fiddle
diff options
context:
space:
mode:
authorGravatar Robert Phillips <robertphillips@google.com>2017-11-17 14:59:43 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-11-27 17:22:26 +0000
commitc34aa9d51a6d7b0426436e32750228964274f754 (patch)
treec1c0fd28746701868d34452f4fae1e4239026533 /tools/fiddle
parentc82dd4e2cff30453f0dce4dfba9dc912321ba7bd (diff)
Add Fiddle DrawOptions for the backend objects
Change-Id: I720125f134394a8b923d6e883941d20715945d73 Reviewed-on: https://skia-review.googlesource.com/73340 Reviewed-by: Cary Clark <caryclark@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'tools/fiddle')
-rw-r--r--tools/fiddle/draw.cpp11
-rw-r--r--tools/fiddle/fiddle_main.cpp59
-rw-r--r--tools/fiddle/fiddle_main.h28
3 files changed, 74 insertions, 24 deletions
diff --git a/tools/fiddle/draw.cpp b/tools/fiddle/draw.cpp
index 31aa9d0a81..346d1caf59 100644
--- a/tools/fiddle/draw.cpp
+++ b/tools/fiddle/draw.cpp
@@ -13,7 +13,8 @@
DrawOptions GetDrawOptions() {
// path *should* be absolute.
static const char path[] = "resources/color_wheel.png";
- return DrawOptions(256, 256, true, true, true, true, true, false, false, path);
+ return DrawOptions(256, 256, true, true, true, true, true, false, false, path,
+ GrMipMapped::kYes, 64, 64, 0, GrMipMapped::kYes);
}
void draw(SkCanvas* canvas) {
canvas->clear(SK_ColorWHITE);
@@ -35,21 +36,17 @@ void draw(SkCanvas* canvas) {
kOpaque_SkAlphaType,
nullptr);
+ // TODO: this sampleCnt parameter here should match that set in the options!
sk_sp<SkSurface> tmp2 = SkSurface::MakeFromBackendTexture(context,
backEndTextureRenderTarget,
kTopLeft_GrSurfaceOrigin,
0, nullptr, nullptr);
+ // Note: this surface should only be renderable (i.e., not textureable)
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 b815be10f7..92767d1b40 100644
--- a/tools/fiddle/fiddle_main.cpp
+++ b/tools/fiddle/fiddle_main.cpp
@@ -11,6 +11,7 @@
#include <string>
#include "SkCommandLineFlags.h"
+#include "SkMipMap.h"
#include "SkUtils.h"
#include "fiddle_main.h"
@@ -115,8 +116,9 @@ static SkCanvas* prepare_canvas(SkCanvas * canvas) {
return canvas;
}
-static bool setup_backend_objects(GrContext* context, const SkBitmap& bm,
- int width, int height, int sampleCnt) {
+static bool setup_backend_objects(GrContext* context,
+ const SkBitmap& bm,
+ const DrawOptions& options) {
if (!context) {
return false;
}
@@ -133,11 +135,22 @@ static bool setup_backend_objects(GrContext* context, const SkBitmap& bm,
backingDesc.fSampleCnt = 0;
if (!bm.empty()) {
- GrMipLevel level0 = { bm.getPixels(), bm.rowBytes() };
+ int mipLevelCount = GrMipMapped::kYes == options.fMipMapping
+ ? SkMipMap::ComputeLevelCount(bm.width(), bm.height())
+ : 1;
+ std::unique_ptr<GrMipLevel[]> texels(new GrMipLevel[mipLevelCount]);
+
+ texels[0].fPixels = bm.getPixels();
+ texels[0].fRowBytes = bm.rowBytes();
+
+ for (int i = 1; i < mipLevelCount; i++) {
+ texels[i].fPixels = nullptr;
+ texels[i].fRowBytes = 0;
+ }
backingTexture = context->resourceProvider()->createTexture(
backingDesc, SkBudgeted::kNo,
- &level0, 1,
+ texels.get(), mipLevelCount,
SkDestinationSurfaceColorMode::kLegacy);
if (!backingTexture) {
return false;
@@ -147,7 +160,7 @@ static bool setup_backend_objects(GrContext* context, const SkBitmap& bm,
backingDesc.fWidth,
backingDesc.fHeight,
kConfig,
- GrMipMapped::kNo,
+ options.fMipMapping,
backingTexture->getTextureHandle());
if (!backEndTexture.isValid()) {
return false;
@@ -155,16 +168,20 @@ static bool setup_backend_objects(GrContext* context, const SkBitmap& bm,
}
backingDesc.fFlags = kRenderTarget_GrSurfaceFlag;
- backingDesc.fWidth = width;
- backingDesc.fHeight = height;
- backingDesc.fSampleCnt = sampleCnt;
+ backingDesc.fWidth = options.fOffScreenWidth;
+ backingDesc.fHeight = options.fOffScreenHeight;
+ backingDesc.fSampleCnt = options.fOffScreenSampleCount;
- SkAutoTMalloc<uint32_t> data(width * height);
- sk_memset32(data.get(), 0, width * height);
+ SkAutoTMalloc<uint32_t> data(backingDesc.fWidth * backingDesc.fHeight);
+ sk_memset32(data.get(), 0, backingDesc.fWidth * backingDesc.fHeight);
- GrMipLevel level0 = { data.get(), width*sizeof(uint32_t) };
{
+ // This backend object should be renderable but not textureable. Given the limitations
+ // of how we're creating it though it will wind up being secretly textureable.
+ // We use this fact to initialize it with data but don't allow mipmaps
+ GrMipLevel level0 = { data.get(), backingDesc.fWidth*sizeof(uint32_t) };
+
sk_sp<GrTexture> tmp = context->resourceProvider()->createTexture(
backingDesc, SkBudgeted::kNo,
&level0, 1,
@@ -188,9 +205,22 @@ static bool setup_backend_objects(GrContext* context, const SkBitmap& bm,
}
{
+ int mipLevelCount = GrMipMapped::kYes == options.fOffScreenMipMapping
+ ? SkMipMap::ComputeLevelCount(backingDesc.fWidth, backingDesc.fHeight)
+ : 1;
+ std::unique_ptr<GrMipLevel[]> texels(new GrMipLevel[mipLevelCount]);
+
+ texels[0].fPixels = data.get();
+ texels[0].fRowBytes = backingDesc.fWidth*sizeof(uint32_t);
+
+ for (int i = 1; i < mipLevelCount; i++) {
+ texels[i].fPixels = nullptr;
+ texels[i].fRowBytes = 0;
+ }
+
backingTextureRenderTarget = context->resourceProvider()->createTexture(
backingDesc, SkBudgeted::kNo,
- &level0, 1,
+ texels.get(), mipLevelCount,
SkDestinationSurfaceColorMode::kLegacy);
if (!backingTextureRenderTarget || !backingTextureRenderTarget->asRenderTarget()) {
return false;
@@ -201,7 +231,7 @@ static bool setup_backend_objects(GrContext* context, const SkBitmap& bm,
backingDesc.fWidth,
backingDesc.fHeight,
kConfig,
- GrMipMapped::kNo,
+ options.fOffScreenMipMapping,
backingTextureRenderTarget->getTextureHandle());
if (!backEndTextureRenderTarget.isValid()) {
return false;
@@ -262,8 +292,7 @@ int main(int argc, char** argv) {
if (!grContext) {
fputs("Unable to get GrContext.\n", stderr);
} else {
- if (!setup_backend_objects(grContext.get(), source,
- options.size.width(), options.size.height(), 0)) {
+ if (!setup_backend_objects(grContext.get(), source, options)) {
fputs("Unable to create backend objects.\n", stderr);
exit(1);
}
diff --git a/tools/fiddle/fiddle_main.h b/tools/fiddle/fiddle_main.h
index 97fa071913..5492a424ea 100644
--- a/tools/fiddle/fiddle_main.h
+++ b/tools/fiddle/fiddle_main.h
@@ -31,7 +31,13 @@ extern double duration; // The total duration of the animation in seconds.
extern double frame; // A value in [0, 1] of where we are in the animation.
struct DrawOptions {
- DrawOptions(int w, int h, bool r, bool g, bool p, bool k, bool srgb, bool f16, bool textOnly, const char* s)
+ DrawOptions(int w, int h, bool r, bool g, bool p, bool k, bool srgb, bool f16,
+ bool textOnly, const char* s,
+ GrMipMapped mipMapping,
+ int offScreenWidth,
+ int offScreenHeight,
+ int offScreenSampleCount,
+ GrMipMapped offScreenMipMapping)
: size(SkISize::Make(w, h))
, raster(r)
, gpu(g)
@@ -41,7 +47,11 @@ struct DrawOptions {
, f16(f16)
, textOnly(textOnly)
, source(s)
- {
+ , fMipMapping(mipMapping)
+ , fOffScreenWidth(offScreenWidth)
+ , fOffScreenHeight(offScreenHeight)
+ , fOffScreenSampleCount(offScreenSampleCount)
+ , fOffScreenMipMapping(offScreenMipMapping) {
// F16 mode is only valid for color correct backends.
SkASSERT(srgb || !f16);
}
@@ -54,6 +64,20 @@ struct DrawOptions {
bool f16;
bool textOnly;
const char* source;
+
+ // This flag is used when a GPU texture resource is created and exposed as a GrBackendTexture.
+ // In this case the resource is created with extra room to accomodate mipmaps.
+ // TODO: The SkImage::makeTextureImage API would need to be widened to allow this to be true
+ // for the non-backend gpu SkImages.
+ GrMipMapped fMipMapping;
+
+ // Parameters for an GPU offscreen resource exposed as a GrBackendRenderTarget
+ int fOffScreenWidth;
+ int fOffScreenHeight;
+ int fOffScreenSampleCount;
+ // TODO: should we also expose stencilBits here? How about the config?
+
+ GrMipMapped fOffScreenMipMapping; // only applicable if the offscreen is also textureable
};
extern DrawOptions GetDrawOptions();