| 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 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 | 590 |
| 591 Context* onCreateContext(const ContextRec& rec, void* storage) const overrid
e { | 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 new (storage) Sk3DShaderContext(*this, rec, proxyContext); |
| 601 } | 601 } |
| 602 | 602 |
| 603 class Sk3DShaderContext : public SkShader::Context { | 603 class Sk3DShaderContext : public SkShader::Context { |
| 604 public: | 604 public: |
| 605 // Calls proxyContext's destructor but will NOT free its memory. | 605 // Calls proxyContext's destructor but will NOT free its memory. |
| 606 Sk3DShaderContext(const Sk3DShader& shader, const ContextRec& rec, | 606 Sk3DShaderContext(const Sk3DShader& shader, const ContextRec& rec, |
| 607 SkShader::Context* proxyContext) | 607 SkShader::Context* proxyContext) |
| 608 : INHERITED(shader, rec) | 608 : INHERITED(shader, rec) |
| 609 , fMask(NULL) | 609 , fMask(NULL) |
| 610 , fProxyContext(proxyContext) | 610 , fProxyContext(proxyContext) |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 new 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) override { | 739 void blitH(int x, int y, int width) override { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 793 | 793 |
| 794 SkShader* shader = origPaint.getShader(); | 794 SkShader* shader = origPaint.getShader(); |
| 795 SkColorFilter* cf = origPaint.getColorFilter(); | 795 SkColorFilter* cf = origPaint.getColorFilter(); |
| 796 SkXfermode* mode = origPaint.getXfermode(); | 796 SkXfermode* mode = origPaint.getXfermode(); |
| 797 Sk3DShader* shader3D = NULL; | 797 Sk3DShader* shader3D = NULL; |
| 798 | 798 |
| 799 SkTCopyOnFirstWrite<SkPaint> paint(origPaint); | 799 SkTCopyOnFirstWrite<SkPaint> paint(origPaint); |
| 800 | 800 |
| 801 if (origPaint.getMaskFilter() != NULL && | 801 if (origPaint.getMaskFilter() != NULL && |
| 802 origPaint.getMaskFilter()->getFormat() == SkMask::k3D_Format) { | 802 origPaint.getMaskFilter()->getFormat() == SkMask::k3D_Format) { |
| 803 shader3D = SkNEW_ARGS(Sk3DShader, (shader)); | 803 shader3D = new Sk3DShader(shader); |
| 804 // we know we haven't initialized lazyPaint yet, so just do it | 804 // we know we haven't initialized lazyPaint yet, so just do it |
| 805 paint.writable()->setShader(shader3D)->unref(); | 805 paint.writable()->setShader(shader3D)->unref(); |
| 806 shader = shader3D; | 806 shader = shader3D; |
| 807 } | 807 } |
| 808 | 808 |
| 809 if (mode) { | 809 if (mode) { |
| 810 bool deviceIsOpaque = kRGB_565_SkColorType == device.colorType(); | 810 bool deviceIsOpaque = kRGB_565_SkColorType == device.colorType(); |
| 811 switch (SkInterpretXfermode(*paint, deviceIsOpaque)) { | 811 switch (SkInterpretXfermode(*paint, deviceIsOpaque)) { |
| 812 case kSrcOver_SkXfermodeInterpretation: | 812 case kSrcOver_SkXfermodeInterpretation: |
| 813 mode = NULL; | 813 mode = NULL; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 830 SkPaint* p = paint.writable(); | 830 SkPaint* p = paint.writable(); |
| 831 shader = p->setShader(NULL); | 831 shader = p->setShader(NULL); |
| 832 cf = p->setColorFilter(NULL); | 832 cf = p->setColorFilter(NULL); |
| 833 mode = p->setXfermodeMode(SkXfermode::kSrc_Mode); | 833 mode = p->setXfermodeMode(SkXfermode::kSrc_Mode); |
| 834 p->setColor(0); | 834 p->setColor(0); |
| 835 } | 835 } |
| 836 | 836 |
| 837 if (NULL == shader) { | 837 if (NULL == shader) { |
| 838 if (mode) { | 838 if (mode) { |
| 839 // xfermodes (and filters) require shaders for our current blitters | 839 // xfermodes (and filters) require shaders for our current blitters |
| 840 shader = SkNEW_ARGS(SkColorShader, (paint->getColor())); | 840 shader = new SkColorShader(paint->getColor()); |
| 841 paint.writable()->setShader(shader)->unref(); | 841 paint.writable()->setShader(shader)->unref(); |
| 842 paint.writable()->setAlpha(0xFF); | 842 paint.writable()->setAlpha(0xFF); |
| 843 } else if (cf) { | 843 } else if (cf) { |
| 844 // if no shader && no xfermode, we just apply the colorfilter to | 844 // if no shader && no xfermode, we just apply the colorfilter to |
| 845 // our color and move on. | 845 // our color and move on. |
| 846 SkPaint* writablePaint = paint.writable(); | 846 SkPaint* writablePaint = paint.writable(); |
| 847 writablePaint->setColor(cf->filterColor(paint->getColor())); | 847 writablePaint->setColor(cf->filterColor(paint->getColor())); |
| 848 writablePaint->setColorFilter(NULL); | 848 writablePaint->setColorFilter(NULL); |
| 849 cf = NULL; | 849 cf = NULL; |
| 850 } | 850 } |
| 851 } | 851 } |
| 852 | 852 |
| 853 if (cf) { | 853 if (cf) { |
| 854 SkASSERT(shader); | 854 SkASSERT(shader); |
| 855 shader = SkNEW_ARGS(SkFilterShader, (shader, cf)); | 855 shader = new SkFilterShader(shader, cf); |
| 856 paint.writable()->setShader(shader)->unref(); | 856 paint.writable()->setShader(shader)->unref(); |
| 857 // blitters should ignore the presence/absence of a filter, since | 857 // blitters should ignore the presence/absence of a filter, since |
| 858 // if there is one, the shader will take care of it. | 858 // if there is one, the shader will take care of it. |
| 859 } | 859 } |
| 860 | 860 |
| 861 /* | 861 /* |
| 862 * We create a SkShader::Context object, and store it on the blitter. | 862 * We create a SkShader::Context object, and store it on the blitter. |
| 863 */ | 863 */ |
| 864 SkShader::Context* shaderContext = NULL; | 864 SkShader::Context* shaderContext = NULL; |
| 865 if (shader) { | 865 if (shader) { |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 963 // Only destroy the old context if we have a new one. We need to ensure to h
ave a | 963 // Only destroy the old context if we have a new one. We need to ensure to h
ave a |
| 964 // live context in fShaderContext because the storage is owned by an SkSmall
Allocator | 964 // live context in fShaderContext because the storage is owned by an SkSmall
Allocator |
| 965 // outside of this class. | 965 // outside of this class. |
| 966 // The new context will be of the same size as the old one because we use th
e same | 966 // The new context will be of the same size as the old one because we use th
e same |
| 967 // shader to create it. It is therefore safe to re-use the storage. | 967 // shader to create it. It is therefore safe to re-use the storage. |
| 968 fShaderContext->~Context(); | 968 fShaderContext->~Context(); |
| 969 SkShader::Context* ctx = fShader->createContext(rec, (void*)fShaderContext); | 969 SkShader::Context* ctx = fShader->createContext(rec, (void*)fShaderContext); |
| 970 if (NULL == ctx) { | 970 if (NULL == ctx) { |
| 971 // Need a valid context in fShaderContext's storage, so we can later (or
our caller) call | 971 // Need a valid context in fShaderContext's storage, so we can later (or
our caller) call |
| 972 // the in-place destructor. | 972 // the in-place destructor. |
| 973 SkNEW_PLACEMENT_ARGS(fShaderContext, SkZeroShaderContext, (*fShader, rec
)); | 973 new (fShaderContext) SkZeroShaderContext(*fShader, rec); |
| 974 return false; | 974 return false; |
| 975 } | 975 } |
| 976 return true; | 976 return true; |
| 977 } | 977 } |
| OLD | NEW |