blob: c5af46065f59a7d86d53fde510aa720dcb84a49c [file] [log] [blame]
humper@google.com75e3ca12013-04-08 21:44:11 +00001/*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
skia.committer@gmail.com32840172013-04-09 07:01:27 +00007
humper@google.com75e3ca12013-04-08 21:44:11 +00008#ifndef SkError_DEFINED
9#define SkError_DEFINED
10
11
12/** \file SkError.h
13*/
14
15enum SkError {
16 /** All is well
17 */
18 kNoError_SkError=0,
skia.committer@gmail.com32840172013-04-09 07:01:27 +000019
20 /** User argument passed to Skia function was invalid: NULL when that’s
21 * not allowed, out of numeric range, bad enum, or violating some
humper@google.com75e3ca12013-04-08 21:44:11 +000022 * other general precondition.
23 */
24 kInvalidArgument_SkError,
skia.committer@gmail.com32840172013-04-09 07:01:27 +000025
26 /** User tried to perform some operation in a state when the operation
27 * was not legal, or the operands make no sense (e.g., asking for
28 * pixels from an SkPictureCanvas). Other examples might be
humper@google.com75e3ca12013-04-08 21:44:11 +000029 * inset()’ing a rectangle to make it degenerate (negative width/height).
30 */
31 kInvalidOperation_SkError,
skia.committer@gmail.com32840172013-04-09 07:01:27 +000032
33 /** Probably not needed right now, but in the future we could have opaque
34 * handles for SkPictures floating around, and it would be a good idea
humper@google.com75e3ca12013-04-08 21:44:11 +000035 * to anticipate this kind of issue.
36 */
37 kInvalidHandle_SkError,
skia.committer@gmail.com32840172013-04-09 07:01:27 +000038
39 /** This is probably not possible because paint surely has defaults for
humper@google.com75e3ca12013-04-08 21:44:11 +000040 * everything, but perhaps a paint can get into a bad state somehow.
41 */
42 kInvalidPaint_SkError,
skia.committer@gmail.com32840172013-04-09 07:01:27 +000043
humper@google.com75e3ca12013-04-08 21:44:11 +000044 /** Skia was unable to allocate memory to perform some task.
45 */
46 kOutOfMemory_SkError,
skia.committer@gmail.com32840172013-04-09 07:01:27 +000047
humper@google.com75e3ca12013-04-08 21:44:11 +000048 /** Skia failed while trying to consume some external resource.
49 */
50 kParseError_SkError
51};
52
53/** Return the current per-thread error code. Error codes are "sticky"; they
54 * are not not reset by subsequent successful operations.
skia.committer@gmail.com32840172013-04-09 07:01:27 +000055 */
humper@google.com75e3ca12013-04-08 21:44:11 +000056SkError SkGetLastError();
57
58/** Clear the current per-thread error code back to kNoError_SkError.
59 */
60void SkClearLastError();
61
62/** Type for callback functions to be invoked whenever an error is registered.
skia.committer@gmail.com32840172013-04-09 07:01:27 +000063 * Callback functions take the error code being set, as well as a context
humper@google.com75e3ca12013-04-08 21:44:11 +000064 * argument that is provided when the callback is registered.
65 */
66typedef void (*SkErrorCallbackFunction)(SkError, void *);
67
68/** Set the current per-thread error callback.
skia.committer@gmail.com32840172013-04-09 07:01:27 +000069 *
humper@google.com75e3ca12013-04-08 21:44:11 +000070 * @param cb The callback function to be invoked. Passing NULL
71 * for cb will revert to the default error callback which
72 * does nothing on release builds, but on debug builds will
73 * print an informative error message to the screen.
skia.committer@gmail.com32840172013-04-09 07:01:27 +000074 * @param context An arbitrary pointer that will be passed to
humper@google.com75e3ca12013-04-08 21:44:11 +000075 * the provided callback function.
76 */
77void SkSetErrorCallback(SkErrorCallbackFunction cb, void *context);
78
skia.committer@gmail.com32840172013-04-09 07:01:27 +000079/** Get a human-readable description of the last (per-thread) error that
80 * occurred. The returned error message will include not only a human
81 * readable version of the error code, but also information about the
humper@google.com75e3ca12013-04-08 21:44:11 +000082 * conditions that led to the error itself.
83 */
84const char *SkGetLastErrorString();
85
86#endif /* SkError_DEFINED */