| 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 | 9 |
| 10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 } | 93 } |
| 94 } | 94 } |
| 95 SkRect rect; | 95 SkRect rect; |
| 96 buffer.readRect(&rect); | 96 buffer.readRect(&rect); |
| 97 if (!buffer.isValid() || !buffer.validate(SkIsValidRect(rect))) { | 97 if (!buffer.isValid() || !buffer.validate(SkIsValidRect(rect))) { |
| 98 return false; | 98 return false; |
| 99 } | 99 } |
| 100 | 100 |
| 101 uint32_t flags = buffer.readUInt(); | 101 uint32_t flags = buffer.readUInt(); |
| 102 fCropRect = CropRect(rect, flags); | 102 fCropRect = CropRect(rect, flags); |
| 103 fUniqueID = buffer.readUInt(); | 103 // FIXME: this is now unused; and should be made conditional on the next SkP
icture version bump. |
| 104 // See skbug.com/3559. |
| 105 (void) buffer.readUInt(); |
| 104 return buffer.isValid(); | 106 return buffer.isValid(); |
| 105 } | 107 } |
| 106 | 108 |
| 107 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 109 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 108 | 110 |
| 109 SkImageFilter::SkImageFilter(int inputCount, SkImageFilter** inputs, const CropR
ect* cropRect, uint32_t uniqueID) | 111 SkImageFilter::SkImageFilter(int inputCount, SkImageFilter** inputs, const CropR
ect* cropRect) |
| 110 : fInputCount(inputCount), | 112 : fInputCount(inputCount), |
| 111 fInputs(new SkImageFilter*[inputCount]), | 113 fInputs(new SkImageFilter*[inputCount]), |
| 112 fUsesSrcInput(false), | 114 fUsesSrcInput(false), |
| 113 fCropRect(cropRect ? *cropRect : CropRect(SkRect(), 0x0)), | 115 fCropRect(cropRect ? *cropRect : CropRect(SkRect(), 0x0)), |
| 114 fUniqueID(uniqueID ? uniqueID : next_image_filter_unique_id()) { | 116 fUniqueID(next_image_filter_unique_id()) { |
| 115 for (int i = 0; i < inputCount; ++i) { | 117 for (int i = 0; i < inputCount; ++i) { |
| 116 if (NULL == inputs[i] || inputs[i]->usesSrcInput()) { | 118 if (NULL == inputs[i] || inputs[i]->usesSrcInput()) { |
| 117 fUsesSrcInput = true; | 119 fUsesSrcInput = true; |
| 118 } | 120 } |
| 119 fInputs[i] = inputs[i]; | 121 fInputs[i] = inputs[i]; |
| 120 SkSafeRef(fInputs[i]); | 122 SkSafeRef(fInputs[i]); |
| 121 } | 123 } |
| 122 } | 124 } |
| 123 | 125 |
| 124 SkImageFilter::~SkImageFilter() { | 126 SkImageFilter::~SkImageFilter() { |
| 125 for (int i = 0; i < fInputCount; i++) { | 127 for (int i = 0; i < fInputCount; i++) { |
| 126 SkSafeUnref(fInputs[i]); | 128 SkSafeUnref(fInputs[i]); |
| 127 } | 129 } |
| 128 delete[] fInputs; | 130 delete[] fInputs; |
| 129 } | 131 } |
| 130 | 132 |
| 131 SkImageFilter::SkImageFilter(int inputCount, SkReadBuffer& buffer) | 133 SkImageFilter::SkImageFilter(int inputCount, SkReadBuffer& buffer) |
| 132 : fUsesSrcInput(false) { | 134 : fUsesSrcInput(false) |
| 135 , fUniqueID(next_image_filter_unique_id()) { |
| 133 Common common; | 136 Common common; |
| 134 if (common.unflatten(buffer, inputCount)) { | 137 if (common.unflatten(buffer, inputCount)) { |
| 135 fCropRect = common.cropRect(); | 138 fCropRect = common.cropRect(); |
| 136 fInputCount = common.inputCount(); | 139 fInputCount = common.inputCount(); |
| 137 fInputs = SkNEW_ARRAY(SkImageFilter*, fInputCount); | 140 fInputs = SkNEW_ARRAY(SkImageFilter*, fInputCount); |
| 138 common.detachInputs(fInputs); | 141 common.detachInputs(fInputs); |
| 139 for (int i = 0; i < fInputCount; ++i) { | 142 for (int i = 0; i < fInputCount; ++i) { |
| 140 if (NULL == fInputs[i] || fInputs[i]->usesSrcInput()) { | 143 if (NULL == fInputs[i] || fInputs[i]->usesSrcInput()) { |
| 141 fUsesSrcInput = true; | 144 fUsesSrcInput = true; |
| 142 } | 145 } |
| 143 } | 146 } |
| 144 fUniqueID = buffer.isCrossProcess() ? next_image_filter_unique_id() : co
mmon.uniqueID(); | |
| 145 } else { | 147 } else { |
| 146 fInputCount = 0; | 148 fInputCount = 0; |
| 147 fInputs = NULL; | 149 fInputs = NULL; |
| 148 } | 150 } |
| 149 } | 151 } |
| 150 | 152 |
| 151 void SkImageFilter::flatten(SkWriteBuffer& buffer) const { | 153 void SkImageFilter::flatten(SkWriteBuffer& buffer) const { |
| 152 buffer.writeInt(fInputCount); | 154 buffer.writeInt(fInputCount); |
| 153 for (int i = 0; i < fInputCount; i++) { | 155 for (int i = 0; i < fInputCount; i++) { |
| 154 SkImageFilter* input = getInput(i); | 156 SkImageFilter* input = getInput(i); |
| 155 buffer.writeBool(input != NULL); | 157 buffer.writeBool(input != NULL); |
| 156 if (input != NULL) { | 158 if (input != NULL) { |
| 157 buffer.writeFlattenable(input); | 159 buffer.writeFlattenable(input); |
| 158 } | 160 } |
| 159 } | 161 } |
| 160 buffer.writeRect(fCropRect.rect()); | 162 buffer.writeRect(fCropRect.rect()); |
| 161 buffer.writeUInt(fCropRect.flags()); | 163 buffer.writeUInt(fCropRect.flags()); |
| 162 buffer.writeUInt(fUniqueID); | 164 // FIXME: this is now unused; and should be removed on the next SkPicture ve
rsion bump. |
| 165 // See skbug.com/3559. |
| 166 buffer.writeUInt(0); |
| 163 } | 167 } |
| 164 | 168 |
| 165 bool SkImageFilter::filterImage(Proxy* proxy, const SkBitmap& src, | 169 bool SkImageFilter::filterImage(Proxy* proxy, const SkBitmap& src, |
| 166 const Context& context, | 170 const Context& context, |
| 167 SkBitmap* result, SkIPoint* offset) const { | 171 SkBitmap* result, SkIPoint* offset) const { |
| 168 SkASSERT(result); | 172 SkASSERT(result); |
| 169 SkASSERT(offset); | 173 SkASSERT(offset); |
| 170 uint32_t srcGenID = fUsesSrcInput ? src.getGenerationID() : 0; | 174 uint32_t srcGenID = fUsesSrcInput ? src.getGenerationID() : 0; |
| 171 Cache::Key key(fUniqueID, context.ctm(), context.clipBounds(), srcGenID); | 175 Cache::Key key(fUniqueID, context.ctm(), context.clipBounds(), srcGenID); |
| 172 if (context.cache()) { | 176 if (context.cache()) { |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 | 489 |
| 486 SkImageFilter::Cache* SkImageFilter::Cache::Create(size_t maxBytes) { | 490 SkImageFilter::Cache* SkImageFilter::Cache::Create(size_t maxBytes) { |
| 487 return SkNEW_ARGS(CacheImpl, (maxBytes)); | 491 return SkNEW_ARGS(CacheImpl, (maxBytes)); |
| 488 } | 492 } |
| 489 | 493 |
| 490 SK_DECLARE_STATIC_LAZY_PTR(SkImageFilter::Cache, cache, CreateCache); | 494 SK_DECLARE_STATIC_LAZY_PTR(SkImageFilter::Cache, cache, CreateCache); |
| 491 | 495 |
| 492 SkImageFilter::Cache* SkImageFilter::Cache::Get() { | 496 SkImageFilter::Cache* SkImageFilter::Cache::Get() { |
| 493 return cache.get(); | 497 return cache.get(); |
| 494 } | 498 } |
| OLD | NEW |