summaryrefslogtreecommitdiffstats
path: root/skia/effects
diff options
context:
space:
mode:
authorbrettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-12 21:01:41 +0000
committerbrettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-12 21:01:41 +0000
commit52e935d04c59135739c3a68fb6e19d313dc6d5ad (patch)
tree95f7ab178b045bef4456cbf92c6aa7e476becd99 /skia/effects
parent30fab79877b4bb067944b74d98346ac9bb6bfc7e (diff)
downloadchromium_src-52e935d04c59135739c3a68fb6e19d313dc6d5ad.zip
chromium_src-52e935d04c59135739c3a68fb6e19d313dc6d5ad.tar.gz
chromium_src-52e935d04c59135739c3a68fb6e19d313dc6d5ad.tar.bz2
New drop of Skia. This is up to CL 121320.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6925 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia/effects')
-rw-r--r--skia/effects/Sk1DPathEffect.cpp2
-rw-r--r--skia/effects/Sk2DPathEffect.cpp2
-rw-r--r--skia/effects/SkAvoidXfermode.cpp2
-rw-r--r--skia/effects/SkBlurDrawLooper.cpp5
-rw-r--r--skia/effects/SkBlurMask.cpp2
-rw-r--r--skia/effects/SkBlurMask.h2
-rw-r--r--skia/effects/SkBlurMaskFilter.cpp10
-rw-r--r--skia/effects/SkCamera.cpp2
-rw-r--r--skia/effects/SkColorFilters.cpp2
-rw-r--r--skia/effects/SkColorMatrixFilter.cpp38
-rw-r--r--skia/effects/SkCornerPathEffect.cpp2
-rw-r--r--skia/effects/SkCullPoints.cpp10
-rw-r--r--skia/effects/SkDashPathEffect.cpp2
-rw-r--r--skia/effects/SkDiscretePathEffect.cpp2
-rw-r--r--skia/effects/SkEmbossMask.cpp2
-rw-r--r--skia/effects/SkEmbossMask.h2
-rw-r--r--skia/effects/SkEmbossMaskFilter.cpp2
-rw-r--r--skia/effects/SkEmbossMask_Table.h2
-rw-r--r--skia/effects/SkGradientShader.cpp34
-rw-r--r--skia/effects/SkLayerDrawLooper.cpp130
-rw-r--r--skia/effects/SkLayerRasterizer.cpp2
-rw-r--r--skia/effects/SkNinePatch.cpp75
-rw-r--r--skia/effects/SkRadialGradient_Table.h2
-rw-r--r--skia/effects/SkShaderExtras.cpp2
-rw-r--r--skia/effects/SkTransparentShader.cpp2
25 files changed, 272 insertions, 66 deletions
diff --git a/skia/effects/Sk1DPathEffect.cpp b/skia/effects/Sk1DPathEffect.cpp
index 325d402..fe299c9 100644
--- a/skia/effects/Sk1DPathEffect.cpp
+++ b/skia/effects/Sk1DPathEffect.cpp
@@ -1,6 +1,6 @@
/* libs/graphics/effects/Sk1DPathEffect.cpp
**
-** Copyright 2006, Google Inc.
+** 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.
diff --git a/skia/effects/Sk2DPathEffect.cpp b/skia/effects/Sk2DPathEffect.cpp
index 48c3a4c..405b194 100644
--- a/skia/effects/Sk2DPathEffect.cpp
+++ b/skia/effects/Sk2DPathEffect.cpp
@@ -1,6 +1,6 @@
/* libs/graphics/effects/Sk2DPathEffect.cpp
**
-** Copyright 2006, Google Inc.
+** 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.
diff --git a/skia/effects/SkAvoidXfermode.cpp b/skia/effects/SkAvoidXfermode.cpp
index 6781e9f..eed4012 100644
--- a/skia/effects/SkAvoidXfermode.cpp
+++ b/skia/effects/SkAvoidXfermode.cpp
@@ -1,6 +1,6 @@
/* libs/graphics/effects/SkAvoidXfermode.cpp
**
-** Copyright 2006, Google Inc.
+** 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.
diff --git a/skia/effects/SkBlurDrawLooper.cpp b/skia/effects/SkBlurDrawLooper.cpp
index 61b69eb..6ad0136 100644
--- a/skia/effects/SkBlurDrawLooper.cpp
+++ b/skia/effects/SkBlurDrawLooper.cpp
@@ -84,3 +84,8 @@ void SkBlurDrawLooper::restore()
}
}
+///////////////////////////////////////////////////////////////////////////////
+
+static SkFlattenable::Registrar gReg("SkBlurDrawLooper",
+ SkBlurDrawLooper::CreateProc);
+
diff --git a/skia/effects/SkBlurMask.cpp b/skia/effects/SkBlurMask.cpp
index f2c07a8..a7b3202 100644
--- a/skia/effects/SkBlurMask.cpp
+++ b/skia/effects/SkBlurMask.cpp
@@ -1,6 +1,6 @@
/* libs/graphics/effects/SkBlurMask.cpp
**
-** Copyright 2006, Google Inc.
+** 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.
diff --git a/skia/effects/SkBlurMask.h b/skia/effects/SkBlurMask.h
index 2df5731..8f61d54 100644
--- a/skia/effects/SkBlurMask.h
+++ b/skia/effects/SkBlurMask.h
@@ -1,6 +1,6 @@
/* libs/graphics/effects/SkBlurMask.h
**
-** Copyright 2006, Google Inc.
+** 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.
diff --git a/skia/effects/SkBlurMaskFilter.cpp b/skia/effects/SkBlurMaskFilter.cpp
index 3ff1d81..2db60a5 100644
--- a/skia/effects/SkBlurMaskFilter.cpp
+++ b/skia/effects/SkBlurMaskFilter.cpp
@@ -1,6 +1,6 @@
/* libs/graphics/effects/SkBlurMaskFilter.cpp
**
-** Copyright 2006, Google Inc.
+** 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.
@@ -34,11 +34,12 @@ public:
// This method is not exported to java.
virtual void flatten(SkFlattenableWriteBuffer&);
+ static SkFlattenable* CreateProc(SkFlattenableReadBuffer&);
+
private:
SkScalar fRadius;
SkBlurMaskFilter::BlurStyle fBlurStyle;
- static SkFlattenable* CreateProc(SkFlattenableReadBuffer&);
SkBlurMaskFilterImpl(SkFlattenableReadBuffer&);
typedef SkMaskFilter INHERITED;
@@ -115,3 +116,8 @@ void SkBlurMaskFilterImpl::flatten(SkFlattenableWriteBuffer& buffer)
buffer.write32(fBlurStyle);
}
+///////////////////////////////////////////////////////////////////////////////
+
+static SkFlattenable::Registrar gReg("SkBlurMaskFilter",
+ SkBlurMaskFilterImpl::CreateProc);
+
diff --git a/skia/effects/SkCamera.cpp b/skia/effects/SkCamera.cpp
index 469b175..b02499f 100644
--- a/skia/effects/SkCamera.cpp
+++ b/skia/effects/SkCamera.cpp
@@ -1,6 +1,6 @@
/* libs/graphics/effects/SkCamera.cpp
**
-** Copyright 2006, Google Inc.
+** 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.
diff --git a/skia/effects/SkColorFilters.cpp b/skia/effects/SkColorFilters.cpp
index f5178a8..50be1ad 100644
--- a/skia/effects/SkColorFilters.cpp
+++ b/skia/effects/SkColorFilters.cpp
@@ -1,6 +1,6 @@
/* libs/graphics/effects/SkColorFilters.cpp
**
-** Copyright 2006, Google Inc.
+** 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.
diff --git a/skia/effects/SkColorMatrixFilter.cpp b/skia/effects/SkColorMatrixFilter.cpp
index 751cd30..07c8d2f 100644
--- a/skia/effects/SkColorMatrixFilter.cpp
+++ b/skia/effects/SkColorMatrixFilter.cpp
@@ -65,9 +65,10 @@ static void ScaleAdd(SkColorMatrixFilter::State* state,
const int shift = state->fShift;
int32_t* SK_RESTRICT result = state->fResult;
- result[0] = (array[0] * r + array[4]) >> shift;
- result[1] = (array[6] * g + array[9]) >> shift;
- result[2] = (array[12] * b + array[14]) >> shift;
+ // cast to (int) to keep the expression signed for the shift
+ result[0] = (array[0] * (int)r + array[4]) >> shift;
+ result[1] = (array[6] * (int)g + array[9]) >> shift;
+ result[2] = (array[12] * (int)b + array[14]) >> shift;
result[3] = a;
}
@@ -76,9 +77,10 @@ static void ScaleAdd16(SkColorMatrixFilter::State* state,
const int32_t* SK_RESTRICT array = state->fArray;
int32_t* SK_RESTRICT result = state->fResult;
- result[0] = (array[0] * r + array[4]) >> 16;
- result[1] = (array[6] * g + array[9]) >> 16;
- result[2] = (array[12] * b + array[14]) >> 16;
+ // cast to (int) to keep the expression signed for the shift
+ result[0] = (array[0] * (int)r + array[4]) >> 16;
+ result[1] = (array[6] * (int)g + array[9]) >> 16;
+ result[2] = (array[12] * (int)b + array[14]) >> 16;
result[3] = a;
}
@@ -137,7 +139,7 @@ void SkColorMatrixFilter::setup(const SkScalar SK_RESTRICT src[20]) {
fState.fShift = 16; // we are starting out as fixed 16.16
if (bits < 9) {
- bits = 8 - bits;
+ bits = 9 - bits;
fState.fShift -= bits;
for (i = 0; i < 20; i++) {
array[i] >>= bits;
@@ -269,9 +271,6 @@ void SkColorMatrixFilter::filterSpan(const SkPMColor src[], int count,
}
}
-#define SK_RG_BITS_DIFF (SK_G16_BITS - SK_R16_BITS)
-#define SK_BG_BITS_DIFF (SK_G16_BITS - SK_B16_BITS)
-
void SkColorMatrixFilter::filterSpan16(const uint16_t src[], int count,
uint16_t dst[]) {
SkASSERT(fFlags & SkColorFilter::kHasFilter16_Flag);
@@ -290,18 +289,19 @@ void SkColorMatrixFilter::filterSpan16(const uint16_t src[], int count,
for (int i = 0; i < count; i++) {
uint16_t c = src[i];
- unsigned r = SkGetPackedR16(c);
- unsigned g = SkGetPackedG16(c);
- unsigned b = SkGetPackedB16(c);
+ // expand to 8bit components (since our matrix translate is 8bit biased
+ unsigned r = SkPacked16ToR32(c);
+ unsigned g = SkPacked16ToG32(c);
+ unsigned b = SkPacked16ToB32(c);
- r = (r << SK_RG_BITS_DIFF) | (r >> (SK_R16_BITS - 1));
- b = (b << SK_BG_BITS_DIFF) | (b >> (SK_B16_BITS - 1));
proc(state, r, g, b, 0);
- r = pin(result[0], SK_G16_MASK) >> SK_RG_BITS_DIFF;
- g = pin(result[1], SK_G16_MASK);
- b = pin(result[2], SK_G16_MASK) >> SK_BG_BITS_DIFF;
- dst[i] = SkPackRGB16(r, g, b);
+ r = pin(result[0], SK_R32_MASK);
+ g = pin(result[1], SK_G32_MASK);
+ b = pin(result[2], SK_B32_MASK);
+
+ // now packed it back down to 16bits (hmmm, could dither...)
+ dst[i] = SkPack888ToRGB16(r, g, b);
}
}
diff --git a/skia/effects/SkCornerPathEffect.cpp b/skia/effects/SkCornerPathEffect.cpp
index ad92af1..43d571a 100644
--- a/skia/effects/SkCornerPathEffect.cpp
+++ b/skia/effects/SkCornerPathEffect.cpp
@@ -1,6 +1,6 @@
/* libs/graphics/effects/SkCornerPathEffect.cpp
**
-** Copyright 2006, Google Inc.
+** 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.
diff --git a/skia/effects/SkCullPoints.cpp b/skia/effects/SkCullPoints.cpp
index 1b50349..23d00b6 100644
--- a/skia/effects/SkCullPoints.cpp
+++ b/skia/effects/SkCullPoints.cpp
@@ -1,6 +1,6 @@
/* libs/graphics/effects/SkCullPoints.cpp
**
-** Copyright 2006, Google Inc.
+** 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.
@@ -36,10 +36,10 @@ bool SkCullPoints::sect_test(int x0, int y0, int x1, int y1) const
{
const SkIRect& r = fR;
- if ((x0 < r.fLeft && x1 < r.fLeft) ||
- (x0 > r.fRight && x1 > r.fRight) ||
- (y0 < r.fTop && y1 < r.fTop) ||
- (y0 > r.fBottom && y1 > r.fBottom))
+ if (x0 < r.fLeft && x1 < r.fLeft ||
+ x0 > r.fRight && x1 > r.fRight ||
+ y0 < r.fTop && y1 < r.fTop ||
+ y0 > r.fBottom && y1 > r.fBottom)
return false;
// since the crossprod test is a little expensive, check for easy-in cases first
diff --git a/skia/effects/SkDashPathEffect.cpp b/skia/effects/SkDashPathEffect.cpp
index 2c29009..48581b5 100644
--- a/skia/effects/SkDashPathEffect.cpp
+++ b/skia/effects/SkDashPathEffect.cpp
@@ -1,6 +1,6 @@
/* libs/graphics/effects/SkDashPathEffect.cpp
**
-** Copyright 2006, Google Inc.
+** 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.
diff --git a/skia/effects/SkDiscretePathEffect.cpp b/skia/effects/SkDiscretePathEffect.cpp
index d19b23a..6286045 100644
--- a/skia/effects/SkDiscretePathEffect.cpp
+++ b/skia/effects/SkDiscretePathEffect.cpp
@@ -1,6 +1,6 @@
/* libs/graphics/effects/SkDiscretePathEffect.cpp
**
-** Copyright 2006, Google Inc.
+** 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.
diff --git a/skia/effects/SkEmbossMask.cpp b/skia/effects/SkEmbossMask.cpp
index 9a77df1..28e38a1 100644
--- a/skia/effects/SkEmbossMask.cpp
+++ b/skia/effects/SkEmbossMask.cpp
@@ -1,6 +1,6 @@
/* libs/graphics/effects/SkEmbossMask.cpp
**
-** Copyright 2006, Google Inc.
+** 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.
diff --git a/skia/effects/SkEmbossMask.h b/skia/effects/SkEmbossMask.h
index 093e53d..8e56d6f 100644
--- a/skia/effects/SkEmbossMask.h
+++ b/skia/effects/SkEmbossMask.h
@@ -1,6 +1,6 @@
/* libs/graphics/effects/SkEmbossMask.h
**
-** Copyright 2006, Google Inc.
+** 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.
diff --git a/skia/effects/SkEmbossMaskFilter.cpp b/skia/effects/SkEmbossMaskFilter.cpp
index 0af2ae05..fcfad9d 100644
--- a/skia/effects/SkEmbossMaskFilter.cpp
+++ b/skia/effects/SkEmbossMaskFilter.cpp
@@ -1,6 +1,6 @@
/* libs/graphics/effects/SkEmbossMaskFilter.cpp
**
-** Copyright 2006, Google Inc.
+** 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.
diff --git a/skia/effects/SkEmbossMask_Table.h b/skia/effects/SkEmbossMask_Table.h
index d936c32..775fe25 100644
--- a/skia/effects/SkEmbossMask_Table.h
+++ b/skia/effects/SkEmbossMask_Table.h
@@ -1,6 +1,6 @@
/* libs/graphics/effects/SkEmbossMask_Table.h
**
-** Copyright 2006, Google Inc.
+** 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.
diff --git a/skia/effects/SkGradientShader.cpp b/skia/effects/SkGradientShader.cpp
index 1f279f9..a1674cb 100644
--- a/skia/effects/SkGradientShader.cpp
+++ b/skia/effects/SkGradientShader.cpp
@@ -1,6 +1,6 @@
/* libs/graphics/effects/SkGradientShader.cpp
**
-** Copyright 2006, Google Inc.
+** 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.
@@ -607,15 +607,12 @@ private:
typedef Gradient_Shader INHERITED;
};
-#if 0
-// Used by a section that's currently #if 0 Linear_Gradient::shadeSpan
// Return true if fx, fx+dx, fx+2*dx, ... is always in range
static bool no_need_for_clamp(int fx, int dx, int count)
{
SkASSERT(count > 0);
return (unsigned)((fx | (fx + (count - 1) * dx)) >> 8) <= 0xFF;
}
-#endif
void Linear_Gradient::shadeSpan(int x, int y, SkPMColor dstC[], int count)
{
@@ -1505,11 +1502,26 @@ void Sweep_Gradient::shadeSpan16(int x, int y, uint16_t dstC[], int count)
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
+// assumes colors is SkColor* and pos is SkScalar*
+#define EXPAND_1_COLOR(count) \
+ SkColor tmp[2]; \
+ do { \
+ if (1 == count) { \
+ tmp[0] = tmp[1] = colors[0]; \
+ colors = tmp; \
+ pos = NULL; \
+ count = 2; \
+ } \
+ } while (0)
+
SkShader* SkGradientShader::CreateLinear( const SkPoint pts[2],
const SkColor colors[], const SkScalar pos[], int colorCount,
SkShader::TileMode mode, SkUnitMapper* mapper)
{
- SkASSERT(pts && colors && colorCount >= 2);
+ if (NULL == pts || NULL == colors || colorCount < 1) {
+ return NULL;
+ }
+ EXPAND_1_COLOR(colorCount);
return SkNEW_ARGS(Linear_Gradient, (pts, colors, pos, colorCount, mode, mapper));
}
@@ -1518,7 +1530,10 @@ SkShader* SkGradientShader::CreateRadial( const SkPoint& center, SkScalar radi
const SkColor colors[], const SkScalar pos[], int colorCount,
SkShader::TileMode mode, SkUnitMapper* mapper)
{
- SkASSERT(radius > 0 && colors && colorCount >= 2);
+ if (radius <= 0 || NULL == colors || colorCount < 1) {
+ return NULL;
+ }
+ EXPAND_1_COLOR(colorCount);
return SkNEW_ARGS(Radial_Gradient, (center, radius, colors, pos, colorCount, mode, mapper));
}
@@ -1528,8 +1543,11 @@ SkShader* SkGradientShader::CreateSweep(SkScalar cx, SkScalar cy,
const SkScalar pos[],
int count, SkUnitMapper* mapper)
{
- SkASSERT(colors && count >= 2);
-
+ if (NULL == colors || count < 1) {
+ return NULL;
+ }
+ EXPAND_1_COLOR(count);
+
return SkNEW_ARGS(Sweep_Gradient, (cx, cy, colors, pos, count, mapper));
}
diff --git a/skia/effects/SkLayerDrawLooper.cpp b/skia/effects/SkLayerDrawLooper.cpp
new file mode 100644
index 0000000..f2d8ba8
--- /dev/null
+++ b/skia/effects/SkLayerDrawLooper.cpp
@@ -0,0 +1,130 @@
+#include "SkCanvas.h"
+#include "SkLayerDrawLooper.h"
+#include "SkPaint.h"
+
+SkLayerDrawLooper::SkLayerDrawLooper() {
+ fRecs = NULL;
+ fCount = 0;
+}
+
+SkLayerDrawLooper::~SkLayerDrawLooper() {
+ Rec* rec = fRecs;
+ while (rec) {
+ Rec* next = rec->fNext;
+ SkDELETE(rec);
+ rec = next;
+ }
+}
+
+SkPaint* SkLayerDrawLooper::addLayer(SkScalar dx, SkScalar dy) {
+ fCount += 1;
+
+ Rec* rec = SkNEW(Rec);
+ rec->fNext = fRecs;
+ rec->fOffset.set(dx, dy);
+ fRecs = rec;
+
+ return &rec->fPaint;
+}
+
+void SkLayerDrawLooper::init(SkCanvas* canvas, SkPaint* paint) {
+ fIter.fSavedPaint = *paint;
+ fIter.fPaint = paint;
+ fIter.fCanvas = canvas;
+ fIter.fRec = fRecs;
+ canvas->save(SkCanvas::kMatrix_SaveFlag);
+}
+
+bool SkLayerDrawLooper::next() {
+ Rec* rec = fIter.fRec;
+ if (rec) {
+ *fIter.fPaint = rec->fPaint;
+ fIter.fCanvas->restore();
+ fIter.fCanvas->save(SkCanvas::kMatrix_SaveFlag);
+ fIter.fCanvas->translate(rec->fOffset.fX, rec->fOffset.fY);
+
+ fIter.fRec = rec->fNext;
+ return true;
+ }
+ return false;
+}
+
+void SkLayerDrawLooper::restore() {
+ fIter.fCanvas->restore();
+ *fIter.fPaint = fIter.fSavedPaint;
+}
+
+SkLayerDrawLooper::Rec* SkLayerDrawLooper::Rec::Reverse(Rec* head) {
+ Rec* rec = head;
+ Rec* prev = NULL;
+ while (rec) {
+ Rec* next = rec->fNext;
+ rec->fNext = prev;
+ prev = rec;
+ rec = next;
+ }
+ return prev;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
+void SkLayerDrawLooper::flatten(SkFlattenableWriteBuffer& buffer) {
+ this->INHERITED::flatten(buffer);
+
+#ifdef SK_DEBUG
+ {
+ Rec* rec = fRecs;
+ int count = 0;
+ while (rec) {
+ rec = rec->fNext;
+ count += 1;
+ }
+ SkASSERT(count == fCount);
+ }
+#endif
+
+ buffer.writeInt(fCount);
+
+ Rec* rec = fRecs;
+ for (int i = 0; i < fCount; i++) {
+ buffer.writeScalar(rec->fOffset.fX);
+ buffer.writeScalar(rec->fOffset.fY);
+ rec->fPaint.flatten(buffer);
+ rec = rec->fNext;
+ }
+}
+
+SkLayerDrawLooper::SkLayerDrawLooper(SkFlattenableReadBuffer& buffer)
+ : INHERITED(buffer) {
+ fRecs = NULL;
+ fCount = 0;
+
+ int count = buffer.readInt();
+
+ for (int i = 0; i < count; i++) {
+ SkScalar dx = buffer.readScalar();
+ SkScalar dy = buffer.readScalar();
+ this->addLayer(dx, dy)->unflatten(buffer);
+ }
+ SkASSERT(count == fCount);
+
+ // we're in reverse order, so fix it now
+ fRecs = Rec::Reverse(fRecs);
+
+#ifdef SK_DEBUG
+ {
+ Rec* rec = fRecs;
+ int n = 0;
+ while (rec) {
+ rec = rec->fNext;
+ n += 1;
+ }
+ SkASSERT(count == n);
+ }
+#endif
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
+static SkFlattenable::Registrar gReg("SkLayerDrawLooper",
+ SkLayerDrawLooper::CreateProc);
diff --git a/skia/effects/SkLayerRasterizer.cpp b/skia/effects/SkLayerRasterizer.cpp
index b21f885..390e3a3 100644
--- a/skia/effects/SkLayerRasterizer.cpp
+++ b/skia/effects/SkLayerRasterizer.cpp
@@ -1,6 +1,6 @@
/* libs/graphics/effects/SkLayerRasterizer.cpp
**
-** Copyright 2006, Google Inc.
+** 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.
diff --git a/skia/effects/SkNinePatch.cpp b/skia/effects/SkNinePatch.cpp
index 267c39e..b8e11fb 100644
--- a/skia/effects/SkNinePatch.cpp
+++ b/skia/effects/SkNinePatch.cpp
@@ -1,5 +1,5 @@
/*
-** Copyright 2006, Google Inc.
+** 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.
@@ -90,10 +90,10 @@ void SkNinePatch::DrawMesh(SkCanvas* canvas, const SkRect& bounds,
return;
}
- // should try a quick-reject test before calling lockPixels <reed>
+ // should try a quick-reject test before calling lockPixels
SkAutoLockPixels alp(bitmap);
- // after the lock, it is valid to check getPixels()
- if (bitmap.getPixels() == NULL) {
+ // after the lock, it is valid to check
+ if (!bitmap.readyToDraw()) {
return;
}
@@ -224,17 +224,64 @@ void SkNinePatch::DrawMesh(SkCanvas* canvas, const SkRect& bounds,
mesh.fIndices, indexCount, p);
}
+///////////////////////////////////////////////////////////////////////////////
+
+static void drawNineViaRects(SkCanvas* canvas, const SkRect& dst,
+ const SkBitmap& bitmap, const SkIRect& margins,
+ const SkPaint* paint) {
+ const int32_t srcX[4] = {
+ 0, margins.fLeft, bitmap.width() - margins.fRight, bitmap.width()
+ };
+ const int32_t srcY[4] = {
+ 0, margins.fTop, bitmap.height() - margins.fBottom, bitmap.height()
+ };
+ const SkScalar dstX[4] = {
+ dst.fLeft, dst.fLeft + SkIntToScalar(margins.fLeft),
+ dst.fRight - SkIntToScalar(margins.fRight), dst.fRight
+ };
+ const SkScalar dstY[4] = {
+ dst.fTop, dst.fTop + SkIntToScalar(margins.fTop),
+ dst.fBottom - SkIntToScalar(margins.fBottom), dst.fBottom
+ };
+
+ SkIRect s;
+ SkRect d;
+ for (int y = 0; y < 3; y++) {
+ s.fTop = srcY[y];
+ s.fBottom = srcY[y+1];
+ d.fTop = dstY[y];
+ d.fBottom = dstY[y+1];
+ for (int x = 0; x < 3; x++) {
+ s.fLeft = srcX[x];
+ s.fRight = srcX[x+1];
+ d.fLeft = dstX[x];
+ d.fRight = dstX[x+1];
+ canvas->drawBitmapRect(bitmap, &s, d, paint);
+ }
+ }
+}
+
void SkNinePatch::DrawNine(SkCanvas* canvas, const SkRect& bounds,
const SkBitmap& bitmap, const SkIRect& margins,
const SkPaint* paint) {
- int32_t xDivs[2];
- int32_t yDivs[2];
-
- xDivs[0] = margins.fLeft;
- xDivs[1] = bitmap.width() - margins.fRight;
- yDivs[0] = margins.fTop;
- yDivs[1] = bitmap.height() - margins.fBottom;
-
- SkNinePatch::DrawMesh(canvas, bounds, bitmap, xDivs, 2, yDivs, 2, paint);
+ /** Our vertices code has numerical precision problems if the transformed
+ coordinates land directly on a 1/2 pixel boundary. To work around that
+ for now, we only take the vertices case if we are in opengl. Also,
+ when not in GL, the vertices impl is slower (more math) than calling
+ the viaRects code.
+ */
+ if (canvas->getViewport(NULL)) { // returns true for OpenGL
+ int32_t xDivs[2];
+ int32_t yDivs[2];
+
+ xDivs[0] = margins.fLeft;
+ xDivs[1] = bitmap.width() - margins.fRight;
+ yDivs[0] = margins.fTop;
+ yDivs[1] = bitmap.height() - margins.fBottom;
+
+ SkNinePatch::DrawMesh(canvas, bounds, bitmap,
+ xDivs, 2, yDivs, 2, paint);
+ } else {
+ drawNineViaRects(canvas, bounds, bitmap, margins, paint);
+ }
}
-
diff --git a/skia/effects/SkRadialGradient_Table.h b/skia/effects/SkRadialGradient_Table.h
index ed9712f..2336237 100644
--- a/skia/effects/SkRadialGradient_Table.h
+++ b/skia/effects/SkRadialGradient_Table.h
@@ -1,6 +1,6 @@
/* libs/graphics/effects/SkRadialGradient_Table.h
**
-** Copyright 2006, Google Inc.
+** 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.
diff --git a/skia/effects/SkShaderExtras.cpp b/skia/effects/SkShaderExtras.cpp
index 6bfe517..84a1647 100644
--- a/skia/effects/SkShaderExtras.cpp
+++ b/skia/effects/SkShaderExtras.cpp
@@ -1,6 +1,6 @@
/* libs/graphics/effects/SkShaderExtras.cpp
**
-** Copyright 2006, Google Inc.
+** 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.
diff --git a/skia/effects/SkTransparentShader.cpp b/skia/effects/SkTransparentShader.cpp
index 0c08543..6b79839 100644
--- a/skia/effects/SkTransparentShader.cpp
+++ b/skia/effects/SkTransparentShader.cpp
@@ -1,6 +1,6 @@
/* libs/graphics/effects/SkTransparentShader.cpp
**
-** Copyright 2006, Google Inc.
+** 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.