| 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 "SkBlitter.h" | 8 #include "SkBlitter.h" |
| 9 #include "SkAntiRun.h" | 9 #include "SkAntiRun.h" |
| 10 #include "SkColor.h" | 10 #include "SkColor.h" |
| (...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 class Sk3DShader : public SkShader { | 573 class Sk3DShader : public SkShader { |
| 574 public: | 574 public: |
| 575 Sk3DShader(SkShader* proxy) : fProxy(proxy) { | 575 Sk3DShader(SkShader* proxy) : fProxy(proxy) { |
| 576 SkSafeRef(proxy); | 576 SkSafeRef(proxy); |
| 577 } | 577 } |
| 578 | 578 |
| 579 virtual ~Sk3DShader() { | 579 virtual ~Sk3DShader() { |
| 580 SkSafeUnref(fProxy); | 580 SkSafeUnref(fProxy); |
| 581 } | 581 } |
| 582 | 582 |
| 583 size_t contextSize() const SK_OVERRIDE { | 583 size_t contextSize() const override { |
| 584 size_t size = sizeof(Sk3DShaderContext); | 584 size_t size = sizeof(Sk3DShaderContext); |
| 585 if (fProxy) { | 585 if (fProxy) { |
| 586 size += fProxy->contextSize(); | 586 size += fProxy->contextSize(); |
| 587 } | 587 } |
| 588 return size; | 588 return size; |
| 589 } | 589 } |
| 590 | 590 |
| 591 Context* onCreateContext(const ContextRec& rec, void* storage) const SK_OVER
RIDE { | 591 Context* onCreateContext(const ContextRec& rec, void* storage) const overrid
e { |
| 592 SkShader::Context* proxyContext = NULL; | 592 SkShader::Context* proxyContext = NULL; |
| 593 if (fProxy) { | 593 if (fProxy) { |
| 594 char* proxyContextStorage = (char*) storage + sizeof(Sk3DShaderConte
xt); | 594 char* proxyContextStorage = (char*) storage + sizeof(Sk3DShaderConte
xt); |
| 595 proxyContext = fProxy->createContext(rec, proxyContextStorage); | 595 proxyContext = fProxy->createContext(rec, proxyContextStorage); |
| 596 if (!proxyContext) { | 596 if (!proxyContext) { |
| 597 return NULL; | 597 return NULL; |
| 598 } | 598 } |
| 599 } | 599 } |
| 600 return SkNEW_PLACEMENT_ARGS(storage, Sk3DShaderContext, (*this, rec, pro
xyContext)); | 600 return SkNEW_PLACEMENT_ARGS(storage, Sk3DShaderContext, (*this, rec, pro
xyContext)); |
| 601 } | 601 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 613 fPMColor = SkPreMultiplyColor(rec.fPaint->getColor()); | 613 fPMColor = SkPreMultiplyColor(rec.fPaint->getColor()); |
| 614 } | 614 } |
| 615 } | 615 } |
| 616 | 616 |
| 617 virtual ~Sk3DShaderContext() { | 617 virtual ~Sk3DShaderContext() { |
| 618 if (fProxyContext) { | 618 if (fProxyContext) { |
| 619 fProxyContext->~Context(); | 619 fProxyContext->~Context(); |
| 620 } | 620 } |
| 621 } | 621 } |
| 622 | 622 |
| 623 void set3DMask(const SkMask* mask) SK_OVERRIDE { fMask = mask; } | 623 void set3DMask(const SkMask* mask) override { fMask = mask; } |
| 624 | 624 |
| 625 void shadeSpan(int x, int y, SkPMColor span[], int count) SK_OVERRIDE { | 625 void shadeSpan(int x, int y, SkPMColor span[], int count) override { |
| 626 if (fProxyContext) { | 626 if (fProxyContext) { |
| 627 fProxyContext->shadeSpan(x, y, span, count); | 627 fProxyContext->shadeSpan(x, y, span, count); |
| 628 } | 628 } |
| 629 | 629 |
| 630 if (fMask == NULL) { | 630 if (fMask == NULL) { |
| 631 if (fProxyContext == NULL) { | 631 if (fProxyContext == NULL) { |
| 632 sk_memset32(span, fPMColor, count); | 632 sk_memset32(span, fPMColor, count); |
| 633 } | 633 } |
| 634 return; | 634 return; |
| 635 } | 635 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 // Unowned. | 690 // Unowned. |
| 691 const SkMask* fMask; | 691 const SkMask* fMask; |
| 692 // Memory is unowned, but we need to call the destructor. | 692 // Memory is unowned, but we need to call the destructor. |
| 693 SkShader::Context* fProxyContext; | 693 SkShader::Context* fProxyContext; |
| 694 SkPMColor fPMColor; | 694 SkPMColor fPMColor; |
| 695 | 695 |
| 696 typedef SkShader::Context INHERITED; | 696 typedef SkShader::Context INHERITED; |
| 697 }; | 697 }; |
| 698 | 698 |
| 699 #ifndef SK_IGNORE_TO_STRING | 699 #ifndef SK_IGNORE_TO_STRING |
| 700 void toString(SkString* str) const SK_OVERRIDE { | 700 void toString(SkString* str) const override { |
| 701 str->append("Sk3DShader: ("); | 701 str->append("Sk3DShader: ("); |
| 702 | 702 |
| 703 if (fProxy) { | 703 if (fProxy) { |
| 704 str->append("Proxy: "); | 704 str->append("Proxy: "); |
| 705 fProxy->toString(str); | 705 fProxy->toString(str); |
| 706 } | 706 } |
| 707 | 707 |
| 708 this->INHERITED::toString(str); | 708 this->INHERITED::toString(str); |
| 709 | 709 |
| 710 str->append(")"); | 710 str->append(")"); |
| 711 } | 711 } |
| 712 #endif | 712 #endif |
| 713 | 713 |
| 714 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(Sk3DShader) | 714 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(Sk3DShader) |
| 715 | 715 |
| 716 protected: | 716 protected: |
| 717 void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE { | 717 void flatten(SkWriteBuffer& buffer) const override { |
| 718 buffer.writeFlattenable(fProxy); | 718 buffer.writeFlattenable(fProxy); |
| 719 } | 719 } |
| 720 | 720 |
| 721 private: | 721 private: |
| 722 SkShader* fProxy; | 722 SkShader* fProxy; |
| 723 | 723 |
| 724 typedef SkShader INHERITED; | 724 typedef SkShader INHERITED; |
| 725 }; | 725 }; |
| 726 | 726 |
| 727 SkFlattenable* Sk3DShader::CreateProc(SkReadBuffer& buffer) { | 727 SkFlattenable* Sk3DShader::CreateProc(SkReadBuffer& buffer) { |
| 728 SkAutoTUnref<SkShader> shader(buffer.readShader()); | 728 SkAutoTUnref<SkShader> shader(buffer.readShader()); |
| 729 return SkNEW_ARGS(Sk3DShader, (shader)); | 729 return SkNEW_ARGS(Sk3DShader, (shader)); |
| 730 } | 730 } |
| 731 | 731 |
| 732 class Sk3DBlitter : public SkBlitter { | 732 class Sk3DBlitter : public SkBlitter { |
| 733 public: | 733 public: |
| 734 Sk3DBlitter(SkBlitter* proxy, SkShader::Context* shaderContext) | 734 Sk3DBlitter(SkBlitter* proxy, SkShader::Context* shaderContext) |
| 735 : fProxy(proxy) | 735 : fProxy(proxy) |
| 736 , fShaderContext(shaderContext) | 736 , fShaderContext(shaderContext) |
| 737 {} | 737 {} |
| 738 | 738 |
| 739 void blitH(int x, int y, int width) SK_OVERRIDE { | 739 void blitH(int x, int y, int width) override { |
| 740 fProxy->blitH(x, y, width); | 740 fProxy->blitH(x, y, width); |
| 741 } | 741 } |
| 742 | 742 |
| 743 virtual void blitAntiH(int x, int y, const SkAlpha antialias[], | 743 virtual void blitAntiH(int x, int y, const SkAlpha antialias[], |
| 744 const int16_t runs[]) SK_OVERRIDE { | 744 const int16_t runs[]) override { |
| 745 fProxy->blitAntiH(x, y, antialias, runs); | 745 fProxy->blitAntiH(x, y, antialias, runs); |
| 746 } | 746 } |
| 747 | 747 |
| 748 void blitV(int x, int y, int height, SkAlpha alpha) SK_OVERRIDE { | 748 void blitV(int x, int y, int height, SkAlpha alpha) override { |
| 749 fProxy->blitV(x, y, height, alpha); | 749 fProxy->blitV(x, y, height, alpha); |
| 750 } | 750 } |
| 751 | 751 |
| 752 void blitRect(int x, int y, int width, int height) SK_OVERRIDE { | 752 void blitRect(int x, int y, int width, int height) override { |
| 753 fProxy->blitRect(x, y, width, height); | 753 fProxy->blitRect(x, y, width, height); |
| 754 } | 754 } |
| 755 | 755 |
| 756 void blitMask(const SkMask& mask, const SkIRect& clip) SK_OVERRIDE { | 756 void blitMask(const SkMask& mask, const SkIRect& clip) override { |
| 757 if (mask.fFormat == SkMask::k3D_Format) { | 757 if (mask.fFormat == SkMask::k3D_Format) { |
| 758 fShaderContext->set3DMask(&mask); | 758 fShaderContext->set3DMask(&mask); |
| 759 | 759 |
| 760 ((SkMask*)&mask)->fFormat = SkMask::kA8_Format; | 760 ((SkMask*)&mask)->fFormat = SkMask::kA8_Format; |
| 761 fProxy->blitMask(mask, clip); | 761 fProxy->blitMask(mask, clip); |
| 762 ((SkMask*)&mask)->fFormat = SkMask::k3D_Format; | 762 ((SkMask*)&mask)->fFormat = SkMask::k3D_Format; |
| 763 | 763 |
| 764 fShaderContext->set3DMask(NULL); | 764 fShaderContext->set3DMask(NULL); |
| 765 } else { | 765 } else { |
| 766 fProxy->blitMask(mask, clip); | 766 fProxy->blitMask(mask, clip); |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 984 } | 984 } |
| 985 | 985 |
| 986 /////////////////////////////////////////////////////////////////////////////// | 986 /////////////////////////////////////////////////////////////////////////////// |
| 987 | 987 |
| 988 class SkTransparentShaderContext : public SkShader::Context { | 988 class SkTransparentShaderContext : public SkShader::Context { |
| 989 public: | 989 public: |
| 990 SkTransparentShaderContext(const SkShader& shader, const SkShader::ContextRe
c& rec) | 990 SkTransparentShaderContext(const SkShader& shader, const SkShader::ContextRe
c& rec) |
| 991 // Override rec with the identity matrix, so it is guaranteed to be inve
rtible. | 991 // Override rec with the identity matrix, so it is guaranteed to be inve
rtible. |
| 992 : INHERITED(shader, SkShader::ContextRec(*rec.fDevice, *rec.fPaint, SkMa
trix::I())) {} | 992 : INHERITED(shader, SkShader::ContextRec(*rec.fDevice, *rec.fPaint, SkMa
trix::I())) {} |
| 993 | 993 |
| 994 void shadeSpan(int x, int y, SkPMColor colors[], int count) SK_OVERRIDE { | 994 void shadeSpan(int x, int y, SkPMColor colors[], int count) override { |
| 995 sk_bzero(colors, count * sizeof(SkPMColor)); | 995 sk_bzero(colors, count * sizeof(SkPMColor)); |
| 996 } | 996 } |
| 997 | 997 |
| 998 private: | 998 private: |
| 999 typedef SkShader::Context INHERITED; | 999 typedef SkShader::Context INHERITED; |
| 1000 }; | 1000 }; |
| 1001 | 1001 |
| 1002 SkShaderBlitter::SkShaderBlitter(const SkBitmap& device, const SkPaint& paint, | 1002 SkShaderBlitter::SkShaderBlitter(const SkBitmap& device, const SkPaint& paint, |
| 1003 SkShader::Context* shaderContext) | 1003 SkShader::Context* shaderContext) |
| 1004 : INHERITED(device) | 1004 : INHERITED(device) |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1024 fShaderContext->~Context(); | 1024 fShaderContext->~Context(); |
| 1025 SkShader::Context* ctx = fShader->createContext(rec, (void*)fShaderContext); | 1025 SkShader::Context* ctx = fShader->createContext(rec, (void*)fShaderContext); |
| 1026 if (NULL == ctx) { | 1026 if (NULL == ctx) { |
| 1027 // Need a valid context in fShaderContext's storage, so we can later (or
our caller) call | 1027 // Need a valid context in fShaderContext's storage, so we can later (or
our caller) call |
| 1028 // the in-place destructor. | 1028 // the in-place destructor. |
| 1029 SkNEW_PLACEMENT_ARGS(fShaderContext, SkTransparentShaderContext, (*fShad
er, rec)); | 1029 SkNEW_PLACEMENT_ARGS(fShaderContext, SkTransparentShaderContext, (*fShad
er, rec)); |
| 1030 return false; | 1030 return false; |
| 1031 } | 1031 } |
| 1032 return true; | 1032 return true; |
| 1033 } | 1033 } |
| OLD | NEW |