make asABitmap() const
change private cache fields in gradient to be mutable
git-svn-id: http://skia.googlecode.com/svn/trunk@898 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/core/SkShader.h b/include/core/SkShader.h
index faaa0af..c59cc59 100644
--- a/include/core/SkShader.h
+++ b/include/core/SkShader.h
@@ -80,7 +80,7 @@
shadeSpan().
*/
kConstInY32_Flag = 0x08,
-
+
/** same as kConstInY32_Flag, but is set if this is true for shadeSpan16
which may not always be the case, since shadeSpan16 may be
predithered, which would mean it was not const in Y, even though
@@ -101,7 +101,7 @@
kHasSpan16_Flag is not set, this value is meaningless.
*/
virtual uint8_t getSpan16Alpha() const { return fPaintAlpha; }
-
+
/** Called once before drawing, with the current paint and
device matrix. Return true if your shader supports these
parameters, or false if not. If false is returned, nothing
@@ -144,7 +144,7 @@
*/
virtual void beginSession();
virtual void endSession();
-
+
/**
Gives method bitmap should be read to implement a shader.
Also determines number and interpretation of "extra" parameters returned
@@ -152,35 +152,35 @@
*/
enum BitmapType {
kNone_BitmapType, //<! Shader is not represented as a bitmap
- kDefault_BitmapType,//<! Access bitmap using local coords transformed
+ kDefault_BitmapType,//<! Access bitmap using local coords transformed
// by matrix. No extras
- kRadial_BitmapType, //<! Access bitmap by transforming local coordinates
- // by the matrix and taking the distance of result
- // from (0,0) as bitmap column. Bitmap is 1 pixel
+ kRadial_BitmapType, //<! Access bitmap by transforming local coordinates
+ // by the matrix and taking the distance of result
+ // from (0,0) as bitmap column. Bitmap is 1 pixel
// tall. No extras
- kSweep_BitmapType, //<! Access bitmap by transforming local coordinates
+ kSweep_BitmapType, //<! Access bitmap by transforming local coordinates
// by the matrix and taking the angle of result
// to (0,0) as bitmap x coord, where angle = 0 is
- // bitmap left edge of bitmap = 2pi is the
+ // bitmap left edge of bitmap = 2pi is the
// right edge. Bitmap is 1 pixel tall. No extras
kTwoPointRadial_BitmapType,
- //<! Matrix transforms to space where (0,0) is
+ //<! Matrix transforms to space where (0,0) is
// the center of the starting circle. The second
- // circle will be centered (x, 0) where x may be
- // 0. The post-matrix space is normalized such
+ // circle will be centered (x, 0) where x may be
+ // 0. The post-matrix space is normalized such
// that 1 is the second radius - first radius.
// Three extra parameters are returned:
- // 0: x-offset of second circle center
+ // 0: x-offset of second circle center
// to first.
- // 1: radius of first circle in post-matrix
+ // 1: radius of first circle in post-matrix
// space
// 2: the second radius minus the first radius
- // in pre-transformed space.
+ // in pre-transformed space.
kLast_BitmapType = kTwoPointRadial_BitmapType
};
/** Optional methods for shaders that can pretend to be a bitmap/texture
- to play along with opengl. Default just returns kNone_BitmapType and
+ to play along with opengl. Default just returns kNone_BitmapType and
ignores the out parameters.
@param outTexture if non-NULL will be the bitmap representing the shader
@@ -195,7 +195,7 @@
about the first point.
*/
virtual BitmapType asABitmap(SkBitmap* outTexture, SkMatrix* outMatrix,
- TileMode xy[2], SkScalar* twoPointRadialParams);
+ TileMode xy[2], SkScalar* twoPointRadialParams) const;
/**
* If the shader subclass can be represented as a gradient, asAGradient
diff --git a/src/core/SkBitmapProcShader.cpp b/src/core/SkBitmapProcShader.cpp
index 1eaa46d..a16e96a 100644
--- a/src/core/SkBitmapProcShader.cpp
+++ b/src/core/SkBitmapProcShader.cpp
@@ -44,10 +44,10 @@
this->INHERITED::endSession();
}
-SkShader::BitmapType SkBitmapProcShader::asABitmap(SkBitmap* texture,
- SkMatrix* texM,
+SkShader::BitmapType SkBitmapProcShader::asABitmap(SkBitmap* texture,
+ SkMatrix* texM,
TileMode xy[],
- SkScalar* twoPointRadialParams) {
+ SkScalar* twoPointRadialParams) const {
if (texture) {
*texture = fRawBitmap;
}
@@ -95,7 +95,7 @@
const SkBitmap& bitmap = *fState.fBitmap;
bool bitmapIsOpaque = bitmap.isOpaque();
-
+
// update fFlags
uint32_t flags = 0;
if (bitmapIsOpaque && (255 == this->getPaintAlpha())) {
@@ -182,7 +182,7 @@
}
#endif
sproc(state, buffer, n, dstC);
-
+
if ((count -= n) == 0) {
break;
}
@@ -198,7 +198,7 @@
state.fShaderProc16(state, x, y, dstC, count);
return;
}
-
+
uint32_t buffer[BUF_MAX];
SkBitmapProcState::MatrixProc mproc = state.fMatrixProc;
SkBitmapProcState::SampleProc16 sproc = state.fSampleProc16;
@@ -215,7 +215,7 @@
}
mproc(state, buffer, n, x, y);
sproc(state, buffer, n, dstC);
-
+
if ((count -= n) == 0) {
break;
}
@@ -287,7 +287,7 @@
str->printf("BitmapShader: [%d %d %d",
fRawBitmap.width(), fRawBitmap.height(),
fRawBitmap.bytesPerPixel());
-
+
// add the pixelref
SkPixelRef* pr = fRawBitmap.pixelRef();
if (pr) {
@@ -296,7 +296,7 @@
str->appendf(" \"%s\"", uri);
}
}
-
+
// add the (optional) matrix
{
SkMatrix m;
@@ -306,7 +306,7 @@
str->appendf(" %s", info.c_str());
}
}
-
+
str->appendf(" [%s %s]]",
gTileModeName[fState.fTileModeX],
gTileModeName[fState.fTileModeY]);
diff --git a/src/core/SkBitmapProcShader.h b/src/core/SkBitmapProcShader.h
index 88598fc..bd19b75 100644
--- a/src/core/SkBitmapProcShader.h
+++ b/src/core/SkBitmapProcShader.h
@@ -2,16 +2,16 @@
**
** Copyright 2006, The Android Open Source Project
**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
**
-** http://www.apache.org/licenses/LICENSE-2.0
+** http://www.apache.org/licenses/LICENSE-2.0
**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
** limitations under the License.
*/
@@ -32,12 +32,12 @@
virtual void shadeSpan16(int x, int y, uint16_t dstC[], int count);
virtual void beginSession();
virtual void endSession();
- virtual BitmapType asABitmap(SkBitmap*, SkMatrix*, TileMode*,
- SkScalar* twoPointRadialParams);
+ virtual BitmapType asABitmap(SkBitmap*, SkMatrix*, TileMode*,
+ SkScalar* twoPointRadialParams) const;
static bool CanDo(const SkBitmap&, TileMode tx, TileMode ty);
- static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
+ static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
return SkNEW_ARGS(SkBitmapProcShader, (buffer));
}
@@ -53,7 +53,7 @@
SkBitmapProcState fState;
uint32_t fFlags;
-private:
+private:
typedef SkShader INHERITED;
};
diff --git a/src/core/SkShader.cpp b/src/core/SkShader.cpp
index 6798bec..015389e 100644
--- a/src/core/SkShader.cpp
+++ b/src/core/SkShader.cpp
@@ -2,16 +2,16 @@
**
** Copyright 2006, The Android Open Source Project
**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
**
-** http://www.apache.org/licenses/LICENSE-2.0
+** http://www.apache.org/licenses/LICENSE-2.0
**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
** limitations under the License.
*/
@@ -120,7 +120,7 @@
}
#define kTempColorQuadCount 6 // balance between speed (larger) and saving stack-space
-#define kTempColorCount (kTempColorQuadCount << 2)
+#define kTempColorCount (kTempColorQuadCount << 2)
#ifdef SK_CPU_BENDIAN
#define SkU32BitShiftToByteOffset(shift) (3 - ((shift) >> 3))
@@ -198,7 +198,7 @@
//////////////////////////////////////////////////////////////////////////////
SkShader::BitmapType SkShader::asABitmap(SkBitmap*, SkMatrix*,
- TileMode*, SkScalar*) {
+ TileMode*, SkScalar*) const {
return kNone_BitmapType;
}
@@ -311,7 +311,7 @@
// if we had a asAColor method, that would be more efficient...
SkShader::BitmapType SkColorShader::asABitmap(SkBitmap* bitmap, SkMatrix* matrix,
- TileMode modes[],
+ TileMode modes[],
SkScalar* twoPointRadialParams) {
// we cache the pixelref, since its generateID is used in the texture cache
if (NULL == fAsABitmapPixelRef) {
@@ -320,7 +320,7 @@
fAsABitmapPixelRef = new SkMallocPixelRef(storage, sizeof(SkPMColor),
NULL);
}
-
+
if (bitmap) {
bitmap->setConfig(SkBitmap::kARGB_8888_Config, 1, 1);
bitmap->setPixelRef(fAsABitmapPixelRef);
diff --git a/src/effects/SkGradientShader.cpp b/src/effects/SkGradientShader.cpp
index 41b97cc..3452212 100644
--- a/src/effects/SkGradientShader.cpp
+++ b/src/effects/SkGradientShader.cpp
@@ -123,12 +123,10 @@
kCache32Count = 1 << kCache32Bits
};
virtual void flatten(SkFlattenableWriteBuffer& );
- const uint16_t* getCache16();
- const SkPMColor* getCache32();
+ const uint16_t* getCache16() const;
+ const SkPMColor* getCache32() const;
- SkMallocPixelRef* fCache32PixelRef;
-
- void commonAsABitmap(SkBitmap*);
+ void commonAsABitmap(SkBitmap*) const;
void commonAsAGradient(GradientInfo*) const;
private:
@@ -140,10 +138,11 @@
SkColor fStorage[(kStorageSize + 3) >> 2];
SkColor* fOrigColors;
- uint16_t* fCache16; // working ptr. If this is NULL, we need to recompute the cache values
- SkPMColor* fCache32; // working ptr. If this is NULL, we need to recompute the cache values
+ mutable uint16_t* fCache16; // working ptr. If this is NULL, we need to recompute the cache values
+ mutable SkPMColor* fCache32; // working ptr. If this is NULL, we need to recompute the cache values
- uint16_t* fCache16Storage; // storage for fCache16, allocated on demand
+ mutable uint16_t* fCache16Storage; // storage for fCache16, allocated on demand
+ mutable SkMallocPixelRef* fCache32PixelRef;
unsigned fCacheAlpha; // the alpha value we used when we computed the cache. larger than 8bits so we can store uninitialized value
static void Build16bitCache(uint16_t[], SkColor c0, SkColor c1, int count);
@@ -536,7 +535,7 @@
return 0;
}
-const uint16_t* Gradient_Shader::getCache16() {
+const uint16_t* Gradient_Shader::getCache16() const {
if (fCache16 == NULL) {
// double the count for dither entries
const int entryCount = kCache16Count * 2;
@@ -579,7 +578,7 @@
return fCache16;
}
-const SkPMColor* Gradient_Shader::getCache32() {
+const SkPMColor* Gradient_Shader::getCache32() const {
if (fCache32 == NULL) {
// double the count for dither entries
const int entryCount = kCache32Count * 2;
@@ -636,7 +635,7 @@
* colors and positions. Note: we don't try to flatten the fMapper, so if one
* is present, we skip the cache for now.
*/
-void Gradient_Shader::commonAsABitmap(SkBitmap* bitmap) {
+void Gradient_Shader::commonAsABitmap(SkBitmap* bitmap) const {
// don't have a way to put the mapper into our cache-key yet
if (fMapper) {
// force our cahce32pixelref to be built
@@ -741,7 +740,7 @@
virtual void shadeSpan(int x, int y, SkPMColor dstC[], int count);
virtual void shadeSpan16(int x, int y, uint16_t dstC[], int count);
virtual BitmapType asABitmap(SkBitmap*, SkMatrix*,
- TileMode*, SkScalar* twoPointRadialParams);
+ TileMode*, SkScalar* twoPointRadialParams) const;
virtual GradientType asAGradient(GradientInfo* info) const;
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
@@ -875,7 +874,7 @@
SkShader::BitmapType Linear_Gradient::asABitmap(SkBitmap* bitmap,
SkMatrix* matrix,
TileMode xy[],
- SkScalar* twoPointRadialParams) {
+ SkScalar* twoPointRadialParams) const {
if (bitmap) {
this->commonAsABitmap(bitmap);
}
@@ -1236,7 +1235,7 @@
virtual BitmapType asABitmap(SkBitmap* bitmap,
SkMatrix* matrix,
TileMode* xy,
- SkScalar* twoPointRadialParams) {
+ SkScalar* twoPointRadialParams) const {
if (bitmap) {
this->commonAsABitmap(bitmap);
}
@@ -1388,7 +1387,7 @@
virtual BitmapType asABitmap(SkBitmap* bitmap,
SkMatrix* matrix,
TileMode* xy,
- SkScalar* twoPointRadialParams) {
+ SkScalar* twoPointRadialParams) const {
if (bitmap) {
this->commonAsABitmap(bitmap);
}
@@ -1604,7 +1603,7 @@
virtual BitmapType asABitmap(SkBitmap* bitmap,
SkMatrix* matrix,
TileMode* xy,
- SkScalar* twoPointRadialParams) {
+ SkScalar* twoPointRadialParams) const {
if (bitmap) {
this->commonAsABitmap(bitmap);
}