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:
parent
1efccd297e
commit
768bc6a920
@ -11,6 +11,12 @@
|
|||||||
#include "SkTArray.h"
|
#include "SkTArray.h"
|
||||||
#include "SkNulCanvas.h"
|
#include "SkNulCanvas.h"
|
||||||
|
|
||||||
|
#if SK_SUPPORT_GPU
|
||||||
|
#include "GrContextFactory.h"
|
||||||
|
#include "GrContext.h"
|
||||||
|
#include "SkGpuDevice.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "SkPdfRenderer.h"
|
#include "SkPdfRenderer.h"
|
||||||
|
|
||||||
DEFINE_string2(readPath, r, "", "pdf files or directories of pdf files to process.");
|
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).");
|
"\tminimal parsing to ensure correctness. Default 0 (disabled).");
|
||||||
DEFINE_int32(benchRender, 0, "Render the pdf content N times. 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"
|
DEFINE_string2(config, c, "8888", "Canvas to render:\n"
|
||||||
"\t8888 - all pages\n"
|
"\t8888 - argb\n"
|
||||||
"\tnul - all pages, in reverse order\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" SkBitmap* gDumpBitmap;
|
||||||
extern "C" SkCanvas* gDumpCanvas;
|
extern "C" SkCanvas* gDumpCanvas;
|
||||||
|
|
||||||
|
#if SK_SUPPORT_GPU
|
||||||
|
GrContextFactory gContextFactory;
|
||||||
|
#endif
|
||||||
|
|
||||||
static bool render_page(const SkString& outputDir,
|
static bool render_page(const SkString& outputDir,
|
||||||
const SkString& inputFilename,
|
const SkString& inputFilename,
|
||||||
const SkPdfRenderer& renderer,
|
const SkPdfRenderer& renderer,
|
||||||
@ -183,7 +197,36 @@ static bool render_page(const SkString& outputDir,
|
|||||||
#else
|
#else
|
||||||
setup_bitmap(&bitmap, (int)SkScalarToDouble(width), (int)SkScalarToDouble(height));
|
setup_bitmap(&bitmap, (int)SkScalarToDouble(width), (int)SkScalarToDouble(height));
|
||||||
#endif
|
#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);
|
SkCanvas canvas(device);
|
||||||
|
|
||||||
gDumpBitmap = &bitmap;
|
gDumpBitmap = &bitmap;
|
||||||
|
@ -72,9 +72,7 @@
|
|||||||
'<(SHARED_INTERMEDIATE_DIR)/native/autogen',
|
'<(SHARED_INTERMEDIATE_DIR)/native/autogen',
|
||||||
],
|
],
|
||||||
'dependencies': [
|
'dependencies': [
|
||||||
'core.gyp:core',
|
'skia_lib.gyp:skia_lib',
|
||||||
'effects.gyp:effects',
|
|
||||||
'images.gyp:images',
|
|
||||||
'zlib.gyp:zlib',
|
'zlib.gyp:zlib',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@ -96,7 +94,7 @@
|
|||||||
'../experimental/PdfViewer/pdfparser/native/autogen',
|
'../experimental/PdfViewer/pdfparser/native/autogen',
|
||||||
],
|
],
|
||||||
'dependencies': [
|
'dependencies': [
|
||||||
'core.gyp:core',
|
'skia_lib.gyp:skia_lib',
|
||||||
'flags.gyp:flags',
|
'flags.gyp:flags',
|
||||||
'libpdfviewer',
|
'libpdfviewer',
|
||||||
'chop_transparency',
|
'chop_transparency',
|
||||||
|
Loading…
Reference in New Issue
Block a user