OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "SkPDFShader.h" | 10 #include "SkPDFShader.h" |
(...skipping 1092 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1103 fPixelGeneration(0) { | 1103 fPixelGeneration(0) { |
1104 fInfo.fColorCount = 0; | 1104 fInfo.fColorCount = 0; |
1105 fInfo.fColors = NULL; | 1105 fInfo.fColors = NULL; |
1106 fInfo.fColorOffsets = NULL; | 1106 fInfo.fColorOffsets = NULL; |
1107 fShaderTransform = shader.getLocalMatrix(); | 1107 fShaderTransform = shader.getLocalMatrix(); |
1108 fImageTileModes[0] = fImageTileModes[1] = SkShader::kClamp_TileMode; | 1108 fImageTileModes[0] = fImageTileModes[1] = SkShader::kClamp_TileMode; |
1109 | 1109 |
1110 fType = shader.asAGradient(&fInfo); | 1110 fType = shader.asAGradient(&fInfo); |
1111 | 1111 |
1112 if (fType == SkShader::kNone_GradientType) { | 1112 if (fType == SkShader::kNone_GradientType) { |
1113 SkShader::BitmapType bitmapType; | |
1114 SkMatrix matrix; | 1113 SkMatrix matrix; |
1115 bitmapType = shader.asABitmap(&fImage, &matrix, fImageTileModes); | 1114 if (shader.isABitmap(&fImage, &matrix, fImageTileModes)) { |
1116 if (bitmapType != SkShader::kDefault_BitmapType) { | 1115 SkASSERT(matrix.isIdentity()); |
| 1116 } else { |
1117 // Generic fallback for unsupported shaders: | 1117 // Generic fallback for unsupported shaders: |
1118 // * allocate a bbox-sized bitmap | 1118 // * allocate a bbox-sized bitmap |
1119 // * shade the whole area | 1119 // * shade the whole area |
1120 // * use the result as a bitmap shader | 1120 // * use the result as a bitmap shader |
1121 | 1121 |
1122 // bbox is in device space. While that's exactly what we want for si
zing our bitmap, | 1122 // bbox is in device space. While that's exactly what we want for si
zing our bitmap, |
1123 // we need to map it into shader space for adjustments (to match | 1123 // we need to map it into shader space for adjustments (to match |
1124 // SkPDFImageShader::Create's behavior). | 1124 // SkPDFImageShader::Create's behavior). |
1125 SkRect shaderRect = SkRect::Make(bbox); | 1125 SkRect shaderRect = SkRect::Make(bbox); |
1126 if (!inverse_transform_bbox(canvasTransform, &shaderRect)) { | 1126 if (!inverse_transform_bbox(canvasTransform, &shaderRect)) { |
(...skipping 19 matching lines...) Expand all Loading... |
1146 SkPaint p; | 1146 SkPaint p; |
1147 p.setShader(const_cast<SkShader*>(&shader)); | 1147 p.setShader(const_cast<SkShader*>(&shader)); |
1148 | 1148 |
1149 SkCanvas canvas(fImage); | 1149 SkCanvas canvas(fImage); |
1150 canvas.scale(scale.width(), scale.height()); | 1150 canvas.scale(scale.width(), scale.height()); |
1151 canvas.translate(-shaderRect.x(), -shaderRect.y()); | 1151 canvas.translate(-shaderRect.x(), -shaderRect.y()); |
1152 canvas.drawPaint(p); | 1152 canvas.drawPaint(p); |
1153 | 1153 |
1154 fShaderTransform.setTranslate(shaderRect.x(), shaderRect.y()); | 1154 fShaderTransform.setTranslate(shaderRect.x(), shaderRect.y()); |
1155 fShaderTransform.preScale(1 / scale.width(), 1 / scale.height()); | 1155 fShaderTransform.preScale(1 / scale.width(), 1 / scale.height()); |
1156 } else { | |
1157 SkASSERT(matrix.isIdentity()); | |
1158 } | 1156 } |
1159 fPixelGeneration = fImage.getGenerationID(); | 1157 fPixelGeneration = fImage.getGenerationID(); |
1160 } else { | 1158 } else { |
1161 AllocateGradientInfoStorage(); | 1159 AllocateGradientInfoStorage(); |
1162 shader.asAGradient(&fInfo); | 1160 shader.asAGradient(&fInfo); |
1163 } | 1161 } |
1164 } | 1162 } |
1165 | 1163 |
1166 SkPDFShader::State::State(const SkPDFShader::State& other) | 1164 SkPDFShader::State::State(const SkPDFShader::State& other) |
1167 : fType(other.fType), | 1165 : fType(other.fType), |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1234 return false; | 1232 return false; |
1235 } | 1233 } |
1236 | 1234 |
1237 void SkPDFShader::State::AllocateGradientInfoStorage() { | 1235 void SkPDFShader::State::AllocateGradientInfoStorage() { |
1238 fColorData.set(sk_malloc_throw( | 1236 fColorData.set(sk_malloc_throw( |
1239 fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar)))); | 1237 fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar)))); |
1240 fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get()); | 1238 fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get()); |
1241 fInfo.fColorOffsets = | 1239 fInfo.fColorOffsets = |
1242 reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount); | 1240 reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount); |
1243 } | 1241 } |
OLD | NEW |