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 "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 fDevice->drawRect(*this, r, newPaint); | 621 fDevice->drawRect(*this, r, newPaint); |
622 } else { | 622 } else { |
623 this->drawRect(r, newPaint); | 623 this->drawRect(r, newPaint); |
624 } | 624 } |
625 } | 625 } |
626 } | 626 } |
627 break; | 627 break; |
628 } | 628 } |
629 case SkCanvas::kLines_PointMode: | 629 case SkCanvas::kLines_PointMode: |
630 #ifndef SK_DISABLE_DASHING_OPTIMIZATION | 630 #ifndef SK_DISABLE_DASHING_OPTIMIZATION |
631 if (2 == count && NULL != paint.getPathEffect()) { | 631 if (2 == count && paint.getPathEffect()) { |
632 // most likely a dashed line - see if it is one of the ones | 632 // most likely a dashed line - see if it is one of the ones |
633 // we can accelerate | 633 // we can accelerate |
634 SkStrokeRec rec(paint); | 634 SkStrokeRec rec(paint); |
635 SkPathEffect::PointData pointData; | 635 SkPathEffect::PointData pointData; |
636 | 636 |
637 SkPath path; | 637 SkPath path; |
638 path.moveTo(pts[0]); | 638 path.moveTo(pts[0]); |
639 path.lineTo(pts[1]); | 639 path.lineTo(pts[1]); |
640 | 640 |
641 SkRect cullRect = SkRect::Make(fRC->getBounds()); | 641 SkRect cullRect = SkRect::Make(fRC->getBounds()); |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
932 return false; | 932 return false; |
933 } | 933 } |
934 | 934 |
935 SkVector src[2], dst[2]; | 935 SkVector src[2], dst[2]; |
936 src[0].set(strokeWidth, 0); | 936 src[0].set(strokeWidth, 0); |
937 src[1].set(0, strokeWidth); | 937 src[1].set(0, strokeWidth); |
938 matrix.mapVectors(dst, src, 2); | 938 matrix.mapVectors(dst, src, 2); |
939 SkScalar len0 = fast_len(dst[0]); | 939 SkScalar len0 = fast_len(dst[0]); |
940 SkScalar len1 = fast_len(dst[1]); | 940 SkScalar len1 = fast_len(dst[1]); |
941 if (len0 <= SK_Scalar1 && len1 <= SK_Scalar1) { | 941 if (len0 <= SK_Scalar1 && len1 <= SK_Scalar1) { |
942 if (NULL != coverage) { | 942 if (coverage) { |
943 *coverage = SkScalarAve(len0, len1); | 943 *coverage = SkScalarAve(len0, len1); |
944 } | 944 } |
945 return true; | 945 return true; |
946 } | 946 } |
947 return false; | 947 return false; |
948 } | 948 } |
949 | 949 |
950 void SkDraw::drawRRect(const SkRRect& rrect, const SkPaint& paint) const { | 950 void SkDraw::drawRRect(const SkRRect& rrect, const SkPaint& paint) const { |
951 SkDEBUGCODE(this->validate()); | 951 SkDEBUGCODE(this->validate()); |
952 | 952 |
(...skipping 1170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2123 | 2123 |
2124 str->append(")"); | 2124 str->append(")"); |
2125 } | 2125 } |
2126 #endif | 2126 #endif |
2127 | 2127 |
2128 void SkDraw::drawVertices(SkCanvas::VertexMode vmode, int count, | 2128 void SkDraw::drawVertices(SkCanvas::VertexMode vmode, int count, |
2129 const SkPoint vertices[], const SkPoint textures[], | 2129 const SkPoint vertices[], const SkPoint textures[], |
2130 const SkColor colors[], SkXfermode* xmode, | 2130 const SkColor colors[], SkXfermode* xmode, |
2131 const uint16_t indices[], int indexCount, | 2131 const uint16_t indices[], int indexCount, |
2132 const SkPaint& paint) const { | 2132 const SkPaint& paint) const { |
2133 SkASSERT(0 == count || NULL != vertices); | 2133 SkASSERT(0 == count || vertices); |
2134 | 2134 |
2135 // abort early if there is nothing to draw | 2135 // abort early if there is nothing to draw |
2136 if (count < 3 || (indices && indexCount < 3) || fRC->isEmpty()) { | 2136 if (count < 3 || (indices && indexCount < 3) || fRC->isEmpty()) { |
2137 return; | 2137 return; |
2138 } | 2138 } |
2139 | 2139 |
2140 // transform out vertices into device coordinates | 2140 // transform out vertices into device coordinates |
2141 SkAutoSTMalloc<16, SkPoint> storage(count); | 2141 SkAutoSTMalloc<16, SkPoint> storage(count); |
2142 SkPoint* devVerts = storage.get(); | 2142 SkPoint* devVerts = storage.get(); |
2143 fMatrix->mapPoints(devVerts, vertices, count); | 2143 fMatrix->mapPoints(devVerts, vertices, count); |
(...skipping 17 matching lines...) Expand all Loading... |
2161 // if we have no shader, we ignore the texture coordinates | 2161 // if we have no shader, we ignore the texture coordinates |
2162 textures = NULL; | 2162 textures = NULL; |
2163 } else if (NULL == textures) { | 2163 } else if (NULL == textures) { |
2164 // if we don't have texture coordinates, ignore the shader | 2164 // if we don't have texture coordinates, ignore the shader |
2165 p.setShader(NULL); | 2165 p.setShader(NULL); |
2166 shader = NULL; | 2166 shader = NULL; |
2167 } | 2167 } |
2168 | 2168 |
2169 // setup the custom shader (if needed) | 2169 // setup the custom shader (if needed) |
2170 SkAutoTUnref<SkComposeShader> composeShader; | 2170 SkAutoTUnref<SkComposeShader> composeShader; |
2171 if (NULL != colors) { | 2171 if (colors) { |
2172 if (NULL == textures) { | 2172 if (NULL == textures) { |
2173 // just colors (no texture) | 2173 // just colors (no texture) |
2174 shader = p.setShader(&triShader); | 2174 shader = p.setShader(&triShader); |
2175 } else { | 2175 } else { |
2176 // colors * texture | 2176 // colors * texture |
2177 SkASSERT(shader); | 2177 SkASSERT(shader); |
2178 bool releaseMode = false; | 2178 bool releaseMode = false; |
2179 if (NULL == xmode) { | 2179 if (NULL == xmode) { |
2180 xmode = SkXfermode::Create(SkXfermode::kModulate_Mode); | 2180 xmode = SkXfermode::Create(SkXfermode::kModulate_Mode); |
2181 releaseMode = true; | 2181 releaseMode = true; |
2182 } | 2182 } |
2183 composeShader.reset(SkNEW_ARGS(SkComposeShader, (&triShader, shader,
xmode))); | 2183 composeShader.reset(SkNEW_ARGS(SkComposeShader, (&triShader, shader,
xmode))); |
2184 p.setShader(composeShader); | 2184 p.setShader(composeShader); |
2185 if (releaseMode) { | 2185 if (releaseMode) { |
2186 xmode->unref(); | 2186 xmode->unref(); |
2187 } | 2187 } |
2188 } | 2188 } |
2189 } | 2189 } |
2190 | 2190 |
2191 SkAutoBlitterChoose blitter(*fBitmap, *fMatrix, p); | 2191 SkAutoBlitterChoose blitter(*fBitmap, *fMatrix, p); |
2192 // Abort early if we failed to create a shader context. | 2192 // Abort early if we failed to create a shader context. |
2193 if (blitter->isNullBlitter()) { | 2193 if (blitter->isNullBlitter()) { |
2194 return; | 2194 return; |
2195 } | 2195 } |
2196 | 2196 |
2197 // setup our state and function pointer for iterating triangles | 2197 // setup our state and function pointer for iterating triangles |
2198 VertState state(count, indices, indexCount); | 2198 VertState state(count, indices, indexCount); |
2199 VertState::Proc vertProc = state.chooseProc(vmode); | 2199 VertState::Proc vertProc = state.chooseProc(vmode); |
2200 | 2200 |
2201 if (NULL != textures || NULL != colors) { | 2201 if (textures || colors) { |
2202 while (vertProc(&state)) { | 2202 while (vertProc(&state)) { |
2203 if (NULL != textures) { | 2203 if (textures) { |
2204 SkMatrix tempM; | 2204 SkMatrix tempM; |
2205 if (texture_to_matrix(state, vertices, textures, &tempM)) { | 2205 if (texture_to_matrix(state, vertices, textures, &tempM)) { |
2206 SkShader::ContextRec rec(*fBitmap, p, *fMatrix); | 2206 SkShader::ContextRec rec(*fBitmap, p, *fMatrix); |
2207 rec.fLocalMatrix = &tempM; | 2207 rec.fLocalMatrix = &tempM; |
2208 if (!blitter->resetShaderContext(rec)) { | 2208 if (!blitter->resetShaderContext(rec)) { |
2209 continue; | 2209 continue; |
2210 } | 2210 } |
2211 } | 2211 } |
2212 } | 2212 } |
2213 if (NULL != colors) { | 2213 if (colors) { |
2214 // Find the context for triShader. | 2214 // Find the context for triShader. |
2215 SkTriColorShader::TriColorShaderContext* triColorShaderContext; | 2215 SkTriColorShader::TriColorShaderContext* triColorShaderContext; |
2216 | 2216 |
2217 SkShader::Context* shaderContext = blitter->getShaderContext(); | 2217 SkShader::Context* shaderContext = blitter->getShaderContext(); |
2218 SkASSERT(shaderContext); | 2218 SkASSERT(shaderContext); |
2219 if (p.getShader() == &triShader) { | 2219 if (p.getShader() == &triShader) { |
2220 triColorShaderContext = | 2220 triColorShaderContext = |
2221 static_cast<SkTriColorShader::TriColorShaderContext*
>(shaderContext); | 2221 static_cast<SkTriColorShader::TriColorShaderContext*
>(shaderContext); |
2222 } else { | 2222 } else { |
2223 // The shader is a compose shader and triShader is its first
shader. | 2223 // The shader is a compose shader and triShader is its first
shader. |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2373 mask->fImage = SkMask::AllocImage(size); | 2373 mask->fImage = SkMask::AllocImage(size); |
2374 memset(mask->fImage, 0, mask->computeImageSize()); | 2374 memset(mask->fImage, 0, mask->computeImageSize()); |
2375 } | 2375 } |
2376 | 2376 |
2377 if (SkMask::kJustComputeBounds_CreateMode != mode) { | 2377 if (SkMask::kJustComputeBounds_CreateMode != mode) { |
2378 draw_into_mask(*mask, devPath, style); | 2378 draw_into_mask(*mask, devPath, style); |
2379 } | 2379 } |
2380 | 2380 |
2381 return true; | 2381 return true; |
2382 } | 2382 } |
OLD | NEW |