OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkCanvasPriv_DEFINED | 8 #ifndef SkCanvasPriv_DEFINED |
9 #define SkCanvasPriv_DEFINED | 9 #define SkCanvasPriv_DEFINED |
10 | 10 |
11 #include "SkCanvas.h" | 11 #include "SkCanvas.h" |
| 12 #include "SkData.h" |
12 | 13 |
13 class SkAutoCanvasMatrixPaint : SkNoncopyable { | 14 class SkAutoCanvasMatrixPaint : SkNoncopyable { |
14 public: | 15 public: |
15 SkAutoCanvasMatrixPaint(SkCanvas*, const SkMatrix*, const SkPaint*, const Sk
Rect& bounds); | 16 SkAutoCanvasMatrixPaint(SkCanvas*, const SkMatrix*, const SkPaint*, const Sk
Rect& bounds); |
16 ~SkAutoCanvasMatrixPaint(); | 17 ~SkAutoCanvasMatrixPaint(); |
17 | 18 |
18 private: | 19 private: |
19 SkCanvas* fCanvas; | 20 SkCanvas* fCanvas; |
20 int fSaveCount; | 21 int fSaveCount; |
21 }; | 22 }; |
22 | 23 |
| 24 /** |
| 25 * Allows NinePatchDivs to be serialized to and from data. |
| 26 */ |
| 27 struct SkNinePatchDivs : SkCanvas::NinePatchDivs { |
| 28 |
| 29 sk_sp<SkData> asData() const { |
| 30 sk_sp<SkData> data = SkData::MakeUninitialized(sizeof(int32_t) * (2 + fX
Count + fYCount)); |
| 31 int32_t* ptr = (int32_t*) data->writable_data(); |
| 32 ptr[0] = fXCount; |
| 33 ptr[1] = fYCount; |
| 34 memcpy(&ptr[2], fXDivs, sizeof(int32_t) * fXCount); |
| 35 memcpy(&ptr[2 + fXCount], fYDivs, sizeof(int32_t) * fYCount); |
| 36 return data; |
| 37 } |
| 38 |
| 39 static NinePatchDivs FromData(SkData* data) { |
| 40 int32_t* ptr = (int32_t*) data->writable_data(); |
| 41 NinePatchDivs divs; |
| 42 divs.fXCount = ptr[0]; |
| 43 divs.fYCount = ptr[1]; |
| 44 divs.fXDivs = &ptr[2]; |
| 45 divs.fYDivs = &ptr[2 + divs.fXCount]; |
| 46 return divs; |
| 47 } |
| 48 }; |
| 49 |
23 #endif | 50 #endif |
OLD | NEW |