| 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" |
| 11 #include "SkCanvas.h" | 11 #include "SkCanvas.h" |
| 12 #include "SkColorPriv.h" | 12 #include "SkColorPriv.h" |
| 13 #include "SkDevice.h" | 13 #include "SkDevice.h" |
| 14 #include "SkDeviceLooper.h" | 14 #include "SkDeviceLooper.h" |
| 15 #include "SkFixed.h" | 15 #include "SkFixed.h" |
| 16 #include "SkMaskFilter.h" | 16 #include "SkMaskFilter.h" |
| 17 #include "SkPaint.h" | 17 #include "SkPaint.h" |
| 18 #include "SkPathEffect.h" | 18 #include "SkPathEffect.h" |
| 19 #include "SkRasterClip.h" | 19 #include "SkRasterClip.h" |
| 20 #include "SkRasterizer.h" | 20 #include "SkRasterizer.h" |
| 21 #include "SkRRect.h" | 21 #include "SkRRect.h" |
| 22 #include "SkScan.h" | 22 #include "SkScan.h" |
| 23 #include "SkShader.h" | 23 #include "SkShader.h" |
| 24 #include "SkSmallAllocator.h" | 24 #include "SkSmallAllocator.h" |
| 25 #include "SkString.h" | 25 #include "SkString.h" |
| 26 #include "SkStroke.h" | 26 #include "SkStroke.h" |
| 27 #include "SkTLazy.h" | 27 #include "SkTLazy.h" |
| 28 #include "SkUtils.h" | 28 #include "SkUtils.h" |
| 29 #include "SkVertState.h" |
| 29 | 30 |
| 30 #include "SkAutoKern.h" | 31 #include "SkAutoKern.h" |
| 31 #include "SkBitmapProcShader.h" | 32 #include "SkBitmapProcShader.h" |
| 32 #include "SkDrawProcs.h" | 33 #include "SkDrawProcs.h" |
| 33 #include "SkMatrixUtils.h" | 34 #include "SkMatrixUtils.h" |
| 34 | 35 |
| 35 | 36 |
| 36 //#define TRACE_BITMAP_DRAWS | 37 //#define TRACE_BITMAP_DRAWS |
| 37 | 38 |
| 38 | 39 |
| (...skipping 2164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2203 fDevice->drawPath(*this, tmp, iter.getPaint(), NULL, true); | 2204 fDevice->drawPath(*this, tmp, iter.getPaint(), NULL, true); |
| 2204 } else { | 2205 } else { |
| 2205 this->drawPath(tmp, iter.getPaint(), NULL, true); | 2206 this->drawPath(tmp, iter.getPaint(), NULL, true); |
| 2206 } | 2207 } |
| 2207 } | 2208 } |
| 2208 } | 2209 } |
| 2209 } | 2210 } |
| 2210 | 2211 |
| 2211 /////////////////////////////////////////////////////////////////////////////// | 2212 /////////////////////////////////////////////////////////////////////////////// |
| 2212 | 2213 |
| 2213 struct VertState { | |
| 2214 int f0, f1, f2; | |
| 2215 | |
| 2216 VertState(int vCount, const uint16_t indices[], int indexCount) | |
| 2217 : fIndices(indices) { | |
| 2218 fCurrIndex = 0; | |
| 2219 if (indices) { | |
| 2220 fCount = indexCount; | |
| 2221 } else { | |
| 2222 fCount = vCount; | |
| 2223 } | |
| 2224 } | |
| 2225 | |
| 2226 typedef bool (*Proc)(VertState*); | |
| 2227 Proc chooseProc(SkCanvas::VertexMode mode); | |
| 2228 | |
| 2229 private: | |
| 2230 int fCount; | |
| 2231 int fCurrIndex; | |
| 2232 const uint16_t* fIndices; | |
| 2233 | |
| 2234 static bool Triangles(VertState*); | |
| 2235 static bool TrianglesX(VertState*); | |
| 2236 static bool TriangleStrip(VertState*); | |
| 2237 static bool TriangleStripX(VertState*); | |
| 2238 static bool TriangleFan(VertState*); | |
| 2239 static bool TriangleFanX(VertState*); | |
| 2240 }; | |
| 2241 | |
| 2242 bool VertState::Triangles(VertState* state) { | |
| 2243 int index = state->fCurrIndex; | |
| 2244 if (index + 3 > state->fCount) { | |
| 2245 return false; | |
| 2246 } | |
| 2247 state->f0 = index + 0; | |
| 2248 state->f1 = index + 1; | |
| 2249 state->f2 = index + 2; | |
| 2250 state->fCurrIndex = index + 3; | |
| 2251 return true; | |
| 2252 } | |
| 2253 | |
| 2254 bool VertState::TrianglesX(VertState* state) { | |
| 2255 const uint16_t* indices = state->fIndices; | |
| 2256 int index = state->fCurrIndex; | |
| 2257 if (index + 3 > state->fCount) { | |
| 2258 return false; | |
| 2259 } | |
| 2260 state->f0 = indices[index + 0]; | |
| 2261 state->f1 = indices[index + 1]; | |
| 2262 state->f2 = indices[index + 2]; | |
| 2263 state->fCurrIndex = index + 3; | |
| 2264 return true; | |
| 2265 } | |
| 2266 | |
| 2267 bool VertState::TriangleStrip(VertState* state) { | |
| 2268 int index = state->fCurrIndex; | |
| 2269 if (index + 3 > state->fCount) { | |
| 2270 return false; | |
| 2271 } | |
| 2272 state->f2 = index + 2; | |
| 2273 if (index & 1) { | |
| 2274 state->f0 = index + 1; | |
| 2275 state->f1 = index + 0; | |
| 2276 } else { | |
| 2277 state->f0 = index + 0; | |
| 2278 state->f1 = index + 1; | |
| 2279 } | |
| 2280 state->fCurrIndex = index + 1; | |
| 2281 return true; | |
| 2282 } | |
| 2283 | |
| 2284 bool VertState::TriangleStripX(VertState* state) { | |
| 2285 const uint16_t* indices = state->fIndices; | |
| 2286 int index = state->fCurrIndex; | |
| 2287 if (index + 3 > state->fCount) { | |
| 2288 return false; | |
| 2289 } | |
| 2290 state->f2 = indices[index + 2]; | |
| 2291 if (index & 1) { | |
| 2292 state->f0 = indices[index + 1]; | |
| 2293 state->f1 = indices[index + 0]; | |
| 2294 } else { | |
| 2295 state->f0 = indices[index + 0]; | |
| 2296 state->f1 = indices[index + 1]; | |
| 2297 } | |
| 2298 state->fCurrIndex = index + 1; | |
| 2299 return true; | |
| 2300 } | |
| 2301 | |
| 2302 bool VertState::TriangleFan(VertState* state) { | |
| 2303 int index = state->fCurrIndex; | |
| 2304 if (index + 3 > state->fCount) { | |
| 2305 return false; | |
| 2306 } | |
| 2307 state->f0 = 0; | |
| 2308 state->f1 = index + 1; | |
| 2309 state->f2 = index + 2; | |
| 2310 state->fCurrIndex = index + 1; | |
| 2311 return true; | |
| 2312 } | |
| 2313 | |
| 2314 bool VertState::TriangleFanX(VertState* state) { | |
| 2315 const uint16_t* indices = state->fIndices; | |
| 2316 int index = state->fCurrIndex; | |
| 2317 if (index + 3 > state->fCount) { | |
| 2318 return false; | |
| 2319 } | |
| 2320 state->f0 = indices[0]; | |
| 2321 state->f1 = indices[index + 1]; | |
| 2322 state->f2 = indices[index + 2]; | |
| 2323 state->fCurrIndex = index + 1; | |
| 2324 return true; | |
| 2325 } | |
| 2326 | |
| 2327 VertState::Proc VertState::chooseProc(SkCanvas::VertexMode mode) { | |
| 2328 switch (mode) { | |
| 2329 case SkCanvas::kTriangles_VertexMode: | |
| 2330 return fIndices ? TrianglesX : Triangles; | |
| 2331 case SkCanvas::kTriangleStrip_VertexMode: | |
| 2332 return fIndices ? TriangleStripX : TriangleStrip; | |
| 2333 case SkCanvas::kTriangleFan_VertexMode: | |
| 2334 return fIndices ? TriangleFanX : TriangleFan; | |
| 2335 default: | |
| 2336 return NULL; | |
| 2337 } | |
| 2338 } | |
| 2339 | |
| 2340 typedef void (*HairProc)(const SkPoint&, const SkPoint&, const SkRasterClip&, | 2214 typedef void (*HairProc)(const SkPoint&, const SkPoint&, const SkRasterClip&, |
| 2341 SkBlitter*); | 2215 SkBlitter*); |
| 2342 | 2216 |
| 2343 static HairProc ChooseHairProc(bool doAntiAlias) { | 2217 static HairProc ChooseHairProc(bool doAntiAlias) { |
| 2344 return doAntiAlias ? SkScan::AntiHairLine : SkScan::HairLine; | 2218 return doAntiAlias ? SkScan::AntiHairLine : SkScan::HairLine; |
| 2345 } | 2219 } |
| 2346 | 2220 |
| 2347 static bool texture_to_matrix(const VertState& state, const SkPoint verts[], | 2221 static bool texture_to_matrix(const VertState& state, const SkPoint verts[], |
| 2348 const SkPoint texs[], SkMatrix* matrix) { | 2222 const SkPoint texs[], SkMatrix* matrix) { |
| 2349 SkPoint src[3], dst[3]; | 2223 SkPoint src[3], dst[3]; |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2606 continue; | 2480 continue; |
| 2607 } | 2481 } |
| 2608 } | 2482 } |
| 2609 | 2483 |
| 2610 SkPoint tmp[] = { | 2484 SkPoint tmp[] = { |
| 2611 devVerts[state.f0], devVerts[state.f1], devVerts[state.f2] | 2485 devVerts[state.f0], devVerts[state.f1], devVerts[state.f2] |
| 2612 }; | 2486 }; |
| 2613 SkScan::FillTriangle(tmp, *fRC, blitter.get()); | 2487 SkScan::FillTriangle(tmp, *fRC, blitter.get()); |
| 2614 } | 2488 } |
| 2615 } else { | 2489 } else { |
| 2616 // no colors[] and no texture | 2490 // no colors[] and no texture, stroke hairlines with paint's color. |
| 2617 HairProc hairProc = ChooseHairProc(paint.isAntiAlias()); | 2491 HairProc hairProc = ChooseHairProc(paint.isAntiAlias()); |
| 2618 const SkRasterClip& clip = *fRC; | 2492 const SkRasterClip& clip = *fRC; |
| 2619 while (vertProc(&state)) { | 2493 while (vertProc(&state)) { |
| 2620 hairProc(devVerts[state.f0], devVerts[state.f1], clip, blitter.get()
); | 2494 hairProc(devVerts[state.f0], devVerts[state.f1], clip, blitter.get()
); |
| 2621 hairProc(devVerts[state.f1], devVerts[state.f2], clip, blitter.get()
); | 2495 hairProc(devVerts[state.f1], devVerts[state.f2], clip, blitter.get()
); |
| 2622 hairProc(devVerts[state.f2], devVerts[state.f0], clip, blitter.get()
); | 2496 hairProc(devVerts[state.f2], devVerts[state.f0], clip, blitter.get()
); |
| 2623 } | 2497 } |
| 2624 } | 2498 } |
| 2625 } | 2499 } |
| 2626 | 2500 |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2836 mask->fImage = SkMask::AllocImage(size); | 2710 mask->fImage = SkMask::AllocImage(size); |
| 2837 memset(mask->fImage, 0, mask->computeImageSize()); | 2711 memset(mask->fImage, 0, mask->computeImageSize()); |
| 2838 } | 2712 } |
| 2839 | 2713 |
| 2840 if (SkMask::kJustComputeBounds_CreateMode != mode) { | 2714 if (SkMask::kJustComputeBounds_CreateMode != mode) { |
| 2841 draw_into_mask(*mask, devPath, style); | 2715 draw_into_mask(*mask, devPath, style); |
| 2842 } | 2716 } |
| 2843 | 2717 |
| 2844 return true; | 2718 return true; |
| 2845 } | 2719 } |
| OLD | NEW |