pdfviewer: add ability to run on gpu

Review URL: https://codereview.chromium.org/22684002

git-svn-id: http://skia.googlecode.com/svn/trunk@10638 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
edisonn@google.com 2013-08-08 12:42:13 +00:00
parent 1efccd297e
commit 768bc6a920
2 changed files with 48 additions and 7 deletions

View File

@ -11,6 +11,12 @@
#include "SkTArray.h"
#include "SkNulCanvas.h"
#if SK_SUPPORT_GPU
#include "GrContextFactory.h"
#include "GrContext.h"
#include "SkGpuDevice.h"
#endif
#include "SkPdfRenderer.h"
DEFINE_string2(readPath, r, "", "pdf files or directories of pdf files to process.");
@ -29,8 +35,12 @@ DEFINE_int32(benchLoad, 0, "Load the pdf file minimally N times, without any ren
"\tminimal parsing to ensure correctness. Default 0 (disabled).");
DEFINE_int32(benchRender, 0, "Render the pdf content N times. Default 0 (disabled)");
DEFINE_string2(config, c, "8888", "Canvas to render:\n"
"\t8888 - all pages\n"
"\tnul - all pages, in reverse order\n"
"\t8888 - argb\n"
#if SK_SUPPORT_GPU
"\tgpu: use the gpu\n"
#endif
"\tnul - render in null canvas, any draw will just return.\n"
);
@ -156,6 +166,10 @@ static void setup_bitmap(SkBitmap* bitmap, int width, int height, SkColor color
extern "C" SkBitmap* gDumpBitmap;
extern "C" SkCanvas* gDumpCanvas;
#if SK_SUPPORT_GPU
GrContextFactory gContextFactory;
#endif
static bool render_page(const SkString& outputDir,
const SkString& inputFilename,
const SkPdfRenderer& renderer,
@ -183,7 +197,36 @@ static bool render_page(const SkString& outputDir,
#else
setup_bitmap(&bitmap, (int)SkScalarToDouble(width), (int)SkScalarToDouble(height));
#endif
SkAutoTUnref<SkDevice> device(SkNEW_ARGS(SkDevice, (bitmap)));
SkAutoTUnref<SkDevice> device;
if (strcmp(FLAGS_config[0], "8888") == 0) {
device.reset(SkNEW_ARGS(SkDevice, (bitmap)));
}
#if SK_SUPPORT_GPU
else if (strcmp(FLAGS_config[0], "gpu") == 0) {
SkAutoTUnref<GrSurface> target;
GrContext* gr = gContextFactory.get(GrContextFactory::kNative_GLContextType);
if (gr) {
// create a render target to back the device
GrTextureDesc desc;
desc.fConfig = kSkia8888_GrPixelConfig;
desc.fFlags = kRenderTarget_GrTextureFlagBit;
desc.fWidth = width;
desc.fHeight = height;
desc.fSampleCnt = 0;
target.reset(gr->createUncachedTexture(desc, NULL, 0));
}
if (NULL == target.get()) {
SkASSERT(0);
return false;
}
device.reset(SkGpuDevice::Create(target));
}
#endif
else {
SkDebugf("unknown --config: %s\n", FLAGS_config[0]);
return false;
}
SkCanvas canvas(device);
gDumpBitmap = &bitmap;

View File

@ -72,9 +72,7 @@
'<(SHARED_INTERMEDIATE_DIR)/native/autogen',
],
'dependencies': [
'core.gyp:core',
'effects.gyp:effects',
'images.gyp:images',
'skia_lib.gyp:skia_lib',
'zlib.gyp:zlib',
],
},
@ -96,7 +94,7 @@
'../experimental/PdfViewer/pdfparser/native/autogen',
],
'dependencies': [
'core.gyp:core',
'skia_lib.gyp:skia_lib',
'flags.gyp:flags',
'libpdfviewer',
'chop_transparency',