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" |
(...skipping 2335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2346 dst[0] = verts[state.f0]; | 2346 dst[0] = verts[state.f0]; |
2347 dst[1] = verts[state.f1]; | 2347 dst[1] = verts[state.f1]; |
2348 dst[2] = verts[state.f2]; | 2348 dst[2] = verts[state.f2]; |
2349 return matrix->setPolyToPoly(src, dst, 3); | 2349 return matrix->setPolyToPoly(src, dst, 3); |
2350 } | 2350 } |
2351 | 2351 |
2352 class SkTriColorShader : public SkShader { | 2352 class SkTriColorShader : public SkShader { |
2353 public: | 2353 public: |
2354 SkTriColorShader() {} | 2354 SkTriColorShader() {} |
2355 | 2355 |
2356 virtual SkShader::Context* createContext(const ContextRec&, void*) const SK_ OVERRIDE; | |
2357 virtual size_t contextSize() const SK_OVERRIDE; | 2356 virtual size_t contextSize() const SK_OVERRIDE; |
2358 | 2357 |
2359 class TriColorShaderContext : public SkShader::Context { | 2358 class TriColorShaderContext : public SkShader::Context { |
2360 public: | 2359 public: |
2361 TriColorShaderContext(const SkTriColorShader& shader, const ContextRec&) ; | 2360 TriColorShaderContext(const SkTriColorShader& shader, const ContextRec&) ; |
2362 virtual ~TriColorShaderContext(); | 2361 virtual ~TriColorShaderContext(); |
2363 | 2362 |
2364 bool setup(const SkPoint pts[], const SkColor colors[], int, int, int); | 2363 bool setup(const SkPoint pts[], const SkColor colors[], int, int, int); |
2365 | 2364 |
2366 virtual void shadeSpan(int x, int y, SkPMColor dstC[], int count) SK_OVE RRIDE; | 2365 virtual void shadeSpan(int x, int y, SkPMColor dstC[], int count) SK_OVE RRIDE; |
2367 | 2366 |
2368 private: | 2367 private: |
2369 SkMatrix fDstToUnit; | 2368 SkMatrix fDstToUnit; |
2370 SkPMColor fColors[3]; | 2369 SkPMColor fColors[3]; |
2371 | 2370 |
2372 typedef SkShader::Context INHERITED; | 2371 typedef SkShader::Context INHERITED; |
2373 }; | 2372 }; |
2374 | 2373 |
2375 SK_TO_STRING_OVERRIDE() | 2374 SK_TO_STRING_OVERRIDE() |
2376 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTriColorShader) | 2375 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTriColorShader) |
2377 | 2376 |
2378 protected: | 2377 protected: |
2379 SkTriColorShader(SkReadBuffer& buffer) : SkShader(buffer) {} | 2378 SkTriColorShader(SkReadBuffer& buffer) : SkShader(buffer) {} |
2380 | 2379 |
2380 virtual Context* onCreateContext(const ContextRec& rec, void* storage) const SK_OVERRIDE { | |
2381 return SkNEW_PLACEMENT_ARGS(storage, TriColorShaderContext, (*this, rec) ); | |
2382 } | |
2383 | |
2381 private: | 2384 private: |
2382 typedef SkShader INHERITED; | 2385 typedef SkShader INHERITED; |
2383 }; | 2386 }; |
2384 | 2387 |
2385 SkShader::Context* SkTriColorShader::createContext(const ContextRec& rec, void* storage) const { | |
2386 if (!this->validContext(rec)) { | |
2387 return NULL; | |
2388 } | |
2389 | |
2390 return SkNEW_PLACEMENT_ARGS(storage, TriColorShaderContext, (*this, rec)); | |
2391 } | |
2392 | |
2393 bool SkTriColorShader::TriColorShaderContext::setup(const SkPoint pts[], const S kColor colors[], | 2388 bool SkTriColorShader::TriColorShaderContext::setup(const SkPoint pts[], const S kColor colors[], |
2394 int index0, int index1, int index2) { | 2389 int index0, int index1, int index2) { |
2395 | 2390 |
2396 fColors[0] = SkPreMultiplyColor(colors[index0]); | 2391 fColors[0] = SkPreMultiplyColor(colors[index0]); |
2397 fColors[1] = SkPreMultiplyColor(colors[index1]); | 2392 fColors[1] = SkPreMultiplyColor(colors[index1]); |
2398 fColors[2] = SkPreMultiplyColor(colors[index2]); | 2393 fColors[2] = SkPreMultiplyColor(colors[index2]); |
2399 | 2394 |
2400 SkMatrix m, im; | 2395 SkMatrix m, im; |
2401 m.reset(); | 2396 m.reset(); |
2402 m.set(0, pts[index1].fX - pts[index0].fX); | 2397 m.set(0, pts[index1].fX - pts[index0].fX); |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2557 SkMatrix savedLocalM; | 2552 SkMatrix savedLocalM; |
2558 if (shader) { | 2553 if (shader) { |
2559 savedLocalM = shader->getLocalMatrix(); | 2554 savedLocalM = shader->getLocalMatrix(); |
2560 } | 2555 } |
2561 | 2556 |
2562 while (vertProc(&state)) { | 2557 while (vertProc(&state)) { |
2563 if (NULL != textures) { | 2558 if (NULL != textures) { |
2564 if (texture_to_matrix(state, vertices, textures, &tempM)) { | 2559 if (texture_to_matrix(state, vertices, textures, &tempM)) { |
2565 tempM.postConcat(savedLocalM); | 2560 tempM.postConcat(savedLocalM); |
2566 shader->setLocalMatrix(tempM); | 2561 shader->setLocalMatrix(tempM); |
2567 if (!blitter->resetShaderContext(*fBitmap, p, *fMatrix)) { | 2562 if (!blitter->resetShaderContext(*fBitmap, p, *fMatrix)) { |
scroggo
2014/05/05 14:01:19
The SkSmallAllocator will eventually call ~Context
reed1
2014/05/05 15:10:01
Will change resetShaderContext to always have some
| |
2568 continue; | 2563 continue; |
2569 } | 2564 } |
2570 } | 2565 } |
2571 } | 2566 } |
2572 if (NULL != colors) { | 2567 if (NULL != colors) { |
2573 // Find the context for triShader. | 2568 // Find the context for triShader. |
2574 SkTriColorShader::TriColorShaderContext* triColorShaderContext; | 2569 SkTriColorShader::TriColorShaderContext* triColorShaderContext; |
2575 | 2570 |
2576 SkShader::Context* shaderContext = blitter->getShaderContext(); | 2571 SkShader::Context* shaderContext = blitter->getShaderContext(); |
2577 SkASSERT(shaderContext); | 2572 SkASSERT(shaderContext); |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2829 mask->fImage = SkMask::AllocImage(size); | 2824 mask->fImage = SkMask::AllocImage(size); |
2830 memset(mask->fImage, 0, mask->computeImageSize()); | 2825 memset(mask->fImage, 0, mask->computeImageSize()); |
2831 } | 2826 } |
2832 | 2827 |
2833 if (SkMask::kJustComputeBounds_CreateMode != mode) { | 2828 if (SkMask::kJustComputeBounds_CreateMode != mode) { |
2834 draw_into_mask(*mask, devPath, style); | 2829 draw_into_mask(*mask, devPath, style); |
2835 } | 2830 } |
2836 | 2831 |
2837 return true; | 2832 return true; |
2838 } | 2833 } |
OLD | NEW |