f1754ec691
SkPicture: Remove the constructors which take an SkStream as an argument. Rather than having to check a variable for success, the factory will return NULL on failure. Add a protected function for determining if an SkStream is an SKP to share code with SkTimedPicture. In the factory, check for a NULL SkStream. Use a default decoder (from BUG: https://code.google.com/p/skia/issues/detail?id=1325) SkDebuggerGUI: Call SkPicture::CreateFromStream when necessary. Write a factory for creating SkTimedPictures and use it. Use the factory throughout tools. Add include/lazy to utils and effects gyp include_dirs so SkPicture.h can reference SkImageDecoder.h which references SkBitmapFactory.h (in include/lazy). Changes code Chromium uses, so this will require a temporary Skia and then a change to Chromium to use the new Skia code. TODO: Create a decoder that does nothing to be used by pinspect, lua pictures, etc, and allow it to not assert in SkOrderedReadBuffer. R=reed@google.com Review URL: https://codereview.chromium.org/17113004 git-svn-id: http://skia.googlecode.com/svn/trunk@9822 2bbb7eff-a529-9590-31e7-b0007b416f81
95 lines
2.2 KiB
C++
95 lines
2.2 KiB
C++
/*
|
|
* Copyright 2012 Google Inc.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
#include "SkBitmap.h"
|
|
#include "SkCanvas.h"
|
|
#include "SkGraphics.h"
|
|
#include "SkOSFile.h"
|
|
#include "SkImageDecoder.h"
|
|
#include "SkPicture.h"
|
|
#include "SkStream.h"
|
|
#include "SkString.h"
|
|
#include "SkDumpCanvas.h"
|
|
#include "SkForceLinking.h"
|
|
|
|
__SK_FORCE_IMAGE_DECODER_LINKING;
|
|
|
|
// Defined in PictureRenderingFlags.cpp
|
|
extern bool lazy_decode_bitmap(const void* buffer, size_t size, SkBitmap* bitmap);
|
|
|
|
static SkPicture* inspect(const char path[]) {
|
|
SkFILEStream stream(path);
|
|
if (!stream.isValid()) {
|
|
printf("-- Can't open '%s'\n", path);
|
|
return NULL;
|
|
}
|
|
|
|
printf("Opening '%s'...\n", path);
|
|
|
|
{
|
|
int32_t header[3];
|
|
if (stream.read(header, sizeof(header)) != sizeof(header)) {
|
|
printf("-- Failed to read header (12 bytes)\n");
|
|
return NULL;
|
|
}
|
|
printf("version:%d width:%d height:%d\n", header[0], header[1], header[2]);
|
|
}
|
|
|
|
stream.rewind();
|
|
SkPicture* pic = SkPicture::CreateFromStream(&stream, &lazy_decode_bitmap);
|
|
if (NULL == pic) {
|
|
SkDebugf("Could not create SkPicture: %s\n", path);
|
|
return NULL;
|
|
}
|
|
printf("picture size:[%d %d]\n", pic->width(), pic->height());
|
|
return pic;
|
|
}
|
|
|
|
static void dumpOps(SkPicture* pic) {
|
|
#ifdef SK_DEVELOPER
|
|
SkDebugfDumper dumper;
|
|
SkDumpCanvas canvas(&dumper);
|
|
canvas.drawPicture(*pic);
|
|
#else
|
|
printf("SK_DEVELOPER mode not enabled\n");
|
|
#endif
|
|
}
|
|
|
|
int tool_main(int argc, char** argv);
|
|
int tool_main(int argc, char** argv) {
|
|
SkAutoGraphics ag;
|
|
if (argc < 2) {
|
|
printf("Usage: pinspect [--dump-ops] filename [filename ...]\n");
|
|
return 1;
|
|
}
|
|
|
|
bool doDumpOps = false;
|
|
|
|
int index = 1;
|
|
if (!strcmp(argv[index], "--dump-ops")) {
|
|
index += 1;
|
|
doDumpOps = true;
|
|
}
|
|
|
|
for (; index < argc; ++index) {
|
|
SkAutoTUnref<SkPicture> pic(inspect(argv[index]));
|
|
if (doDumpOps) {
|
|
dumpOps(pic);
|
|
}
|
|
if (index < argc - 1) {
|
|
printf("\n");
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
#if !defined SK_BUILD_FOR_IOS
|
|
int main(int argc, char * const argv[]) {
|
|
return tool_main(argc, (char**) argv);
|
|
}
|
|
#endif
|