Debian Codegraph @

docs/examples/Path_readFromMemory.cpp

raw
1 // Copyright 2019 Google LLC.
2 // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
3 #include "tools/fiddle/examples.h"
4 REG_FIDDLE(Path_readFromMemory, 256, 256, true, 0) {
5 void draw(SkCanvas* canvas) {
6 SkPath path = SkPath::Line({1, 2}, {3, 4});
7 size_t size = path.writeToMemory(nullptr);
8 SkTDArray<char> storage;
9 storage.resize(size);
10 path.writeToMemory(storage.begin());
11 size_t wrongSize = size - 4;
12 auto copy = SkPath::ReadFromMemory(storage.begin(), wrongSize);
13 SkDebugf("Path is valid = %d; for size = %zu\n", copy.has_value(), wrongSize);
14
15 size_t largerSize = size + 4;
16 size_t bytesRead;
17 copy = SkPath::ReadFromMemory(storage.begin(), largerSize, &bytesRead);
18 SkDebugf("Path is valid = %d, length = %zu; returned by readFromMemory = %zu\n",
19 copy.has_value(), largerSize, bytesRead);
20 }
21 } // END FIDDLE