1 /*
2 * Copyright 2022 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #ifndef SkDebugUtils_DEFINED
9 #define SkDebugUtils_DEFINED
10
11 #include "include/core/SkTileMode.h"
12 #include "include/private/base/SkAssert.h"
13 #include "include/private/base/SkDebug.h"
14
15 #include <array>
16 #include <cstdint>
17
SkTileModeToStr(SkTileMode tm)18 static constexpr const char* SkTileModeToStr(SkTileMode tm) {
19 switch (tm) {
20 case SkTileMode::kClamp: return "Clamp";
21 case SkTileMode::kRepeat: return "Repeat";
22 case SkTileMode::kMirror: return "Mirror";
23 case SkTileMode::kDecal: return "Decal";
24 }
25 SkUNREACHABLE;
26 }
27
28 #if defined(SK_DEBUG)
29 inline void SkDumpBuffer(uint8_t const* const buffer, int w, int h, int rowBytes,
30 bool dumpActualValues = false) {
31 SkASSERT(buffer);
32
33 static constexpr char shades[] = {'0', '1', '2', '3', '4', '5', '6', '7',
34 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
35
36 for (int y = 0; y < h; ++y) {
37 for (int x = 0; x < w; ++x) {
38 uint8_t pixelValue = buffer[y * rowBytes + x];
39 if (dumpActualValues) {
40 SkDebugf("%u\t", pixelValue);
41 } else {
42 int idx = static_cast<int>(pixelValue * std::size(shades) / 256);
43 SkASSERT(idx >= 0 && idx < (int)std::size(shades));
44 SkDebugf("%c", shades[idx]);
45 }
46 }
47 SkDebugf("\n");
48 }
49 }
50 #else
SkDumpBuffer(uint8_t *,int,int,int)51 inline void SkDumpBuffer(uint8_t*, int, int, int) {}
52 #endif
53
54
55 #endif // SkDebugUtils_DEFINED
56