OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) Research In Motion Limited 2010. All rights reserved. | 2 * Copyright (C) Research In Motion Limited 2010. All rights reserved. |
3 * | 3 * |
4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
8 * | 8 * |
9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "core/svg/SVGPathByteStreamBuilder.h" | 22 #include "core/svg/SVGPathByteStreamBuilder.h" |
23 | 23 |
24 #include "core/svg/SVGPathSeg.h" | 24 #include "core/svg/SVGPathSeg.h" |
25 #include "wtf/OwnPtr.h" | 25 #include "wtf/OwnPtr.h" |
26 | 26 |
27 namespace blink { | 27 namespace blink { |
28 | 28 |
29 // Helper class that coalesces writes to a SVGPathByteStream to a local buffer. | 29 // Helper class that coalesces writes to a SVGPathByteStream to a local buffer. |
30 class CoalescingBuffer { | 30 class CoalescingBuffer { |
31 public: | 31 public: |
32 CoalescingBuffer(SVGPathByteStream* byteStream) | 32 CoalescingBuffer(SVGPathByteStream& byteStream) |
33 : m_currentOffset(0) | 33 : m_currentOffset(0) |
34 , m_byteStream(byteStream) | 34 , m_byteStream(byteStream) |
35 { | 35 { |
36 ASSERT(byteStream); | |
37 } | 36 } |
38 ~CoalescingBuffer() | 37 ~CoalescingBuffer() |
39 { | 38 { |
40 for (size_t i = 0; i < m_currentOffset; ++i) | 39 for (size_t i = 0; i < m_currentOffset; ++i) |
41 m_byteStream->append(m_bytes[i]); | 40 m_byteStream.append(m_bytes[i]); |
42 } | 41 } |
43 | 42 |
44 template<typename DataType> | 43 template<typename DataType> |
45 void writeType(DataType value) | 44 void writeType(DataType value) |
46 { | 45 { |
47 ByteType<DataType> data; | 46 ByteType<DataType> data; |
48 data.value = value; | 47 data.value = value; |
49 size_t typeSize = sizeof(ByteType<DataType>); | 48 size_t typeSize = sizeof(ByteType<DataType>); |
50 ASSERT(m_currentOffset + typeSize <= sizeof(m_bytes)); | 49 ASSERT(m_currentOffset + typeSize <= sizeof(m_bytes)); |
51 memcpy(m_bytes + m_currentOffset, data.bytes, typeSize); | 50 memcpy(m_bytes + m_currentOffset, data.bytes, typeSize); |
52 m_currentOffset += typeSize; | 51 m_currentOffset += typeSize; |
53 } | 52 } |
54 | 53 |
55 void writeFlag(bool value) { writeType<bool>(value); } | 54 void writeFlag(bool value) { writeType<bool>(value); } |
56 void writeFloat(float value) { writeType<float>(value); } | 55 void writeFloat(float value) { writeType<float>(value); } |
57 void writeFloatPoint(const FloatPoint& point) | 56 void writeFloatPoint(const FloatPoint& point) |
58 { | 57 { |
59 writeType<float>(point.x()); | 58 writeType<float>(point.x()); |
60 writeType<float>(point.y()); | 59 writeType<float>(point.y()); |
61 } | 60 } |
62 void writeSegmentType(unsigned short value) { writeType<unsigned short>(valu
e); } | 61 void writeSegmentType(unsigned short value) { writeType<unsigned short>(valu
e); } |
63 | 62 |
64 private: | 63 private: |
65 // Adjust size to fit the largest command (in serialized/byte-stream format)
. | 64 // Adjust size to fit the largest command (in serialized/byte-stream format)
. |
66 // Currently a cubic segment. | 65 // Currently a cubic segment. |
67 size_t m_currentOffset; | 66 size_t m_currentOffset; |
68 unsigned char m_bytes[sizeof(unsigned short) + sizeof(FloatPoint) * 3]; | 67 unsigned char m_bytes[sizeof(unsigned short) + sizeof(FloatPoint) * 3]; |
69 SVGPathByteStream* m_byteStream; | 68 SVGPathByteStream& m_byteStream; |
70 }; | 69 }; |
71 | 70 |
72 SVGPathByteStreamBuilder::SVGPathByteStreamBuilder() | 71 SVGPathByteStreamBuilder::SVGPathByteStreamBuilder(SVGPathByteStream& byteStream
) |
73 : m_byteStream(0) | 72 : m_byteStream(byteStream) |
74 { | 73 { |
75 } | 74 } |
76 | 75 |
77 void SVGPathByteStreamBuilder::moveTo(const FloatPoint& targetPoint, bool, PathC
oordinateMode mode) | 76 void SVGPathByteStreamBuilder::moveTo(const FloatPoint& targetPoint, bool, PathC
oordinateMode mode) |
78 { | 77 { |
79 CoalescingBuffer buffer(m_byteStream); | 78 CoalescingBuffer buffer(m_byteStream); |
80 buffer.writeSegmentType(mode == RelativeCoordinates ? PathSegMoveToRel : Pa
thSegMoveToAbs); | 79 buffer.writeSegmentType(mode == RelativeCoordinates ? PathSegMoveToRel : Pa
thSegMoveToAbs); |
81 buffer.writeFloatPoint(targetPoint); | 80 buffer.writeFloatPoint(targetPoint); |
82 } | 81 } |
83 | 82 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 buffer.writeFloatPoint(targetPoint); | 145 buffer.writeFloatPoint(targetPoint); |
147 } | 146 } |
148 | 147 |
149 void SVGPathByteStreamBuilder::closePath() | 148 void SVGPathByteStreamBuilder::closePath() |
150 { | 149 { |
151 CoalescingBuffer buffer(m_byteStream); | 150 CoalescingBuffer buffer(m_byteStream); |
152 buffer.writeSegmentType(PathSegClosePath); | 151 buffer.writeSegmentType(PathSegClosePath); |
153 } | 152 } |
154 | 153 |
155 } // namespace blink | 154 } // namespace blink |
OLD | NEW |