| 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 "SkVertState.h" |
| 9 #include "SkBlitter.h" | 10 #include "SkBlitter.h" |
| 10 #include "SkBounder.h" | 11 #include "SkBounder.h" |
| 11 #include "SkCanvas.h" | 12 #include "SkCanvas.h" |
| 12 #include "SkColorPriv.h" | 13 #include "SkColorPriv.h" |
| 13 #include "SkDevice.h" | 14 #include "SkDevice.h" |
| 14 #include "SkDeviceLooper.h" | 15 #include "SkDeviceLooper.h" |
| 15 #include "SkFixed.h" | 16 #include "SkFixed.h" |
| 16 #include "SkMaskFilter.h" | 17 #include "SkMaskFilter.h" |
| 17 #include "SkPaint.h" | 18 #include "SkPaint.h" |
| 18 #include "SkPathEffect.h" | 19 #include "SkPathEffect.h" |
| (...skipping 2176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2195 fDevice->drawPath(*this, tmp, iter.getPaint(), NULL, true); | 2196 fDevice->drawPath(*this, tmp, iter.getPaint(), NULL, true); |
| 2196 } else { | 2197 } else { |
| 2197 this->drawPath(tmp, iter.getPaint(), NULL, true); | 2198 this->drawPath(tmp, iter.getPaint(), NULL, true); |
| 2198 } | 2199 } |
| 2199 } | 2200 } |
| 2200 } | 2201 } |
| 2201 } | 2202 } |
| 2202 | 2203 |
| 2203 /////////////////////////////////////////////////////////////////////////////// | 2204 /////////////////////////////////////////////////////////////////////////////// |
| 2204 | 2205 |
| 2205 struct VertState { | |
| 2206 int f0, f1, f2; | |
| 2207 | |
| 2208 VertState(int vCount, const uint16_t indices[], int indexCount) | |
| 2209 : fIndices(indices) { | |
| 2210 fCurrIndex = 0; | |
| 2211 if (indices) { | |
| 2212 fCount = indexCount; | |
| 2213 } else { | |
| 2214 fCount = vCount; | |
| 2215 } | |
| 2216 } | |
| 2217 | |
| 2218 typedef bool (*Proc)(VertState*); | |
| 2219 Proc chooseProc(SkCanvas::VertexMode mode); | |
| 2220 | |
| 2221 private: | |
| 2222 int fCount; | |
| 2223 int fCurrIndex; | |
| 2224 const uint16_t* fIndices; | |
| 2225 | |
| 2226 static bool Triangles(VertState*); | |
| 2227 static bool TrianglesX(VertState*); | |
| 2228 static bool TriangleStrip(VertState*); | |
| 2229 static bool TriangleStripX(VertState*); | |
| 2230 static bool TriangleFan(VertState*); | |
| 2231 static bool TriangleFanX(VertState*); | |
| 2232 }; | |
| 2233 | |
| 2234 bool VertState::Triangles(VertState* state) { | |
| 2235 int index = state->fCurrIndex; | |
| 2236 if (index + 3 > state->fCount) { | |
| 2237 return false; | |
| 2238 } | |
| 2239 state->f0 = index + 0; | |
| 2240 state->f1 = index + 1; | |
| 2241 state->f2 = index + 2; | |
| 2242 state->fCurrIndex = index + 3; | |
| 2243 return true; | |
| 2244 } | |
| 2245 | |
| 2246 bool VertState::TrianglesX(VertState* state) { | |
| 2247 const uint16_t* indices = state->fIndices; | |
| 2248 int index = state->fCurrIndex; | |
| 2249 if (index + 3 > state->fCount) { | |
| 2250 return false; | |
| 2251 } | |
| 2252 state->f0 = indices[index + 0]; | |
| 2253 state->f1 = indices[index + 1]; | |
| 2254 state->f2 = indices[index + 2]; | |
| 2255 state->fCurrIndex = index + 3; | |
| 2256 return true; | |
| 2257 } | |
| 2258 | |
| 2259 bool VertState::TriangleStrip(VertState* state) { | |
| 2260 int index = state->fCurrIndex; | |
| 2261 if (index + 3 > state->fCount) { | |
| 2262 return false; | |
| 2263 } | |
| 2264 state->f2 = index + 2; | |
| 2265 if (index & 1) { | |
| 2266 state->f0 = index + 1; | |
| 2267 state->f1 = index + 0; | |
| 2268 } else { | |
| 2269 state->f0 = index + 0; | |
| 2270 state->f1 = index + 1; | |
| 2271 } | |
| 2272 state->fCurrIndex = index + 1; | |
| 2273 return true; | |
| 2274 } | |
| 2275 | |
| 2276 bool VertState::TriangleStripX(VertState* state) { | |
| 2277 const uint16_t* indices = state->fIndices; | |
| 2278 int index = state->fCurrIndex; | |
| 2279 if (index + 3 > state->fCount) { | |
| 2280 return false; | |
| 2281 } | |
| 2282 state->f2 = indices[index + 2]; | |
| 2283 if (index & 1) { | |
| 2284 state->f0 = indices[index + 1]; | |
| 2285 state->f1 = indices[index + 0]; | |
| 2286 } else { | |
| 2287 state->f0 = indices[index + 0]; | |
| 2288 state->f1 = indices[index + 1]; | |
| 2289 } | |
| 2290 state->fCurrIndex = index + 1; | |
| 2291 return true; | |
| 2292 } | |
| 2293 | |
| 2294 bool VertState::TriangleFan(VertState* state) { | |
| 2295 int index = state->fCurrIndex; | |
| 2296 if (index + 3 > state->fCount) { | |
| 2297 return false; | |
| 2298 } | |
| 2299 state->f0 = 0; | |
| 2300 state->f1 = index + 1; | |
| 2301 state->f2 = index + 2; | |
| 2302 state->fCurrIndex = index + 1; | |
| 2303 return true; | |
| 2304 } | |
| 2305 | |
| 2306 bool VertState::TriangleFanX(VertState* state) { | |
| 2307 const uint16_t* indices = state->fIndices; | |
| 2308 int index = state->fCurrIndex; | |
| 2309 if (index + 3 > state->fCount) { | |
| 2310 return false; | |
| 2311 } | |
| 2312 state->f0 = indices[0]; | |
| 2313 state->f1 = indices[index + 1]; | |
| 2314 state->f2 = indices[index + 2]; | |
| 2315 state->fCurrIndex = index + 1; | |
| 2316 return true; | |
| 2317 } | |
| 2318 | |
| 2319 VertState::Proc VertState::chooseProc(SkCanvas::VertexMode mode) { | |
| 2320 switch (mode) { | |
| 2321 case SkCanvas::kTriangles_VertexMode: | |
| 2322 return fIndices ? TrianglesX : Triangles; | |
| 2323 case SkCanvas::kTriangleStrip_VertexMode: | |
| 2324 return fIndices ? TriangleStripX : TriangleStrip; | |
| 2325 case SkCanvas::kTriangleFan_VertexMode: | |
| 2326 return fIndices ? TriangleFanX : TriangleFan; | |
| 2327 default: | |
| 2328 return NULL; | |
| 2329 } | |
| 2330 } | |
| 2331 | |
| 2332 typedef void (*HairProc)(const SkPoint&, const SkPoint&, const SkRasterClip&, | 2206 typedef void (*HairProc)(const SkPoint&, const SkPoint&, const SkRasterClip&, |
| 2333 SkBlitter*); | 2207 SkBlitter*); |
| 2334 | 2208 |
| 2335 static HairProc ChooseHairProc(bool doAntiAlias) { | 2209 static HairProc ChooseHairProc(bool doAntiAlias) { |
| 2336 return doAntiAlias ? SkScan::AntiHairLine : SkScan::HairLine; | 2210 return doAntiAlias ? SkScan::AntiHairLine : SkScan::HairLine; |
| 2337 } | 2211 } |
| 2338 | 2212 |
| 2339 static bool texture_to_matrix(const VertState& state, const SkPoint verts[], | 2213 static bool texture_to_matrix(const VertState& state, const SkPoint verts[], |
| 2340 const SkPoint texs[], SkMatrix* matrix) { | 2214 const SkPoint texs[], SkMatrix* matrix) { |
| 2341 SkPoint src[3], dst[3]; | 2215 SkPoint src[3], dst[3]; |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2598 continue; | 2472 continue; |
| 2599 } | 2473 } |
| 2600 } | 2474 } |
| 2601 | 2475 |
| 2602 SkPoint tmp[] = { | 2476 SkPoint tmp[] = { |
| 2603 devVerts[state.f0], devVerts[state.f1], devVerts[state.f2] | 2477 devVerts[state.f0], devVerts[state.f1], devVerts[state.f2] |
| 2604 }; | 2478 }; |
| 2605 SkScan::FillTriangle(tmp, *fRC, blitter.get()); | 2479 SkScan::FillTriangle(tmp, *fRC, blitter.get()); |
| 2606 } | 2480 } |
| 2607 } else { | 2481 } else { |
| 2608 // no colors[] and no texture | 2482 // no colors[] and no texture, stroke hairlines with paint's color. |
| 2609 HairProc hairProc = ChooseHairProc(paint.isAntiAlias()); | 2483 HairProc hairProc = ChooseHairProc(paint.isAntiAlias()); |
| 2610 const SkRasterClip& clip = *fRC; | 2484 const SkRasterClip& clip = *fRC; |
| 2611 while (vertProc(&state)) { | 2485 while (vertProc(&state)) { |
| 2612 hairProc(devVerts[state.f0], devVerts[state.f1], clip, blitter.get()
); | 2486 hairProc(devVerts[state.f0], devVerts[state.f1], clip, blitter.get()
); |
| 2613 hairProc(devVerts[state.f1], devVerts[state.f2], clip, blitter.get()
); | 2487 hairProc(devVerts[state.f1], devVerts[state.f2], clip, blitter.get()
); |
| 2614 hairProc(devVerts[state.f2], devVerts[state.f0], clip, blitter.get()
); | 2488 hairProc(devVerts[state.f2], devVerts[state.f0], clip, blitter.get()
); |
| 2615 } | 2489 } |
| 2616 } | 2490 } |
| 2617 } | 2491 } |
| 2618 | 2492 |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2828 mask->fImage = SkMask::AllocImage(size); | 2702 mask->fImage = SkMask::AllocImage(size); |
| 2829 memset(mask->fImage, 0, mask->computeImageSize()); | 2703 memset(mask->fImage, 0, mask->computeImageSize()); |
| 2830 } | 2704 } |
| 2831 | 2705 |
| 2832 if (SkMask::kJustComputeBounds_CreateMode != mode) { | 2706 if (SkMask::kJustComputeBounds_CreateMode != mode) { |
| 2833 draw_into_mask(*mask, devPath, style); | 2707 draw_into_mask(*mask, devPath, style); |
| 2834 } | 2708 } |
| 2835 | 2709 |
| 2836 return true; | 2710 return true; |
| 2837 } | 2711 } |
| OLD | NEW |