diff options
author | reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2010-12-20 18:26:13 +0000 |
---|---|---|
committer | reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2010-12-20 18:26:13 +0000 |
commit | f2b98d67dcb6fcb3120feede9c72016fc7b3ead8 (patch) | |
tree | d78b57945b29865dcdeb1badbb360575289b292d /src/core/SkShader.cpp | |
parent | 29e5054dd07c97c2195c5f64bf67aaa6b5afa204 (diff) |
merge with changes for GPU backend
git-svn-id: http://skia.googlecode.com/svn/trunk@637 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/core/SkShader.cpp')
-rw-r--r-- | src/core/SkShader.cpp | 52 |
1 files changed, 49 insertions, 3 deletions
diff --git a/src/core/SkShader.cpp b/src/core/SkShader.cpp index 34dc32e0ec..7b3a024c4f 100644 --- a/src/core/SkShader.cpp +++ b/src/core/SkShader.cpp @@ -17,6 +17,7 @@ #include "SkShader.h" #include "SkPaint.h" +#include "SkMallocPixelRef.h" SkShader::SkShader() : fLocalMatrix(NULL) { SkDEBUGCODE(fInSession = false;) @@ -195,8 +196,9 @@ SkShader::MatrixClass SkShader::ComputeMatrixClass(const SkMatrix& mat) { ////////////////////////////////////////////////////////////////////////////// -bool SkShader::asABitmap(SkBitmap*, SkMatrix*, TileMode*) { - return false; +SkShader::BitmapType SkShader::asABitmap(SkBitmap*, SkMatrix*, + TileMode*, SkScalar*) { + return kNone_BitmapType; } SkShader* SkShader::CreateBitmapShader(const SkBitmap& src, @@ -209,9 +211,28 @@ SkShader* SkShader::CreateBitmapShader(const SkBitmap& src, #include "SkColorShader.h" #include "SkUtils.h" +SkColorShader::SkColorShader() { + fFlags = 0; + fInheritColor = true; + fAsABitmapPixelRef = NULL; +} + +SkColorShader::SkColorShader(SkColor c) { + fFlags = 0; + fColor = c; + fInheritColor = false; + fAsABitmapPixelRef = NULL; +} + +SkColorShader::~SkColorShader() { + SkSafeUnref(fAsABitmapPixelRef); +} + SkColorShader::SkColorShader(SkFlattenableReadBuffer& b) : INHERITED(b) { fFlags = 0; // computed in setContext - fInheritColor = b.readU8(); + fAsABitmapPixelRef = NULL; + + fInheritColor = b.readU8(); if (fInheritColor) { return; } @@ -285,3 +306,28 @@ void SkColorShader::shadeSpanAlpha(int x, int y, uint8_t alpha[], int count) { memset(alpha, SkGetPackedA32(fPMColor), count); } +// if we had a asAColor method, that would be more efficient... +SkShader::BitmapType SkColorShader::asABitmap(SkBitmap* bitmap, SkMatrix* matrix, + TileMode modes[], + SkScalar* twoPointRadialParams) { + // we cache the pixelref, since its generateID is used in the texture cache + if (NULL == fAsABitmapPixelRef) { + SkPMColor* storage = (SkPMColor*)sk_malloc_throw(sizeof(SkPMColor)); + *storage = fPMColor; + fAsABitmapPixelRef = new SkMallocPixelRef(storage, sizeof(SkPMColor), + NULL); + } + + if (bitmap) { + bitmap->setConfig(SkBitmap::kARGB_8888_Config, 1, 1); + bitmap->setPixelRef(fAsABitmapPixelRef); + } + if (matrix) { + matrix->reset(); + } + if (modes) { + modes[0] = modes[1] = SkShader::kRepeat_TileMode; + } + return kDefault_BitmapType; +} + |