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

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

Issue 160103002: Work in progress to make SkShader immutable. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 10 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
« no previous file with comments | « include/core/SkShader.h ('k') | src/core/SkBlitter_ARGB32.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 SkSafeRef(proxy); 570 SkSafeRef(proxy);
571 fMask = NULL; 571 fMask = NULL;
572 } 572 }
573 573
574 virtual ~Sk3DShader() { 574 virtual ~Sk3DShader() {
575 SkSafeUnref(fProxy); 575 SkSafeUnref(fProxy);
576 } 576 }
577 577
578 void setMask(const SkMask* mask) { fMask = mask; } 578 void setMask(const SkMask* mask) { fMask = mask; }
579 579
580 virtual bool setContext(const SkBitmap& device, const SkPaint& paint, 580 virtual bool onSetContext(Context* c, const SkBitmap& device, const SkPaint& paint,
581 const SkMatrix& matrix) SK_OVERRIDE { 581 const SkMatrix& matrix) SK_OVERRIDE {
582 if (!this->INHERITED::setContext(device, paint, matrix)) { 582 if (!this->INHERITED::onSetContext(c, device, paint, matrix)) {
583 return false; 583 return false;
584 } 584 }
585 if (fProxy) { 585 if (fProxy) {
586 if (!fProxy->setContext(device, paint, matrix)) { 586 if (!fProxy->onSetContext(c, device, paint, matrix)) {
587 // must keep our set/end context calls balanced
588 this->INHERITED::endContext();
589 return false; 587 return false;
590 } 588 }
591 } else { 589 } else {
592 fPMColor = SkPreMultiplyColor(paint.getColor()); 590 fPMColor = SkPreMultiplyColor(paint.getColor());
593 } 591 }
594 return true; 592 return true;
595 } 593 }
596 594
597 virtual void endContext() SK_OVERRIDE { 595 virtual void endContext() SK_OVERRIDE {
598 if (fProxy) { 596 if (fProxy) {
599 fProxy->endContext(); 597 fProxy->endContext();
600 } 598 }
601 this->INHERITED::endContext(); 599 this->INHERITED::endContext();
602 } 600 }
603 601
604 virtual void shadeSpan(int x, int y, SkPMColor span[], int count) SK_OVERRID E { 602 virtual void shadeSpan(Context* c, int x, int y, SkPMColor span[], int count ) SK_OVERRIDE {
605 if (fProxy) { 603 if (fProxy) {
606 fProxy->shadeSpan(x, y, span, count); 604 fProxy->shadeSpan(c, x, y, span, count);
607 } 605 }
608 606
609 if (fMask == NULL) { 607 if (fMask == NULL) {
610 if (fProxy == NULL) { 608 if (fProxy == NULL) {
611 sk_memset32(span, fPMColor, count); 609 sk_memset32(span, fPMColor, count);
612 } 610 }
613 return; 611 return;
614 } 612 }
615 613
616 SkASSERT(fMask->fBounds.contains(x, y)); 614 SkASSERT(fMask->fBounds.contains(x, y));
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 } 694 }
697 695
698 private: 696 private:
699 SkShader* fProxy; 697 SkShader* fProxy;
700 SkPMColor fPMColor; 698 SkPMColor fPMColor;
701 const SkMask* fMask; 699 const SkMask* fMask;
702 700
703 typedef SkShader INHERITED; 701 typedef SkShader INHERITED;
704 }; 702 };
705 703
704 // Remember, this class is going to hang onto another blitter. I think it's okay for
705 // him to just let that blitter handle the Context.
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, void (*killProc)(void*))
709 : fProxy(proxy), f3DShader(shader), fKillProc(killProc) { 709 : fProxy(proxy), f3DShader(shader), fKillProc(killProc) {
710 shader->ref(); 710 shader->ref();
711 } 711 }
712 712
713 virtual ~Sk3DBlitter() { 713 virtual ~Sk3DBlitter() {
714 f3DShader->unref(); 714 f3DShader->unref();
715 fKillProc(fProxy); 715 fKillProc(fProxy);
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
932 } 932 }
933 933
934 /* 934 /*
935 * We need to have balanced calls to the shader: 935 * We need to have balanced calls to the shader:
936 * setContext 936 * setContext
937 * endContext 937 * endContext
938 * We make the first call here, in case it fails we can abort the draw. 938 * 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 939 * The endContext() call is made by the blitter (assuming setContext did
940 * not fail) in its destructor. 940 * not fail) in its destructor.
941 */ 941 */
942 if (shader && !shader->setContext(device, *paint, matrix)) { 942 SkShader::Context* context = NULL;
943 SK_PLACEMENT_NEW(blitter, SkNullBlitter, storage, storageSize); 943 if (shader) {
944 return blitter; 944 context = shader->setContext(device, *paint, matrix);
945 if (!context) {
946 SK_PLACEMENT_NEW(blitter, SkNullBlitter, storage, storageSize);
947 return blitter;
948 }
945 } 949 }
946 950
947 951
948 switch (device.config()) { 952 switch (device.config()) {
949 case SkBitmap::kA8_Config: 953 case SkBitmap::kA8_Config:
950 if (drawCoverage) { 954 if (drawCoverage) {
951 SkASSERT(NULL == shader); 955 SkASSERT(NULL == shader);
956 SkASSERT(NULL == context);
952 SkASSERT(NULL == paint->getXfermode()); 957 SkASSERT(NULL == paint->getXfermode());
953 SK_PLACEMENT_NEW_ARGS(blitter, SkA8_Coverage_Blitter, 958 SK_PLACEMENT_NEW_ARGS(blitter, SkA8_Coverage_Blitter,
954 storage, storageSize, (device, *paint)); 959 storage, storageSize, (device, *paint));
955 } else if (shader) { 960 } else if (shader) {
961 // I've just made the blitters slightly larger. Make sure they'r e still
962 // small enough to fit in storage
963 SkASSERT(sizeof(SkA8_Shader_Blitter) <= storageSize);
956 SK_PLACEMENT_NEW_ARGS(blitter, SkA8_Shader_Blitter, 964 SK_PLACEMENT_NEW_ARGS(blitter, SkA8_Shader_Blitter,
957 storage, storageSize, (device, *paint)); 965 storage, storageSize, (device, *paint, con text));
958 } else { 966 } else {
959 SK_PLACEMENT_NEW_ARGS(blitter, SkA8_Blitter, 967 SK_PLACEMENT_NEW_ARGS(blitter, SkA8_Blitter,
960 storage, storageSize, (device, *paint)); 968 storage, storageSize, (device, *paint));
961 } 969 }
962 break; 970 break;
963 971
964 case SkBitmap::kRGB_565_Config: 972 case SkBitmap::kRGB_565_Config:
965 blitter = SkBlitter_ChooseD565(device, *paint, storage, storageSize) ; 973 blitter = SkBlitter_ChooseD565(device, *paint, context, storage, sto rageSize);
966 break; 974 break;
967 975
968 case SkBitmap::kARGB_8888_Config: 976 case SkBitmap::kARGB_8888_Config:
969 if (shader) { 977 if (shader) {
978 SkASSERT(sizeof(SkARGB32_Shader_Blitter) <= storageSize);
970 SK_PLACEMENT_NEW_ARGS(blitter, SkARGB32_Shader_Blitter, 979 SK_PLACEMENT_NEW_ARGS(blitter, SkARGB32_Shader_Blitter,
971 storage, storageSize, (device, *paint)); 980 storage, storageSize, (device, *paint, con text));
972 } else if (paint->getColor() == SK_ColorBLACK) { 981 } else if (paint->getColor() == SK_ColorBLACK) {
973 SK_PLACEMENT_NEW_ARGS(blitter, SkARGB32_Black_Blitter, 982 SK_PLACEMENT_NEW_ARGS(blitter, SkARGB32_Black_Blitter,
974 storage, storageSize, (device, *paint)); 983 storage, storageSize, (device, *paint));
975 } else if (paint->getAlpha() == 0xFF) { 984 } else if (paint->getAlpha() == 0xFF) {
976 SK_PLACEMENT_NEW_ARGS(blitter, SkARGB32_Opaque_Blitter, 985 SK_PLACEMENT_NEW_ARGS(blitter, SkARGB32_Opaque_Blitter,
977 storage, storageSize, (device, *paint)); 986 storage, storageSize, (device, *paint));
978 } else { 987 } else {
979 SK_PLACEMENT_NEW_ARGS(blitter, SkARGB32_Blitter, 988 SK_PLACEMENT_NEW_ARGS(blitter, SkARGB32_Blitter,
980 storage, storageSize, (device, *paint)); 989 storage, storageSize, (device, *paint));
981 } 990 }
(...skipping 15 matching lines...) Expand all
997 return blitter; 1006 return blitter;
998 } 1007 }
999 1008
1000 /////////////////////////////////////////////////////////////////////////////// 1009 ///////////////////////////////////////////////////////////////////////////////
1001 1010
1002 const uint16_t gMask_0F0F = 0xF0F; 1011 const uint16_t gMask_0F0F = 0xF0F;
1003 const uint32_t gMask_00FF00FF = 0xFF00FF; 1012 const uint32_t gMask_00FF00FF = 0xFF00FF;
1004 1013
1005 /////////////////////////////////////////////////////////////////////////////// 1014 ///////////////////////////////////////////////////////////////////////////////
1006 1015
1007 SkShaderBlitter::SkShaderBlitter(const SkBitmap& device, const SkPaint& paint) 1016 SkShaderBlitter::SkShaderBlitter(const SkBitmap& device, const SkPaint& paint,
1017 SkShader::Context* context)
1008 : INHERITED(device) { 1018 : INHERITED(device) {
1009 fShader = paint.getShader(); 1019 fShader = paint.getShader();
1010 SkASSERT(fShader); 1020 SkASSERT(fShader);
1011 SkASSERT(fShader->setContextHasBeenCalled()); 1021 SkASSERT(fShader->setContextHasBeenCalled());
1012 1022
1013 fShader->ref(); 1023 fShader->ref();
1014 fShaderFlags = fShader->getFlags(); 1024 fShaderFlags = fShader->getFlags();
1025
1026 fContext = context;
1027 SkASSERT(fContext);
1015 } 1028 }
1016 1029
1017 SkShaderBlitter::~SkShaderBlitter() { 1030 SkShaderBlitter::~SkShaderBlitter() {
1018 SkASSERT(fShader->setContextHasBeenCalled()); 1031 SkASSERT(fShader->setContextHasBeenCalled());
1019 fShader->endContext(); 1032 fShader->endContext(fContext);
1020 fShader->unref(); 1033 fShader->unref();
1021 } 1034 }
OLDNEW
« no previous file with comments | « include/core/SkShader.h ('k') | src/core/SkBlitter_ARGB32.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698