2013-09-26 15:16:12 +00:00
|
|
|
// SkPaints only have an SkPaintOptionsAndroid if SK_BUILD_FOR_ANDROID is true.
|
|
|
|
#ifdef SK_BUILD_FOR_ANDROID
|
|
|
|
|
2014-01-30 18:58:24 +00:00
|
|
|
#include "SkReadBuffer.h"
|
|
|
|
#include "SkWriteBuffer.h"
|
2013-09-26 15:16:12 +00:00
|
|
|
#include "SkPaint.h"
|
2014-01-24 20:56:26 +00:00
|
|
|
#include "SkPaintOptionsAndroid.h"
|
2013-09-26 15:16:12 +00:00
|
|
|
#include "Test.h"
|
|
|
|
|
|
|
|
static size_t Reconstruct(const SkPaint& src, SkPaint* dst) {
|
2014-01-30 18:58:24 +00:00
|
|
|
SkWriteBuffer writer;
|
2013-09-26 15:16:12 +00:00
|
|
|
src.flatten(writer);
|
|
|
|
|
|
|
|
const size_t size = writer.bytesWritten();
|
|
|
|
SkAutoMalloc bytes(size);
|
|
|
|
writer.writeToMemory(bytes.get());
|
|
|
|
|
2014-01-30 18:58:24 +00:00
|
|
|
SkReadBuffer reader(bytes.get(), size);
|
2013-09-26 15:16:12 +00:00
|
|
|
dst->unflatten(reader);
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2014-01-02 21:45:03 +00:00
|
|
|
DEF_TEST(AndroidOptionsSerialization, reporter) {
|
2013-09-26 15:16:12 +00:00
|
|
|
// We want to make sure that Android's paint options survive a flatten/unflatten round trip.
|
|
|
|
// These are all non-default options.
|
|
|
|
SkPaintOptionsAndroid options;
|
|
|
|
options.setLanguage("ja-JP");
|
|
|
|
options.setFontVariant(SkPaintOptionsAndroid::kElegant_Variant);
|
|
|
|
options.setUseFontFallbacks(true);
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setPaintOptionsAndroid(options);
|
|
|
|
|
|
|
|
SkPaint reconstructed;
|
|
|
|
Reconstruct(paint, &reconstructed);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, options == reconstructed.getPaintOptionsAndroid());
|
|
|
|
}
|
|
|
|
|
2014-01-02 21:45:03 +00:00
|
|
|
DEF_TEST(AndroidOptionsSerializationReverse, reporter) {
|
2013-09-26 15:16:12 +00:00
|
|
|
// Opposite test of above: make sure the serialized default values of a paint overwrite
|
|
|
|
// non-default values on the paint we're unflattening into.
|
|
|
|
const SkPaint defaultOptions;
|
|
|
|
|
|
|
|
SkPaintOptionsAndroid options;
|
|
|
|
options.setLanguage("ja-JP");
|
|
|
|
options.setFontVariant(SkPaintOptionsAndroid::kElegant_Variant);
|
|
|
|
options.setUseFontFallbacks(true);
|
|
|
|
SkPaint nonDefaultOptions;
|
|
|
|
nonDefaultOptions.setPaintOptionsAndroid(options);
|
|
|
|
|
|
|
|
Reconstruct(defaultOptions, &nonDefaultOptions);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
defaultOptions.getPaintOptionsAndroid() ==
|
|
|
|
nonDefaultOptions.getPaintOptionsAndroid());
|
|
|
|
}
|
|
|
|
|
2014-01-02 21:45:03 +00:00
|
|
|
DEF_TEST(AndroidOptionsSize, reporter) {
|
2013-09-26 15:16:12 +00:00
|
|
|
// A paint with default android options should serialize to something smaller than
|
|
|
|
// a paint with non-default android options.
|
|
|
|
|
|
|
|
SkPaint defaultOptions;
|
|
|
|
|
|
|
|
SkPaintOptionsAndroid options;
|
|
|
|
options.setUseFontFallbacks(true);
|
|
|
|
SkPaint nonDefaultOptions;
|
|
|
|
nonDefaultOptions.setPaintOptionsAndroid(options);
|
|
|
|
|
|
|
|
SkPaint dummy;
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
Reconstruct(defaultOptions, &dummy) < Reconstruct(nonDefaultOptions, &dummy));
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // SK_BUILD_FOR_ANDROID
|