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

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

Issue 27370003: Clean up 4 old bytes per paint. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: reupload Created 7 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "SkPaint.h" 9 #include "SkPaint.h"
10 #include "SkAnnotation.h" 10 #include "SkAnnotation.h"
(...skipping 1992 matching lines...) Expand 10 before | Expand all | Expand 10 after
2003 return (a << 24) | (b << 16) | (c << 8) | d; 2003 return (a << 24) | (b << 16) | (c << 8) | d;
2004 } 2004 }
2005 2005
2006 enum FlatFlags { 2006 enum FlatFlags {
2007 kHasTypeface_FlatFlag = 0x01, 2007 kHasTypeface_FlatFlag = 0x01,
2008 kHasEffects_FlatFlag = 0x02, 2008 kHasEffects_FlatFlag = 0x02,
2009 kHasNonDefaultPaintOptionsAndroid_FlatFlag = 0x04, 2009 kHasNonDefaultPaintOptionsAndroid_FlatFlag = 0x04,
2010 }; 2010 };
2011 2011
2012 // The size of a flat paint's POD fields 2012 // The size of a flat paint's POD fields
2013 // Include an SkScalar for hinting scale factor whether it is 2013 static const uint32_t kPODPaintSize = 5 * sizeof(SkScalar) +
2014 // supported or not so that an SKP is valid whether it was
2015 // created with support or not.
2016
2017 static const uint32_t kPODPaintSize = 6 * sizeof(SkScalar) +
2018 1 * sizeof(SkColor) + 2014 1 * sizeof(SkColor) +
2019 1 * sizeof(uint16_t) + 2015 1 * sizeof(uint16_t) +
2020 6 * sizeof(uint8_t); 2016 6 * sizeof(uint8_t);
2021 2017
2022 /* To save space/time, we analyze the paint, and write a truncated version of 2018 /* To save space/time, we analyze the paint, and write a truncated version of
2023 it if there are not tricky elements like shaders, etc. 2019 it if there are not tricky elements like shaders, etc.
2024 */ 2020 */
2025 void SkPaint::flatten(SkFlattenableWriteBuffer& buffer) const { 2021 void SkPaint::flatten(SkFlattenableWriteBuffer& buffer) const {
2026 uint8_t flatFlags = 0; 2022 uint8_t flatFlags = 0;
2027 if (this->getTypeface()) { 2023 if (this->getTypeface()) {
(...skipping 16 matching lines...) Expand all
2044 } 2040 }
2045 #endif 2041 #endif
2046 2042
2047 if (buffer.isOrderedBinaryBuffer()) { 2043 if (buffer.isOrderedBinaryBuffer()) {
2048 SkASSERT(SkAlign4(kPODPaintSize) == kPODPaintSize); 2044 SkASSERT(SkAlign4(kPODPaintSize) == kPODPaintSize);
2049 uint32_t* ptr = buffer.getOrderedBinaryBuffer()->reserve(kPODPaintSize); 2045 uint32_t* ptr = buffer.getOrderedBinaryBuffer()->reserve(kPODPaintSize);
2050 2046
2051 ptr = write_scalar(ptr, this->getTextSize()); 2047 ptr = write_scalar(ptr, this->getTextSize());
2052 ptr = write_scalar(ptr, this->getTextScaleX()); 2048 ptr = write_scalar(ptr, this->getTextScaleX());
2053 ptr = write_scalar(ptr, this->getTextSkewX()); 2049 ptr = write_scalar(ptr, this->getTextSkewX());
2054 // Dummy value for obsolete hinting scale factor. TODO: remove with nex t picture version
2055 ptr = write_scalar(ptr, SK_Scalar1);
2056 ptr = write_scalar(ptr, this->getStrokeWidth()); 2050 ptr = write_scalar(ptr, this->getStrokeWidth());
2057 ptr = write_scalar(ptr, this->getStrokeMiter()); 2051 ptr = write_scalar(ptr, this->getStrokeMiter());
2058 *ptr++ = this->getColor(); 2052 *ptr++ = this->getColor();
2059 // previously flags:16, textAlign:8, flatFlags:8 2053 // previously flags:16, textAlign:8, flatFlags:8
2060 // now flags:16, hinting:4, textAlign:4, flatFlags:8 2054 // now flags:16, hinting:4, textAlign:4, flatFlags:8
2061 *ptr++ = (this->getFlags() << 16) | 2055 *ptr++ = (this->getFlags() << 16) |
2062 // hinting added later. 0 in this nibble means use the default. 2056 // hinting added later. 0 in this nibble means use the default.
2063 ((this->getHinting()+1) << 12) | 2057 ((this->getHinting()+1) << 12) |
2064 (this->getTextAlign() << 8) | 2058 (this->getTextAlign() << 8) |
2065 flatFlags; 2059 flatFlags;
2066 *ptr++ = pack_4(this->getStrokeCap(), this->getStrokeJoin(), 2060 *ptr++ = pack_4(this->getStrokeCap(), this->getStrokeJoin(),
2067 this->getStyle(), this->getTextEncoding()); 2061 this->getStyle(), this->getTextEncoding());
2068 } else { 2062 } else {
2069 buffer.writeScalar(fTextSize); 2063 buffer.writeScalar(fTextSize);
2070 buffer.writeScalar(fTextScaleX); 2064 buffer.writeScalar(fTextScaleX);
2071 buffer.writeScalar(fTextSkewX); 2065 buffer.writeScalar(fTextSkewX);
2072 // Dummy value for obsolete hinting scale factor. TODO: remove with nex t picture version
2073 buffer.writeScalar(SK_Scalar1);
2074 buffer.writeScalar(fWidth); 2066 buffer.writeScalar(fWidth);
2075 buffer.writeScalar(fMiterLimit); 2067 buffer.writeScalar(fMiterLimit);
2076 buffer.writeColor(fColor); 2068 buffer.writeColor(fColor);
2077 buffer.writeUInt(fFlags); 2069 buffer.writeUInt(fFlags);
2078 buffer.writeUInt(fHinting); 2070 buffer.writeUInt(fHinting);
2079 buffer.writeUInt(fTextAlign); 2071 buffer.writeUInt(fTextAlign);
2080 buffer.writeUInt(flatFlags); 2072 buffer.writeUInt(flatFlags);
2081 2073
2082 buffer.writeUInt(fCapType); 2074 buffer.writeUInt(fCapType);
2083 buffer.writeUInt(fJoinType); 2075 buffer.writeUInt(fJoinType);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
2120 uint8_t flatFlags = 0; 2112 uint8_t flatFlags = 0;
2121 if (buffer.isOrderedBinaryBuffer()) { 2113 if (buffer.isOrderedBinaryBuffer()) {
2122 SkASSERT(SkAlign4(kPODPaintSize) == kPODPaintSize); 2114 SkASSERT(SkAlign4(kPODPaintSize) == kPODPaintSize);
2123 const void* podData = buffer.getOrderedBinaryBuffer()->skip(kPODPaintSiz e); 2115 const void* podData = buffer.getOrderedBinaryBuffer()->skip(kPODPaintSiz e);
2124 const uint32_t* pod = reinterpret_cast<const uint32_t*>(podData); 2116 const uint32_t* pod = reinterpret_cast<const uint32_t*>(podData);
2125 2117
2126 // the order we read must match the order we wrote in flatten() 2118 // the order we read must match the order we wrote in flatten()
2127 this->setTextSize(read_scalar(pod)); 2119 this->setTextSize(read_scalar(pod));
2128 this->setTextScaleX(read_scalar(pod)); 2120 this->setTextScaleX(read_scalar(pod));
2129 this->setTextSkewX(read_scalar(pod)); 2121 this->setTextSkewX(read_scalar(pod));
2130 // Skip the hinting scalar factor, which is not supported.
2131 read_scalar(pod);
2132 this->setStrokeWidth(read_scalar(pod)); 2122 this->setStrokeWidth(read_scalar(pod));
2133 this->setStrokeMiter(read_scalar(pod)); 2123 this->setStrokeMiter(read_scalar(pod));
2134 this->setColor(*pod++); 2124 this->setColor(*pod++);
2135 2125
2136 // previously flags:16, textAlign:8, flatFlags:8 2126 // previously flags:16, textAlign:8, flatFlags:8
2137 // now flags:16, hinting:4, textAlign:4, flatFlags:8 2127 // now flags:16, hinting:4, textAlign:4, flatFlags:8
2138 uint32_t tmp = *pod++; 2128 uint32_t tmp = *pod++;
2139 this->setFlags(tmp >> 16); 2129 this->setFlags(tmp >> 16);
2140 2130
2141 // hinting added later. 0 in this nibble means use the default. 2131 // hinting added later. 0 in this nibble means use the default.
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
2604 case SkXfermode::kPlus_Mode: 2594 case SkXfermode::kPlus_Mode:
2605 return 0 == this->getAlpha(); 2595 return 0 == this->getAlpha();
2606 case SkXfermode::kDst_Mode: 2596 case SkXfermode::kDst_Mode:
2607 return true; 2597 return true;
2608 default: 2598 default:
2609 break; 2599 break;
2610 } 2600 }
2611 } 2601 }
2612 return false; 2602 return false;
2613 } 2603 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698