OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
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 #include "SkDraw.h" | 8 #include "SkDraw.h" |
9 #include "SkBlitter.h" | 9 #include "SkBlitter.h" |
10 #include "SkBounder.h" | 10 #include "SkBounder.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 public: | 58 public: |
59 SkAutoBlitterChoose() { | 59 SkAutoBlitterChoose() { |
60 fBlitter = NULL; | 60 fBlitter = NULL; |
61 } | 61 } |
62 SkAutoBlitterChoose(const SkBitmap& device, const SkMatrix& matrix, | 62 SkAutoBlitterChoose(const SkBitmap& device, const SkMatrix& matrix, |
63 const SkPaint& paint, bool drawCoverage = false) { | 63 const SkPaint& paint, bool drawCoverage = false) { |
64 fBlitter = SkBlitter::Choose(device, matrix, paint, | 64 fBlitter = SkBlitter::Choose(device, matrix, paint, |
65 fStorage, sizeof(fStorage), drawCoverage); | 65 fStorage, sizeof(fStorage), drawCoverage); |
66 } | 66 } |
67 | 67 |
68 ~SkAutoBlitterChoose(); | 68 ~SkAutoBlitterChoose() { |
| 69 if ((void*)fBlitter == (void*)fStorage) { |
| 70 fBlitter->~SkBlitter(); |
| 71 } else { |
| 72 SkDELETE(fBlitter); |
| 73 } |
| 74 } |
69 | 75 |
70 SkBlitter* operator->() { return fBlitter; } | 76 SkBlitter* operator->() { return fBlitter; } |
71 SkBlitter* get() const { return fBlitter; } | 77 SkBlitter* get() const { return fBlitter; } |
72 | 78 |
73 void choose(const SkBitmap& device, const SkMatrix& matrix, | 79 void choose(const SkBitmap& device, const SkMatrix& matrix, |
74 const SkPaint& paint) { | 80 const SkPaint& paint) { |
75 SkASSERT(!fBlitter); | 81 SkASSERT(!fBlitter); |
76 fBlitter = SkBlitter::Choose(device, matrix, paint, | 82 fBlitter = SkBlitter::Choose(device, matrix, paint, |
77 fStorage, sizeof(fStorage)); | 83 fStorage, sizeof(fStorage)); |
78 } | 84 } |
79 | 85 |
80 private: | 86 private: |
81 SkBlitter* fBlitter; | 87 SkBlitter* fBlitter; |
82 uint32_t fStorage[kBlitterStorageLongCount]; | 88 uint32_t fStorage[kBlitterStorageLongCount]; |
83 }; | 89 }; |
84 | 90 #define SkAutoBlitterChoose(...) SK_REQUIRE_LOCAL_VAR(SkAutoBlitterChoose) |
85 SkAutoBlitterChoose::~SkAutoBlitterChoose() { | |
86 if ((void*)fBlitter == (void*)fStorage) { | |
87 fBlitter->~SkBlitter(); | |
88 } else { | |
89 SkDELETE(fBlitter); | |
90 } | |
91 } | |
92 | 91 |
93 /** | 92 /** |
94 * Since we are providing the storage for the shader (to avoid the perf cost | 93 * Since we are providing the storage for the shader (to avoid the perf cost |
95 * of calling new) we insist that in our destructor we can account for all | 94 * of calling new) we insist that in our destructor we can account for all |
96 * owners of the shader. | 95 * owners of the shader. |
97 */ | 96 */ |
98 class SkAutoBitmapShaderInstall : SkNoncopyable { | 97 class SkAutoBitmapShaderInstall : SkNoncopyable { |
99 public: | 98 public: |
100 SkAutoBitmapShaderInstall(const SkBitmap& src, const SkPaint& paint) | 99 SkAutoBitmapShaderInstall(const SkBitmap& src, const SkPaint& paint) |
101 : fPaint(paint) /* makes a copy of the paint */ { | 100 : fPaint(paint) /* makes a copy of the paint */ { |
(...skipping 19 matching lines...) Expand all Loading... |
121 } | 120 } |
122 } | 121 } |
123 | 122 |
124 // return the new paint that has the shader applied | 123 // return the new paint that has the shader applied |
125 const SkPaint& paintWithShader() const { return fPaint; } | 124 const SkPaint& paintWithShader() const { return fPaint; } |
126 | 125 |
127 private: | 126 private: |
128 SkPaint fPaint; // copy of caller's paint (which we then modify) | 127 SkPaint fPaint; // copy of caller's paint (which we then modify) |
129 uint32_t fStorage[kBlitterStorageLongCount]; | 128 uint32_t fStorage[kBlitterStorageLongCount]; |
130 }; | 129 }; |
| 130 #define SkAutoBitmapShaderInstall(...) SK_REQUIRE_LOCAL_VAR(SkAutoBitmapShaderIn
stall) |
131 | 131 |
132 /////////////////////////////////////////////////////////////////////////////// | 132 /////////////////////////////////////////////////////////////////////////////// |
133 | 133 |
134 SkDraw::SkDraw() { | 134 SkDraw::SkDraw() { |
135 sk_bzero(this, sizeof(*this)); | 135 sk_bzero(this, sizeof(*this)); |
136 } | 136 } |
137 | 137 |
138 SkDraw::SkDraw(const SkDraw& src) { | 138 SkDraw::SkDraw(const SkDraw& src) { |
139 memcpy(this, &src, sizeof(*this)); | 139 memcpy(this, &src, sizeof(*this)); |
140 } | 140 } |
(...skipping 2738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2879 mask->fImage = SkMask::AllocImage(size); | 2879 mask->fImage = SkMask::AllocImage(size); |
2880 memset(mask->fImage, 0, mask->computeImageSize()); | 2880 memset(mask->fImage, 0, mask->computeImageSize()); |
2881 } | 2881 } |
2882 | 2882 |
2883 if (SkMask::kJustComputeBounds_CreateMode != mode) { | 2883 if (SkMask::kJustComputeBounds_CreateMode != mode) { |
2884 draw_into_mask(*mask, devPath, style); | 2884 draw_into_mask(*mask, devPath, style); |
2885 } | 2885 } |
2886 | 2886 |
2887 return true; | 2887 return true; |
2888 } | 2888 } |
OLD | NEW |