Index: experimental/PdfViewer/pdf_viewer_main.cpp |
=================================================================== |
--- experimental/PdfViewer/pdf_viewer_main.cpp (revision 10588) |
+++ experimental/PdfViewer/pdf_viewer_main.cpp (working copy) |
@@ -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 @@ |
"\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 @@ |
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 @@ |
#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; |