OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
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 "SkDevice.h" | 8 #include "SkDevice.h" |
9 #include "SkDraw.h" | |
9 #include "SkMetaData.h" | 10 #include "SkMetaData.h" |
10 | 11 |
11 SkBaseDevice::SkBaseDevice() | 12 SkBaseDevice::SkBaseDevice() |
12 : fLeakyProperties(SkDeviceProperties::MakeDefault()) | 13 : fLeakyProperties(SkDeviceProperties::MakeDefault()) |
13 #ifdef SK_DEBUG | 14 #ifdef SK_DEBUG |
14 , fAttachedToCanvas(false) | 15 , fAttachedToCanvas(false) |
15 #endif | 16 #endif |
16 { | 17 { |
17 fOrigin.setZero(); | 18 fOrigin.setZero(); |
18 fMetaData = NULL; | 19 fMetaData = NULL; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
70 SkPath path; | 71 SkPath path; |
71 path.addRRect(outer); | 72 path.addRRect(outer); |
72 path.addRRect(inner); | 73 path.addRRect(inner); |
73 path.setFillType(SkPath::kEvenOdd_FillType); | 74 path.setFillType(SkPath::kEvenOdd_FillType); |
74 | 75 |
75 const SkMatrix* preMatrix = NULL; | 76 const SkMatrix* preMatrix = NULL; |
76 const bool pathIsMutable = true; | 77 const bool pathIsMutable = true; |
77 this->drawPath(draw, path, paint, preMatrix, pathIsMutable); | 78 this->drawPath(draw, path, paint, preMatrix, pathIsMutable); |
78 } | 79 } |
79 | 80 |
81 void SkBaseDevice::drawPatch(const SkDraw& draw, const SkPatch& patch, const SkP aint& paint) { | |
82 SkPatch::VertexData data; | |
83 | |
84 SkPoint mapPts[12]; | |
85 draw.fMatrix->mapPoints(mapPts, patch.getControlPoints(), 12); | |
86 | |
87 // Approximate length of each cubic. | |
88 int topLength = SkSqrt32(mapPts[SkPatch::kTopP0_CubicCtrlPts] | |
egdaniel
2014/08/01 13:28:52
This may be a good place for a function that calcs
dandov
2014/08/01 15:11:14
Created a function in SkGeometry that calculates a
| |
89 .distanceToSqd(mapPts[SkPatch::kTopP1_CubicCtrlPts] )) + | |
bsalomon
2014/08/01 13:30:27
I'd just give up on trying to reduce sqrts and cal
| |
90 SkSqrt32(mapPts[SkPatch::kTopP1_CubicCtrlPts] | |
91 .distanceToSqd(mapPts[SkPatch::kTopP2_CubicCtrlPts] )) + | |
92 SkSqrt32(mapPts[SkPatch::kTopP2_CubicCtrlPts] | |
93 .distanceToSqd(mapPts[SkPatch::kTopP3_CubicCtrlPts] )); | |
94 int bottomLength = SkSqrt32(mapPts[SkPatch::kBottomP0_CubicCtrlPts] | |
95 .distanceToSqd(mapPts[SkPatch::kBottomP1_CubicCtrlP ts])) + | |
96 SkSqrt32(mapPts[SkPatch::kBottomP1_CubicCtrlPts] | |
97 .distanceToSqd(mapPts[SkPatch::kBottomP2_CubicC trlPts])) + | |
98 SkSqrt32(mapPts[SkPatch::kBottomP2_CubicCtrlPts] | |
99 .distanceToSqd(mapPts[SkPatch::kBottomP3_CubicC trlPts])); | |
100 int leftLength = SkSqrt32(mapPts[SkPatch::kLeftP0_CubicCtrlPts] | |
101 .distanceToSqd(mapPts[SkPatch::kLeftP1_CubicCtrlPts ])) + | |
102 SkSqrt32(mapPts[SkPatch::kLeftP1_CubicCtrlPts] | |
103 .distanceToSqd(mapPts[SkPatch::kLeftP2_CubicCtr lPts])) + | |
104 SkSqrt32(mapPts[SkPatch::kLeftP2_CubicCtrlPts] | |
105 .distanceToSqd(mapPts[SkPatch::kLeftP3_CubicCtr lPts])); | |
106 int rightLength = SkSqrt32(mapPts[SkPatch::kRightP0_CubicCtrlPts] | |
107 .distanceToSqd(mapPts[SkPatch::kRightP1_CubicCtrlPt s])) + | |
108 SkSqrt32(mapPts[SkPatch::kRightP1_CubicCtrlPts] | |
109 .distanceToSqd(mapPts[SkPatch::kRightP2_CubicCt rlPts])) + | |
110 SkSqrt32(mapPts[SkPatch::kRightP2_CubicCtrlPts] | |
111 .distanceToSqd(mapPts[SkPatch::kRightP3_CubicCt rlPts])); | |
112 | |
113 // Level of detail per axis, based on the larger side between top and bottom or left and right | |
114 int lodX = SkMaxScalar(topLength, bottomLength) / SkPatch::kPartitionSize; | |
115 int lodY = SkMaxScalar(leftLength, rightLength) / SkPatch::kPartitionSize; | |
116 | |
117 // It automatically adjusts lodX and lodY in case it exceeds the number of i ndices. | |
118 patch.getVertexData(&data, SkMax32(2, lodX), SkMax32(2, lodY)); | |
119 this->drawVertices(draw, SkCanvas::kTriangles_VertexMode, data.fVertexCount, data.fPoints, | |
120 data.fTexCoords, data.fColors, NULL, data.fIndices, data. fIndexCount, paint); | |
121 } | |
122 | |
80 bool SkBaseDevice::readPixels(const SkImageInfo& info, void* dstP, size_t rowByt es, int x, int y) { | 123 bool SkBaseDevice::readPixels(const SkImageInfo& info, void* dstP, size_t rowByt es, int x, int y) { |
81 #ifdef SK_DEBUG | 124 #ifdef SK_DEBUG |
82 SkASSERT(info.width() > 0 && info.height() > 0); | 125 SkASSERT(info.width() > 0 && info.height() > 0); |
83 SkASSERT(dstP); | 126 SkASSERT(dstP); |
84 SkASSERT(rowBytes >= info.minRowBytes()); | 127 SkASSERT(rowBytes >= info.minRowBytes()); |
85 SkASSERT(x >= 0 && y >= 0); | 128 SkASSERT(x >= 0 && y >= 0); |
86 | 129 |
87 const SkImageInfo& srcInfo = this->imageInfo(); | 130 const SkImageInfo& srcInfo = this->imageInfo(); |
88 SkASSERT(x + info.width() <= srcInfo.width()); | 131 SkASSERT(x + info.width() <= srcInfo.width()); |
89 SkASSERT(y + info.height() <= srcInfo.height()); | 132 SkASSERT(y + info.height() <= srcInfo.height()); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 } | 174 } |
132 | 175 |
133 void SkBaseDevice::EXPERIMENTAL_optimize(const SkPicture* picture) { | 176 void SkBaseDevice::EXPERIMENTAL_optimize(const SkPicture* picture) { |
134 // The base class doesn't perform any analysis but derived classes may | 177 // The base class doesn't perform any analysis but derived classes may |
135 } | 178 } |
136 | 179 |
137 bool SkBaseDevice::EXPERIMENTAL_drawPicture(SkCanvas* canvas, const SkPicture* p icture) { | 180 bool SkBaseDevice::EXPERIMENTAL_drawPicture(SkCanvas* canvas, const SkPicture* p icture) { |
138 // The base class doesn't perform any accelerated picture rendering | 181 // The base class doesn't perform any accelerated picture rendering |
139 return false; | 182 return false; |
140 } | 183 } |
OLD | NEW |