SkPaint: eliminate some dead bytes in 64-bit build.

+ memcpy-based copy constructor was hiding this gap -> manual copy constructor.
+ Split tests for finer-grained failures.

BUG=skia:

Committed: http://code.google.com/p/skia/source/detail?r=13856

R=reed@google.com, mtklein@google.com

Author: mtklein@chromium.org

Review URL: https://codereview.chromium.org/203203003

git-svn-id: http://skia.googlecode.com/svn/trunk@13887 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
commit-bot@chromium.org 2014-03-20 23:02:35 +00:00
Родитель 9615d5fc04
Коммит f48182b161
3 изменённых файлов: 38 добавлений и 40 удалений

Просмотреть файл

@ -1046,10 +1046,6 @@ public:
private: private:
SkTypeface* fTypeface; SkTypeface* fTypeface;
SkScalar fTextSize;
SkScalar fTextScaleX;
SkScalar fTextSkewX;
SkPathEffect* fPathEffect; SkPathEffect* fPathEffect;
SkShader* fShader; SkShader* fShader;
SkXfermode* fXfermode; SkXfermode* fXfermode;
@ -1060,10 +1056,12 @@ private:
SkImageFilter* fImageFilter; SkImageFilter* fImageFilter;
SkAnnotation* fAnnotation; SkAnnotation* fAnnotation;
SkScalar fTextSize;
SkScalar fTextScaleX;
SkScalar fTextSkewX;
SkColor fColor; SkColor fColor;
SkScalar fWidth; SkScalar fWidth;
SkScalar fMiterLimit; SkScalar fMiterLimit;
union { union {
struct { struct {
// all of these bitfields should add up to 32 // all of these bitfields should add up to 32
@ -1078,11 +1076,11 @@ private:
}; };
uint32_t fBitfields; uint32_t fBitfields;
}; };
uint32_t fDirtyBits;
uint32_t getBitfields() const { return fBitfields; } uint32_t getBitfields() const { return fBitfields; }
void setBitfields(uint32_t bitfields); void setBitfields(uint32_t bitfields);
uint32_t fDirtyBits;
SkDrawCacheProc getDrawCacheProc() const; SkDrawCacheProc getDrawCacheProc() const;
SkMeasureCacheProc getMeasureCacheProc(TextBufferDirection dir, SkMeasureCacheProc getMeasureCacheProc(TextBufferDirection dir,
bool needFullMetrics) const; bool needFullMetrics) const;

Просмотреть файл

@ -108,22 +108,35 @@ SkPaint::SkPaint() {
} }
SkPaint::SkPaint(const SkPaint& src) { SkPaint::SkPaint(const SkPaint& src) {
memcpy(this, &src, sizeof(src)); #define COPY(field) field = src.field
#define REF_COPY(field) field = SkSafeRef(src.field)
REF_COPY(fTypeface);
REF_COPY(fPathEffect);
REF_COPY(fShader);
REF_COPY(fXfermode);
REF_COPY(fMaskFilter);
REF_COPY(fColorFilter);
REF_COPY(fRasterizer);
REF_COPY(fLooper);
REF_COPY(fImageFilter);
REF_COPY(fAnnotation);
SkSafeRef(fTypeface); COPY(fTextSize);
SkSafeRef(fPathEffect); COPY(fTextScaleX);
SkSafeRef(fShader); COPY(fTextSkewX);
SkSafeRef(fXfermode); COPY(fColor);
SkSafeRef(fMaskFilter); COPY(fWidth);
SkSafeRef(fColorFilter); COPY(fMiterLimit);
SkSafeRef(fRasterizer); COPY(fBitfields);
SkSafeRef(fLooper); COPY(fDirtyBits);
SkSafeRef(fImageFilter);
SkSafeRef(fAnnotation);
#ifdef SK_BUILD_FOR_ANDROID #ifdef SK_BUILD_FOR_ANDROID
new (&fPaintOptionsAndroid) SkPaintOptionsAndroid(src.fPaintOptionsAndroid); new (&fPaintOptionsAndroid) SkPaintOptionsAndroid(src.fPaintOptionsAndroid);
COPY(fGenerationID);
#endif #endif
#undef COPY
#undef REF_COPY
} }
SkPaint::~SkPaint() { SkPaint::~SkPaint() {

Просмотреть файл

@ -59,7 +59,11 @@ static int find_first_zero(const uint16_t glyphs[], int count) {
return count; return count;
} }
static void test_cmap(skiatest::Reporter* reporter) { DEF_TEST(Paint_cmap, reporter) {
// need to implement charsToGlyphs on other backends (e.g. linux, win)
// before we can run this tests everywhere
return;
static const int NGLYPHS = 64; static const int NGLYPHS = 64;
SkUnichar src[NGLYPHS]; SkUnichar src[NGLYPHS];
@ -113,7 +117,7 @@ static void test_cmap(skiatest::Reporter* reporter) {
} }
// temparary api for bicubic, just be sure we can set/clear it // temparary api for bicubic, just be sure we can set/clear it
static void test_filterlevel(skiatest::Reporter* reporter) { DEF_TEST(Paint_filterlevel, reporter) {
SkPaint p0, p1; SkPaint p0, p1;
REPORTER_ASSERT(reporter, REPORTER_ASSERT(reporter,
@ -137,7 +141,7 @@ static void test_filterlevel(skiatest::Reporter* reporter) {
} }
} }
static void test_copy(skiatest::Reporter* reporter) { DEF_TEST(Paint_copy, reporter) {
SkPaint paint; SkPaint paint;
// set a few member variables // set a few member variables
paint.setStyle(SkPaint::kStrokeAndFill_Style); paint.setStyle(SkPaint::kStrokeAndFill_Style);
@ -192,7 +196,7 @@ static void test_copy(skiatest::Reporter* reporter) {
// found and fixed for webkit: mishandling when we hit recursion limit on // found and fixed for webkit: mishandling when we hit recursion limit on
// mostly degenerate cubic flatness test // mostly degenerate cubic flatness test
static void regression_cubic(skiatest::Reporter* reporter) { DEF_TEST(Paint_regression_cubic, reporter) {
SkPath path, stroke; SkPath path, stroke;
SkPaint paint; SkPaint paint;
@ -225,7 +229,7 @@ static void regression_cubic(skiatest::Reporter* reporter) {
} }
// found and fixed for android: not initializing rect for string's of length 0 // found and fixed for android: not initializing rect for string's of length 0
static void regression_measureText(skiatest::Reporter* reporter) { DEF_TEST(Paint_regression_measureText, reporter) {
SkPaint paint; SkPaint paint;
paint.setTextSize(12.0f); paint.setTextSize(12.0f);
@ -238,23 +242,6 @@ static void regression_measureText(skiatest::Reporter* reporter) {
REPORTER_ASSERT(reporter, r.isEmpty()); REPORTER_ASSERT(reporter, r.isEmpty());
} }
DEF_TEST(Paint, reporter) {
// TODO add general paint tests
test_copy(reporter);
// regression tests
regression_cubic(reporter);
regression_measureText(reporter);
test_filterlevel(reporter);
// need to implement charsToGlyphs on other backends (e.g. linux, win)
// before we can run this tests everywhere
if (false) {
test_cmap(reporter);
}
}
#define ASSERT(expr) REPORTER_ASSERT(r, expr) #define ASSERT(expr) REPORTER_ASSERT(r, expr)
DEF_TEST(Paint_FlatteningTraits, r) { DEF_TEST(Paint_FlatteningTraits, r) {