OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 The Android Open Source Project | 2 * Copyright 2012 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 "SkImageFilter.h" | 8 #include "SkImageFilter.h" |
9 #include "SkImageFilterCacheKey.h" | 9 #include "SkImageFilterCacheKey.h" |
10 | 10 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 static int32_t gImageFilterUniqueID; | 98 static int32_t gImageFilterUniqueID; |
99 | 99 |
100 // Never return 0. | 100 // Never return 0. |
101 int32_t id; | 101 int32_t id; |
102 do { | 102 do { |
103 id = sk_atomic_inc(&gImageFilterUniqueID) + 1; | 103 id = sk_atomic_inc(&gImageFilterUniqueID) + 1; |
104 } while (0 == id); | 104 } while (0 == id); |
105 return id; | 105 return id; |
106 } | 106 } |
107 | 107 |
108 SkImageFilter::Common::~Common() { | 108 void SkImageFilter::Common::allocInputs(int count) { |
| 109 fInputs.reset(count); |
| 110 } |
| 111 |
| 112 void SkImageFilter::Common::detachInputs(SkImageFilter** inputs) { |
109 for (int i = 0; i < fInputs.count(); ++i) { | 113 for (int i = 0; i < fInputs.count(); ++i) { |
110 SkSafeUnref(fInputs[i]); | 114 inputs[i] = fInputs[i].release(); |
111 } | 115 } |
112 } | 116 } |
113 | 117 |
114 void SkImageFilter::Common::allocInputs(int count) { | |
115 const size_t size = count * sizeof(SkImageFilter*); | |
116 fInputs.reset(count); | |
117 sk_bzero(fInputs.get(), size); | |
118 } | |
119 | |
120 void SkImageFilter::Common::detachInputs(SkImageFilter** inputs) { | |
121 const size_t size = fInputs.count() * sizeof(SkImageFilter*); | |
122 memcpy(inputs, fInputs.get(), size); | |
123 sk_bzero(fInputs.get(), size); | |
124 } | |
125 | |
126 bool SkImageFilter::Common::unflatten(SkReadBuffer& buffer, int expectedCount) { | 118 bool SkImageFilter::Common::unflatten(SkReadBuffer& buffer, int expectedCount) { |
127 const int count = buffer.readInt(); | 119 const int count = buffer.readInt(); |
128 if (!buffer.validate(count >= 0)) { | 120 if (!buffer.validate(count >= 0)) { |
129 return false; | 121 return false; |
130 } | 122 } |
131 if (!buffer.validate(expectedCount < 0 || count == expectedCount)) { | 123 if (!buffer.validate(expectedCount < 0 || count == expectedCount)) { |
132 return false; | 124 return false; |
133 } | 125 } |
134 | 126 |
135 this->allocInputs(count); | 127 this->allocInputs(count); |
136 for (int i = 0; i < count; i++) { | 128 for (int i = 0; i < count; i++) { |
137 if (buffer.readBool()) { | 129 if (buffer.readBool()) { |
138 fInputs[i] = buffer.readImageFilter(); | 130 fInputs[i] = sk_sp<SkImageFilter>(buffer.readImageFilter()); |
139 } | 131 } |
140 if (!buffer.isValid()) { | 132 if (!buffer.isValid()) { |
141 return false; | 133 return false; |
142 } | 134 } |
143 } | 135 } |
144 SkRect rect; | 136 SkRect rect; |
145 buffer.readRect(&rect); | 137 buffer.readRect(&rect); |
146 if (!buffer.isValid() || !buffer.validate(SkIsValidRect(rect))) { | 138 if (!buffer.isValid() || !buffer.validate(SkIsValidRect(rect))) { |
147 return false; | 139 return false; |
148 } | 140 } |
(...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
813 dev = SkBitmapDevice::Create(cinfo.fInfo, surfaceProps); | 805 dev = SkBitmapDevice::Create(cinfo.fInfo, surfaceProps); |
814 } | 806 } |
815 return dev; | 807 return dev; |
816 } | 808 } |
817 | 809 |
818 bool SkImageFilter::DeviceProxy::filterImage(const SkImageFilter* filter, const
SkBitmap& src, | 810 bool SkImageFilter::DeviceProxy::filterImage(const SkImageFilter* filter, const
SkBitmap& src, |
819 const SkImageFilter::Context& ctx, | 811 const SkImageFilter::Context& ctx, |
820 SkBitmap* result, SkIPoint* offset) { | 812 SkBitmap* result, SkIPoint* offset) { |
821 return fDevice->filterImage(filter, src, ctx, result, offset); | 813 return fDevice->filterImage(filter, src, ctx, result, offset); |
822 } | 814 } |
OLD | NEW |