gfx/skia/trunk/include/utils/SkDebugUtils.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/include/utils/SkDebugUtils.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,94 @@
     1.4 +
     1.5 +/*
     1.6 + * Copyright 2013 Google, Inc.
     1.7 + *
     1.8 + * Use of this source code is governed by a BSD-style license that can be
     1.9 + * found in the LICENSE file.
    1.10 + */
    1.11 +
    1.12 +
    1.13 +#ifndef SkDebugUtils_DEFINED
    1.14 +#define SkDebugUtils_DEFINED
    1.15 +
    1.16 +#include "SkTypes.h"
    1.17 +
    1.18 +// These functions dump 0, 1, and 2d arrays of data in a format that's
    1.19 +// compatible with Mathematica for quick visualization
    1.20 +
    1.21 +
    1.22 +template<class T>
    1.23 +inline void SkDebugDumpMathematica( const T val ) {
    1.24 +    SkDEBUGFAIL("Need to specialize SkDebugDumpMathematica for your type, sorry.");
    1.25 +}
    1.26 +
    1.27 +template<class T>
    1.28 +inline void SkDebugDumpMathematica(const char *name, const T *array, int size) {
    1.29 +    SkDebugf(name);
    1.30 +    SkDebugf(" = {");
    1.31 +    for (int i=0 ; i < size ; i++) {
    1.32 +        SkDebugDumpMathematica<T>(array[i]);
    1.33 +        if (i != size-1) SkDebugf(", ");
    1.34 +    }
    1.35 +    SkDebugf("};\n");
    1.36 +}
    1.37 +
    1.38 +template<class T>
    1.39 +inline void SkDebugDumpMathematica(const char *name, const T *array, int width, int height) {
    1.40 +    SkDebugf(name);
    1.41 +    SkDebugf(" = {\n");
    1.42 +    for (int i=0 ; i < height ; i++) {
    1.43 +        SkDebugf("  {");
    1.44 +        for (int j = 0 ; j < width ; j++) {
    1.45 +            SkDebugDumpMathematica<T>(array[i*width + j]);
    1.46 +            if (j != width-1) {
    1.47 +                SkDebugf(", ");
    1.48 +            }
    1.49 +        }
    1.50 +        SkDebugf("}");
    1.51 +        if (i != height-1) {
    1.52 +            SkDebugf(", \n");
    1.53 +        }
    1.54 +    }
    1.55 +    SkDebugf("\n};\n");
    1.56 +}
    1.57 +
    1.58 +template<class T>
    1.59 +inline void SkDebugDumpMathematica( const char *name, const T val ) {
    1.60 +    SkDebugf(name);
    1.61 +    SkDebugf(" = ");
    1.62 +    SkDebugDumpMathematica<T>(val);
    1.63 +    SkDebugf(";\n");
    1.64 +}
    1.65 +
    1.66 +template<>
    1.67 +inline void SkDebugDumpMathematica<uint8_t>( const uint8_t val ) {
    1.68 +    SkDebugf("%u", val);
    1.69 +}
    1.70 +
    1.71 +template<>
    1.72 +inline void SkDebugDumpMathematica<unsigned int>( const unsigned int val ) {
    1.73 +    SkDebugf("%u", val);
    1.74 +}
    1.75 +
    1.76 +template<>
    1.77 +inline void SkDebugDumpMathematica<int>( const int val ) {
    1.78 +    SkDebugf("%d", val);
    1.79 +}
    1.80 +
    1.81 +template<>
    1.82 +inline void SkDebugDumpMathematica<size_t>( const size_t val ) {
    1.83 +    SkDebugf("%u", val);
    1.84 +}
    1.85 +
    1.86 +template<>
    1.87 +void SkDebugDumpMathematica<const char *>( const char * val ) {
    1.88 +    SkDebugf("%s", val);
    1.89 +}
    1.90 +
    1.91 +template<>
    1.92 +inline void SkDebugDumpMathematica<float>( float val ) {
    1.93 +    SkDebugf("%f", val);
    1.94 +}
    1.95 +
    1.96 +
    1.97 +#endif

mercurial