Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: src/core/SkPaint.cpp

Issue 1920423002: Prototype code that turns any/every flattenable into JSON (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix copyright dates in new files Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkFlattenableSerialization.cpp ('k') | src/core/SkPictureData.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkPaint.h" 8 #include "SkPaint.h"
9 #include "SkAutoKern.h" 9 #include "SkAutoKern.h"
10 #include "SkChecksum.h" 10 #include "SkChecksum.h"
(...skipping 1180 matching lines...) Expand 10 before | Expand all | Expand 10 after
1191 if (nullptr == typeface) { 1191 if (nullptr == typeface) {
1192 typeface = SkTypeface::GetDefaultTypeface(); 1192 typeface = SkTypeface::GetDefaultTypeface();
1193 } 1193 }
1194 1194
1195 SkRect bounds; 1195 SkRect bounds;
1196 m.mapRect(&bounds, typeface->getBounds()); 1196 m.mapRect(&bounds, typeface->getBounds());
1197 return bounds; 1197 return bounds;
1198 } 1198 }
1199 1199
1200 static void add_flattenable(SkDescriptor* desc, uint32_t tag, 1200 static void add_flattenable(SkDescriptor* desc, uint32_t tag,
1201 SkWriteBuffer* buffer) { 1201 SkBinaryWriteBuffer* buffer) {
1202 buffer->writeToMemory(desc->addEntry(tag, buffer->bytesWritten(), nullptr)); 1202 buffer->writeToMemory(desc->addEntry(tag, buffer->bytesWritten(), nullptr));
1203 } 1203 }
1204 1204
1205 static SkMask::Format compute_mask_format(const SkPaint& paint) { 1205 static SkMask::Format compute_mask_format(const SkPaint& paint) {
1206 uint32_t flags = paint.getFlags(); 1206 uint32_t flags = paint.getFlags();
1207 1207
1208 // Antialiasing being disabled trumps all other settings. 1208 // Antialiasing being disabled trumps all other settings.
1209 if (!(flags & SkPaint::kAntiAlias_Flag)) { 1209 if (!(flags & SkPaint::kAntiAlias_Flag)) {
1210 return SkMask::kBW_Format; 1210 return SkMask::kBW_Format;
1211 } 1211 }
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
1521 } 1521 }
1522 } 1522 }
1523 1523
1524 #define MIN_SIZE_FOR_EFFECT_BUFFER 1024 1524 #define MIN_SIZE_FOR_EFFECT_BUFFER 1024
1525 1525
1526 #ifdef SK_DEBUG 1526 #ifdef SK_DEBUG
1527 #define TEST_DESC 1527 #define TEST_DESC
1528 #endif 1528 #endif
1529 1529
1530 static void write_out_descriptor(SkDescriptor* desc, const SkScalerContext::Rec& rec, 1530 static void write_out_descriptor(SkDescriptor* desc, const SkScalerContext::Rec& rec,
1531 const SkPathEffect* pe, SkWriteBuffer* peBuffer , 1531 const SkPathEffect* pe, SkBinaryWriteBuffer* pe Buffer,
1532 const SkMaskFilter* mf, SkWriteBuffer* mfBuffer , 1532 const SkMaskFilter* mf, SkBinaryWriteBuffer* mf Buffer,
1533 const SkRasterizer* ra, SkWriteBuffer* raBuffer , 1533 const SkRasterizer* ra, SkBinaryWriteBuffer* ra Buffer,
1534 size_t descSize) { 1534 size_t descSize) {
1535 desc->init(); 1535 desc->init();
1536 desc->addEntry(kRec_SkDescriptorTag, sizeof(rec), &rec); 1536 desc->addEntry(kRec_SkDescriptorTag, sizeof(rec), &rec);
1537 1537
1538 if (pe) { 1538 if (pe) {
1539 add_flattenable(desc, kPathEffect_SkDescriptorTag, peBuffer); 1539 add_flattenable(desc, kPathEffect_SkDescriptorTag, peBuffer);
1540 } 1540 }
1541 if (mf) { 1541 if (mf) {
1542 add_flattenable(desc, kMaskFilter_SkDescriptorTag, mfBuffer); 1542 add_flattenable(desc, kMaskFilter_SkDescriptorTag, mfBuffer);
1543 } 1543 }
1544 if (ra) { 1544 if (ra) {
1545 add_flattenable(desc, kRasterizer_SkDescriptorTag, raBuffer); 1545 add_flattenable(desc, kRasterizer_SkDescriptorTag, raBuffer);
1546 } 1546 }
1547 1547
1548 desc->computeChecksum(); 1548 desc->computeChecksum();
1549 } 1549 }
1550 1550
1551 static size_t fill_out_rec(const SkPaint& paint, SkScalerContext::Rec* rec, 1551 static size_t fill_out_rec(const SkPaint& paint, SkScalerContext::Rec* rec,
1552 const SkSurfaceProps* surfaceProps, 1552 const SkSurfaceProps* surfaceProps,
1553 bool fakeGamma, bool boostContrast, 1553 bool fakeGamma, bool boostContrast,
1554 const SkMatrix* deviceMatrix, 1554 const SkMatrix* deviceMatrix,
1555 const SkPathEffect* pe, SkWriteBuffer* peBuffer, 1555 const SkPathEffect* pe, SkBinaryWriteBuffer* peBuffer ,
1556 const SkMaskFilter* mf, SkWriteBuffer* mfBuffer, 1556 const SkMaskFilter* mf, SkBinaryWriteBuffer* mfBuffer ,
1557 const SkRasterizer* ra, SkWriteBuffer* raBuffer) { 1557 const SkRasterizer* ra, SkBinaryWriteBuffer* raBuffer ) {
1558 SkScalerContext::MakeRec(paint, surfaceProps, deviceMatrix, rec); 1558 SkScalerContext::MakeRec(paint, surfaceProps, deviceMatrix, rec);
1559 if (!fakeGamma) { 1559 if (!fakeGamma) {
1560 rec->ignoreGamma(); 1560 rec->ignoreGamma();
1561 } 1561 }
1562 if (!boostContrast) { 1562 if (!boostContrast) {
1563 rec->setContrast(0); 1563 rec->setContrast(0);
1564 } 1564 }
1565 1565
1566 int entryCount = 1; 1566 int entryCount = 1;
1567 size_t descSize = sizeof(*rec); 1567 size_t descSize = sizeof(*rec);
(...skipping 26 matching lines...) Expand all
1594 /////////////////////////////////////////////////////////////////////////// 1594 ///////////////////////////////////////////////////////////////////////////
1595 // Now that we're done tweaking the rec, call the PostMakeRec cleanup 1595 // Now that we're done tweaking the rec, call the PostMakeRec cleanup
1596 SkScalerContext::PostMakeRec(paint, rec); 1596 SkScalerContext::PostMakeRec(paint, rec);
1597 1597
1598 descSize += SkDescriptor::ComputeOverhead(entryCount); 1598 descSize += SkDescriptor::ComputeOverhead(entryCount);
1599 return descSize; 1599 return descSize;
1600 } 1600 }
1601 1601
1602 #ifdef TEST_DESC 1602 #ifdef TEST_DESC
1603 static void test_desc(const SkScalerContext::Rec& rec, 1603 static void test_desc(const SkScalerContext::Rec& rec,
1604 const SkPathEffect* pe, SkWriteBuffer* peBuffer, 1604 const SkPathEffect* pe, SkBinaryWriteBuffer* peBuffer,
1605 const SkMaskFilter* mf, SkWriteBuffer* mfBuffer, 1605 const SkMaskFilter* mf, SkBinaryWriteBuffer* mfBuffer,
1606 const SkRasterizer* ra, SkWriteBuffer* raBuffer, 1606 const SkRasterizer* ra, SkBinaryWriteBuffer* raBuffer,
1607 const SkDescriptor* desc, size_t descSize) { 1607 const SkDescriptor* desc, size_t descSize) {
1608 // Check that we completely write the bytes in desc (our key), and that 1608 // Check that we completely write the bytes in desc (our key), and that
1609 // there are no uninitialized bytes. If there were, then we would get 1609 // there are no uninitialized bytes. If there were, then we would get
1610 // false-misses (or worse, false-hits) in our fontcache. 1610 // false-misses (or worse, false-hits) in our fontcache.
1611 // 1611 //
1612 // We do this buy filling 2 others, one with 0s and the other with 1s 1612 // We do this buy filling 2 others, one with 0s and the other with 1s
1613 // and create those, and then check that all 3 are identical. 1613 // and create those, and then check that all 3 are identical.
1614 SkAutoDescriptor ad1(descSize); 1614 SkAutoDescriptor ad1(descSize);
1615 SkAutoDescriptor ad2(descSize); 1615 SkAutoDescriptor ad2(descSize);
1616 SkDescriptor* desc1 = ad1.getDesc(); 1616 SkDescriptor* desc1 = ad1.getDesc();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1651 SkAutoDescriptor* ad, 1651 SkAutoDescriptor* ad,
1652 const SkSurfaceProps& surfaceProps, 1652 const SkSurfaceProps& surfaceProps,
1653 uint32_t scalerContextFlags, 1653 uint32_t scalerContextFlags,
1654 const SkMatrix* deviceMatrix) const { 1654 const SkMatrix* deviceMatrix) const {
1655 SkScalerContext::Rec rec; 1655 SkScalerContext::Rec rec;
1656 1656
1657 SkPathEffect* pe = this->getPathEffect(); 1657 SkPathEffect* pe = this->getPathEffect();
1658 SkMaskFilter* mf = this->getMaskFilter(); 1658 SkMaskFilter* mf = this->getMaskFilter();
1659 SkRasterizer* ra = this->getRasterizer(); 1659 SkRasterizer* ra = this->getRasterizer();
1660 1660
1661 SkWriteBuffer peBuffer, mfBuffer, raBuffer; 1661 SkBinaryWriteBuffer peBuffer, mfBuffer, raBuffer;
1662 size_t descSize = fill_out_rec(*this, &rec, &surfaceProps, 1662 size_t descSize = fill_out_rec(*this, &rec, &surfaceProps,
1663 SkToBool(scalerContextFlags & kFakeGamma_Scal erContextFlag), 1663 SkToBool(scalerContextFlags & kFakeGamma_Scal erContextFlag),
1664 SkToBool(scalerContextFlags & kBoostContrast_ ScalerContextFlag), 1664 SkToBool(scalerContextFlags & kBoostContrast_ ScalerContextFlag),
1665 deviceMatrix, pe, &peBuffer, mf, &mfBuffer, r a, &raBuffer); 1665 deviceMatrix, pe, &peBuffer, mf, &mfBuffer, r a, &raBuffer);
1666 1666
1667 ad->reset(descSize); 1667 ad->reset(descSize);
1668 SkDescriptor* desc = ad->getDesc(); 1668 SkDescriptor* desc = ad->getDesc();
1669 1669
1670 write_out_descriptor(desc, rec, pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer, descSize); 1670 write_out_descriptor(desc, rec, pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer, descSize);
1671 1671
(...skipping 18 matching lines...) Expand all
1690 const SkMatrix* deviceMatrix, 1690 const SkMatrix* deviceMatrix,
1691 void (*proc)(SkTypeface*, const SkScalerContextEffe cts&, 1691 void (*proc)(SkTypeface*, const SkScalerContextEffe cts&,
1692 const SkDescriptor*, void*), 1692 const SkDescriptor*, void*),
1693 void* context) const { 1693 void* context) const {
1694 SkScalerContext::Rec rec; 1694 SkScalerContext::Rec rec;
1695 1695
1696 SkPathEffect* pe = this->getPathEffect(); 1696 SkPathEffect* pe = this->getPathEffect();
1697 SkMaskFilter* mf = this->getMaskFilter(); 1697 SkMaskFilter* mf = this->getMaskFilter();
1698 SkRasterizer* ra = this->getRasterizer(); 1698 SkRasterizer* ra = this->getRasterizer();
1699 1699
1700 SkWriteBuffer peBuffer, mfBuffer, raBuffer; 1700 SkBinaryWriteBuffer peBuffer, mfBuffer, raBuffer;
1701 size_t descSize = fill_out_rec(*this, &rec, surfaceProps, 1701 size_t descSize = fill_out_rec(*this, &rec, surfaceProps,
1702 SkToBool(scalerContextFlags & kFakeGamma_Scal erContextFlag), 1702 SkToBool(scalerContextFlags & kFakeGamma_Scal erContextFlag),
1703 SkToBool(scalerContextFlags & kBoostContrast_ ScalerContextFlag), 1703 SkToBool(scalerContextFlags & kBoostContrast_ ScalerContextFlag),
1704 deviceMatrix, pe, &peBuffer, mf, &mfBuffer, r a, &raBuffer); 1704 deviceMatrix, pe, &peBuffer, mf, &mfBuffer, r a, &raBuffer);
1705 1705
1706 SkAutoDescriptor ad(descSize); 1706 SkAutoDescriptor ad(descSize);
1707 SkDescriptor* desc = ad.getDesc(); 1707 SkDescriptor* desc = ad.getDesc();
1708 1708
1709 write_out_descriptor(desc, rec, pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer, descSize); 1709 write_out_descriptor(desc, rec, pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer, descSize);
1710 1710
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after
2320 } 2320 }
2321 2321
2322 uint32_t SkPaint::getHash() const { 2322 uint32_t SkPaint::getHash() const {
2323 // We're going to hash 10 pointers and 7 32-bit values, finishing up with fB itfields, 2323 // We're going to hash 10 pointers and 7 32-bit values, finishing up with fB itfields,
2324 // so fBitfields should be 10 pointers and 6 32-bit values from the start. 2324 // so fBitfields should be 10 pointers and 6 32-bit values from the start.
2325 static_assert(offsetof(SkPaint, fBitfields) == 9 * sizeof(void*) + 6 * sizeo f(uint32_t), 2325 static_assert(offsetof(SkPaint, fBitfields) == 9 * sizeof(void*) + 6 * sizeo f(uint32_t),
2326 "SkPaint_notPackedTightly"); 2326 "SkPaint_notPackedTightly");
2327 return SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(this), 2327 return SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(this),
2328 offsetof(SkPaint, fBitfields) + sizeof(fBitfields )); 2328 offsetof(SkPaint, fBitfields) + sizeof(fBitfields ));
2329 } 2329 }
OLDNEW
« no previous file with comments | « src/core/SkFlattenableSerialization.cpp ('k') | src/core/SkPictureData.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698