Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Side by Side Diff: src/core/SkBlitter.cpp

Issue 179343005: Add a class to allocate small objects w/o extra calls to new. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rename the .h file Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "SkBlitter.h" 10 #include "SkBlitter.h"
11 #include "SkAntiRun.h" 11 #include "SkAntiRun.h"
12 #include "SkColor.h" 12 #include "SkColor.h"
13 #include "SkColorFilter.h" 13 #include "SkColorFilter.h"
14 #include "SkCoreBlitters.h"
14 #include "SkFilterShader.h" 15 #include "SkFilterShader.h"
15 #include "SkReadBuffer.h" 16 #include "SkReadBuffer.h"
16 #include "SkWriteBuffer.h" 17 #include "SkWriteBuffer.h"
17 #include "SkMask.h" 18 #include "SkMask.h"
18 #include "SkMaskFilter.h" 19 #include "SkMaskFilter.h"
19 #include "SkTemplatesPriv.h" 20 #include "SkString.h"
20 #include "SkTLazy.h" 21 #include "SkTLazy.h"
21 #include "SkUtils.h" 22 #include "SkUtils.h"
22 #include "SkXfermode.h" 23 #include "SkXfermode.h"
23 #include "SkString.h"
24 24
25 SkBlitter::~SkBlitter() {} 25 SkBlitter::~SkBlitter() {}
26 26
27 bool SkBlitter::isNullBlitter() const { return false; } 27 bool SkBlitter::isNullBlitter() const { return false; }
28 28
29 const SkBitmap* SkBlitter::justAnOpaqueColor(uint32_t* value) { 29 const SkBitmap* SkBlitter::justAnOpaqueColor(uint32_t* value) {
30 return NULL; 30 return NULL;
31 } 31 }
32 32
33 void SkBlitter::blitH(int x, int y, int width) { 33 void SkBlitter::blitH(int x, int y, int width) {
(...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 private: 698 private:
699 SkShader* fProxy; 699 SkShader* fProxy;
700 SkPMColor fPMColor; 700 SkPMColor fPMColor;
701 const SkMask* fMask; 701 const SkMask* fMask;
702 702
703 typedef SkShader INHERITED; 703 typedef SkShader INHERITED;
704 }; 704 };
705 705
706 class Sk3DBlitter : public SkBlitter { 706 class Sk3DBlitter : public SkBlitter {
707 public: 707 public:
708 Sk3DBlitter(SkBlitter* proxy, Sk3DShader* shader, void (*killProc)(void*)) 708 Sk3DBlitter(SkBlitter* proxy, Sk3DShader* shader)
709 : fProxy(proxy), f3DShader(shader), fKillProc(killProc) { 709 : fProxy(proxy)
710 shader->ref(); 710 , f3DShader(SkRef(shader))
711 } 711 {}
712
713 virtual ~Sk3DBlitter() {
714 f3DShader->unref();
715 fKillProc(fProxy);
716 }
717 712
718 virtual void blitH(int x, int y, int width) { 713 virtual void blitH(int x, int y, int width) {
719 fProxy->blitH(x, y, width); 714 fProxy->blitH(x, y, width);
720 } 715 }
721 716
722 virtual void blitAntiH(int x, int y, const SkAlpha antialias[], 717 virtual void blitAntiH(int x, int y, const SkAlpha antialias[],
723 const int16_t runs[]) { 718 const int16_t runs[]) {
724 fProxy->blitAntiH(x, y, antialias, runs); 719 fProxy->blitAntiH(x, y, antialias, runs);
725 } 720 }
726 721
(...skipping 13 matching lines...) Expand all
740 fProxy->blitMask(mask, clip); 735 fProxy->blitMask(mask, clip);
741 ((SkMask*)&mask)->fFormat = SkMask::k3D_Format; 736 ((SkMask*)&mask)->fFormat = SkMask::k3D_Format;
742 737
743 f3DShader->setMask(NULL); 738 f3DShader->setMask(NULL);
744 } else { 739 } else {
745 fProxy->blitMask(mask, clip); 740 fProxy->blitMask(mask, clip);
746 } 741 }
747 } 742 }
748 743
749 private: 744 private:
750 SkBlitter* fProxy; 745 // fProxy is unowned. It will be deleted by SkSmallAllocator.
751 Sk3DShader* f3DShader; 746 SkBlitter* fProxy;
752 void (*fKillProc)(void*); 747 SkAutoTUnref<Sk3DShader> f3DShader;
753 }; 748 };
754 749
755 /////////////////////////////////////////////////////////////////////////////// 750 ///////////////////////////////////////////////////////////////////////////////
756 751
757 #include "SkCoreBlitters.h" 752 #include "SkCoreBlitters.h"
758 753
759 class SkAutoCallProc {
760 public:
761 typedef void (*Proc)(void*);
762
763 SkAutoCallProc(void* obj, Proc proc)
764 : fObj(obj), fProc(proc) {}
765
766 ~SkAutoCallProc() {
767 if (fObj && fProc) {
768 fProc(fObj);
769 }
770 }
771
772 void* get() const { return fObj; }
773
774 void* detach() {
775 void* obj = fObj;
776 fObj = NULL;
777 return obj;
778 }
779
780 private:
781 void* fObj;
782 Proc fProc;
783 };
784 #define SkAutoCallProc(...) SK_REQUIRE_LOCAL_VAR(SkAutoCallProc)
785
786 static void destroy_blitter(void* blitter) {
787 ((SkBlitter*)blitter)->~SkBlitter();
788 }
789
790 static void delete_blitter(void* blitter) {
791 SkDELETE((SkBlitter*)blitter);
792 }
793
794 static bool just_solid_color(const SkPaint& paint) { 754 static bool just_solid_color(const SkPaint& paint) {
795 if (paint.getAlpha() == 0xFF && paint.getColorFilter() == NULL) { 755 if (paint.getAlpha() == 0xFF && paint.getColorFilter() == NULL) {
796 SkShader* shader = paint.getShader(); 756 SkShader* shader = paint.getShader();
797 if (NULL == shader || 757 if (NULL == shader ||
798 (shader->getFlags() & SkShader::kOpaqueAlpha_Flag)) { 758 (shader->getFlags() & SkShader::kOpaqueAlpha_Flag)) {
799 return true; 759 return true;
800 } 760 }
801 } 761 }
802 return false; 762 return false;
803 } 763 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
845 default: 805 default:
846 break; 806 break;
847 } 807 }
848 } 808 }
849 return kNormal_XferInterp; 809 return kNormal_XferInterp;
850 } 810 }
851 811
852 SkBlitter* SkBlitter::Choose(const SkBitmap& device, 812 SkBlitter* SkBlitter::Choose(const SkBitmap& device,
853 const SkMatrix& matrix, 813 const SkMatrix& matrix,
854 const SkPaint& origPaint, 814 const SkPaint& origPaint,
855 void* storage, size_t storageSize, 815 SkTBlitterAllocator* allocator,
856 bool drawCoverage) { 816 bool drawCoverage) {
857 SkASSERT(storageSize == 0 || storage != NULL); 817 SkASSERT(allocator != NULL);
858 818
859 SkBlitter* blitter = NULL; 819 SkBlitter* blitter = NULL;
860 820
861 // which check, in case we're being called by a client with a dummy device 821 // which check, in case we're being called by a client with a dummy device
862 // (e.g. they have a bounder that always aborts the draw) 822 // (e.g. they have a bounder that always aborts the draw)
863 if (kUnknown_SkColorType == device.colorType() || 823 if (kUnknown_SkColorType == device.colorType() ||
864 (drawCoverage && (kAlpha_8_SkColorType != device.colorType()))) { 824 (drawCoverage && (kAlpha_8_SkColorType != device.colorType()))) {
865 SK_PLACEMENT_NEW(blitter, SkNullBlitter, storage, storageSize); 825 blitter = allocator->createT<SkNullBlitter>();
866 return blitter; 826 return blitter;
867 } 827 }
868 828
869 SkShader* shader = origPaint.getShader(); 829 SkShader* shader = origPaint.getShader();
870 SkColorFilter* cf = origPaint.getColorFilter(); 830 SkColorFilter* cf = origPaint.getColorFilter();
871 SkXfermode* mode = origPaint.getXfermode(); 831 SkXfermode* mode = origPaint.getXfermode();
872 Sk3DShader* shader3D = NULL; 832 Sk3DShader* shader3D = NULL;
873 833
874 SkTCopyOnFirstWrite<SkPaint> paint(origPaint); 834 SkTCopyOnFirstWrite<SkPaint> paint(origPaint);
875 835
876 if (origPaint.getMaskFilter() != NULL && 836 if (origPaint.getMaskFilter() != NULL &&
877 origPaint.getMaskFilter()->getFormat() == SkMask::k3D_Format) { 837 origPaint.getMaskFilter()->getFormat() == SkMask::k3D_Format) {
878 shader3D = SkNEW_ARGS(Sk3DShader, (shader)); 838 shader3D = SkNEW_ARGS(Sk3DShader, (shader));
879 // we know we haven't initialized lazyPaint yet, so just do it 839 // we know we haven't initialized lazyPaint yet, so just do it
880 paint.writable()->setShader(shader3D)->unref(); 840 paint.writable()->setShader(shader3D)->unref();
881 shader = shader3D; 841 shader = shader3D;
882 } 842 }
883 843
884 if (NULL != mode) { 844 if (NULL != mode) {
885 switch (interpret_xfermode(*paint, mode, device.colorType())) { 845 switch (interpret_xfermode(*paint, mode, device.colorType())) {
886 case kSrcOver_XferInterp: 846 case kSrcOver_XferInterp:
887 mode = NULL; 847 mode = NULL;
888 paint.writable()->setXfermode(NULL); 848 paint.writable()->setXfermode(NULL);
889 break; 849 break;
890 case kSkipDrawing_XferInterp: 850 case kSkipDrawing_XferInterp:{
891 SK_PLACEMENT_NEW(blitter, SkNullBlitter, storage, storageSize); 851 blitter = allocator->createT<SkNullBlitter>();
892 return blitter; 852 return blitter;
853 }
893 default: 854 default:
894 break; 855 break;
895 } 856 }
896 } 857 }
897 858
898 /* 859 /*
899 * If the xfermode is CLEAR, then we can completely ignore the installed 860 * If the xfermode is CLEAR, then we can completely ignore the installed
900 * color/shader/colorfilter, and just pretend we're SRC + color==0. This 861 * color/shader/colorfilter, and just pretend we're SRC + color==0. This
901 * will fall into our optimizations for SRC mode. 862 * will fall into our optimizations for SRC mode.
902 */ 863 */
(...skipping 30 matching lines...) Expand all
933 894
934 /* 895 /*
935 * We need to have balanced calls to the shader: 896 * We need to have balanced calls to the shader:
936 * setContext 897 * setContext
937 * endContext 898 * endContext
938 * We make the first call here, in case it fails we can abort the draw. 899 * We make the first call here, in case it fails we can abort the draw.
939 * The endContext() call is made by the blitter (assuming setContext did 900 * The endContext() call is made by the blitter (assuming setContext did
940 * not fail) in its destructor. 901 * not fail) in its destructor.
941 */ 902 */
942 if (shader && !shader->setContext(device, *paint, matrix)) { 903 if (shader && !shader->setContext(device, *paint, matrix)) {
943 SK_PLACEMENT_NEW(blitter, SkNullBlitter, storage, storageSize); 904 blitter = allocator->createT<SkNullBlitter>();
944 return blitter; 905 return blitter;
945 } 906 }
946 907
947 908
948 switch (device.colorType()) { 909 switch (device.colorType()) {
949 case kAlpha_8_SkColorType: 910 case kAlpha_8_SkColorType:
950 if (drawCoverage) { 911 if (drawCoverage) {
951 SkASSERT(NULL == shader); 912 SkASSERT(NULL == shader);
952 SkASSERT(NULL == paint->getXfermode()); 913 SkASSERT(NULL == paint->getXfermode());
953 SK_PLACEMENT_NEW_ARGS(blitter, SkA8_Coverage_Blitter, 914 blitter = allocator->createT<SkA8_Coverage_Blitter>(device, *pai nt);
954 storage, storageSize, (device, *paint));
955 } else if (shader) { 915 } else if (shader) {
956 SK_PLACEMENT_NEW_ARGS(blitter, SkA8_Shader_Blitter, 916 blitter = allocator->createT<SkA8_Shader_Blitter>(device, *paint );
957 storage, storageSize, (device, *paint));
958 } else { 917 } else {
959 SK_PLACEMENT_NEW_ARGS(blitter, SkA8_Blitter, 918 blitter = allocator->createT<SkA8_Blitter>(device, *paint);
960 storage, storageSize, (device, *paint));
961 } 919 }
962 break; 920 break;
963 921
964 case kRGB_565_SkColorType: 922 case kRGB_565_SkColorType:
965 blitter = SkBlitter_ChooseD565(device, *paint, storage, storageSize) ; 923 blitter = SkBlitter_ChooseD565(device, *paint, allocator);
966 break; 924 break;
967 925
968 case kPMColor_SkColorType: 926 case kPMColor_SkColorType:
969 if (shader) { 927 if (shader) {
970 SK_PLACEMENT_NEW_ARGS(blitter, SkARGB32_Shader_Blitter, 928 blitter = allocator->createT<SkARGB32_Shader_Blitter>(device, *p aint);
971 storage, storageSize, (device, *paint));
972 } else if (paint->getColor() == SK_ColorBLACK) { 929 } else if (paint->getColor() == SK_ColorBLACK) {
973 SK_PLACEMENT_NEW_ARGS(blitter, SkARGB32_Black_Blitter, 930 blitter = allocator->createT<SkARGB32_Black_Blitter>(device, *pa int);
974 storage, storageSize, (device, *paint));
975 } else if (paint->getAlpha() == 0xFF) { 931 } else if (paint->getAlpha() == 0xFF) {
976 SK_PLACEMENT_NEW_ARGS(blitter, SkARGB32_Opaque_Blitter, 932 blitter = allocator->createT<SkARGB32_Opaque_Blitter>(device, *p aint);
977 storage, storageSize, (device, *paint));
978 } else { 933 } else {
979 SK_PLACEMENT_NEW_ARGS(blitter, SkARGB32_Blitter, 934 blitter = allocator->createT<SkARGB32_Blitter>(device, *paint);
980 storage, storageSize, (device, *paint));
981 } 935 }
982 break; 936 break;
983 937
984 default: 938 default:
985 SkDEBUGFAIL("unsupported device config"); 939 SkDEBUGFAIL("unsupported device config");
986 SK_PLACEMENT_NEW(blitter, SkNullBlitter, storage, storageSize); 940 blitter = allocator->createT<SkNullBlitter>();
987 break; 941 break;
988 } 942 }
989 943
990 if (shader3D) { 944 if (shader3D) {
991 void (*proc)(void*) = ((void*)storage == (void*)blitter) ? destroy_blitt er : delete_blitter; 945 SkBlitter* innerBlitter = blitter;
992 SkAutoCallProc tmp(blitter, proc); 946 // innerBlitter was allocated by allocator, which will delete it.
993 947 blitter = allocator->createT<Sk3DBlitter>(innerBlitter, shader3D);
994 blitter = SkNEW_ARGS(Sk3DBlitter, (blitter, shader3D, proc));
995 (void)tmp.detach();
996 } 948 }
997 return blitter; 949 return blitter;
998 } 950 }
999 951
1000 /////////////////////////////////////////////////////////////////////////////// 952 ///////////////////////////////////////////////////////////////////////////////
1001 953
1002 const uint16_t gMask_0F0F = 0xF0F; 954 const uint16_t gMask_0F0F = 0xF0F;
1003 const uint32_t gMask_00FF00FF = 0xFF00FF; 955 const uint32_t gMask_00FF00FF = 0xFF00FF;
1004 956
1005 /////////////////////////////////////////////////////////////////////////////// 957 ///////////////////////////////////////////////////////////////////////////////
1006 958
1007 SkShaderBlitter::SkShaderBlitter(const SkBitmap& device, const SkPaint& paint) 959 SkShaderBlitter::SkShaderBlitter(const SkBitmap& device, const SkPaint& paint)
1008 : INHERITED(device) { 960 : INHERITED(device) {
1009 fShader = paint.getShader(); 961 fShader = paint.getShader();
1010 SkASSERT(fShader); 962 SkASSERT(fShader);
1011 SkASSERT(fShader->setContextHasBeenCalled()); 963 SkASSERT(fShader->setContextHasBeenCalled());
1012 964
1013 fShader->ref(); 965 fShader->ref();
1014 fShaderFlags = fShader->getFlags(); 966 fShaderFlags = fShader->getFlags();
1015 } 967 }
1016 968
1017 SkShaderBlitter::~SkShaderBlitter() { 969 SkShaderBlitter::~SkShaderBlitter() {
1018 SkASSERT(fShader->setContextHasBeenCalled()); 970 SkASSERT(fShader->setContextHasBeenCalled());
1019 fShader->endContext(); 971 fShader->endContext();
1020 fShader->unref(); 972 fShader->unref();
1021 } 973 }
OLDNEW
« no previous file with comments | « src/core/SkBlitter.h ('k') | src/core/SkBlitter_RGB16.cpp » ('j') | src/core/SkSmallAllocator.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698