| 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 "GrInOrderDrawBuffer.h" | 8 #include "GrInOrderDrawBuffer.h" |
| 9 | 9 |
| 10 #include "GrDefaultGeoProcFactory.h" | 10 #include "GrDefaultGeoProcFactory.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 | 62 |
| 63 The vertex attrib order is always pos, color, [local coords]. | 63 The vertex attrib order is always pos, color, [local coords]. |
| 64 */ | 64 */ |
| 65 static const GrGeometryProcessor* create_rect_gp(bool hasExplicitLocalCoords, | 65 static const GrGeometryProcessor* create_rect_gp(bool hasExplicitLocalCoords, |
| 66 GrColor color, | 66 GrColor color, |
| 67 const SkMatrix* localMatrix) { | 67 const SkMatrix* localMatrix) { |
| 68 uint32_t flags = GrDefaultGeoProcFactory::kPosition_GPType | | 68 uint32_t flags = GrDefaultGeoProcFactory::kPosition_GPType | |
| 69 GrDefaultGeoProcFactory::kColor_GPType; | 69 GrDefaultGeoProcFactory::kColor_GPType; |
| 70 flags |= hasExplicitLocalCoords ? GrDefaultGeoProcFactory::kLocalCoord_GPTyp
e : 0; | 70 flags |= hasExplicitLocalCoords ? GrDefaultGeoProcFactory::kLocalCoord_GPTyp
e : 0; |
| 71 if (localMatrix) { | 71 if (localMatrix) { |
| 72 return GrDefaultGeoProcFactory::Create(color, flags, GrColorIsOpaque(col
or), 0xff, | 72 return GrDefaultGeoProcFactory::Create(flags, color, SkMatrix::I(), *loc
alMatrix, |
| 73 *localMatrix); | 73 GrColorIsOpaque(color)); |
| 74 } else { | 74 } else { |
| 75 return GrDefaultGeoProcFactory::Create(color, flags, GrColorIsOpaque(col
or)); | 75 return GrDefaultGeoProcFactory::Create(flags, color, SkMatrix::I(), SkMa
trix::I(), |
| 76 GrColorIsOpaque(color)); |
| 76 } | 77 } |
| 77 } | 78 } |
| 78 | 79 |
| 79 static bool path_fill_type_is_winding(const GrStencilSettings& pathStencilSettin
gs) { | 80 static bool path_fill_type_is_winding(const GrStencilSettings& pathStencilSettin
gs) { |
| 80 static const GrStencilSettings::Face pathFace = GrStencilSettings::kFront_Fa
ce; | 81 static const GrStencilSettings::Face pathFace = GrStencilSettings::kFront_Fa
ce; |
| 81 bool isWinding = kInvert_StencilOp != pathStencilSettings.passOp(pathFace); | 82 bool isWinding = kInvert_StencilOp != pathStencilSettings.passOp(pathFace); |
| 82 if (isWinding) { | 83 if (isWinding) { |
| 83 // Double check that it is in fact winding. | 84 // Double check that it is in fact winding. |
| 84 SkASSERT(kIncClamp_StencilOp == pathStencilSettings.passOp(pathFace)); | 85 SkASSERT(kIncClamp_StencilOp == pathStencilSettings.passOp(pathFace)); |
| 85 SkASSERT(kIncClamp_StencilOp == pathStencilSettings.failOp(pathFace)); | 86 SkASSERT(kIncClamp_StencilOp == pathStencilSettings.failOp(pathFace)); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 108 }; | 109 }; |
| 109 | 110 |
| 110 static inline uint8_t add_trace_bit(uint8_t cmd) { return cmd | kTraceCmdBit; } | 111 static inline uint8_t add_trace_bit(uint8_t cmd) { return cmd | kTraceCmdBit; } |
| 111 | 112 |
| 112 static inline uint8_t strip_trace_bit(uint8_t cmd) { return cmd & kCmdMask; } | 113 static inline uint8_t strip_trace_bit(uint8_t cmd) { return cmd & kCmdMask; } |
| 113 | 114 |
| 114 static inline bool cmd_has_trace_marker(uint8_t cmd) { return SkToBool(cmd & kTr
aceCmdBit); } | 115 static inline bool cmd_has_trace_marker(uint8_t cmd) { return SkToBool(cmd & kTr
aceCmdBit); } |
| 115 | 116 |
| 116 void GrInOrderDrawBuffer::onDrawRect(GrDrawState* ds, | 117 void GrInOrderDrawBuffer::onDrawRect(GrDrawState* ds, |
| 117 GrColor color, | 118 GrColor color, |
| 119 const SkMatrix& viewMatrix, |
| 118 const SkRect& rect, | 120 const SkRect& rect, |
| 119 const SkRect* localRect, | 121 const SkRect* localRect, |
| 120 const SkMatrix* localMatrix) { | 122 const SkMatrix* localMatrix) { |
| 121 GrDrawState::AutoRestoreEffects are(ds); | 123 GrDrawState::AutoRestoreEffects are(ds); |
| 122 | 124 |
| 123 // Go to device coords to allow batching across matrix changes | 125 // Go to device coords to allow batching across matrix changes |
| 124 SkMatrix matrix = ds->getViewMatrix(); | |
| 125 SkMatrix invert = SkMatrix::I(); | 126 SkMatrix invert = SkMatrix::I(); |
| 126 | 127 |
| 127 // if we have a local rect, then we apply the localMatrix directly to the lo
calRect to generate | 128 // if we have a local rect, then we apply the localMatrix directly to the lo
calRect to generate |
| 128 // vertex local coords | 129 // vertex local coords |
| 129 bool hasExplicitLocalCoords = SkToBool(localRect); | 130 bool hasExplicitLocalCoords = SkToBool(localRect); |
| 130 if (!hasExplicitLocalCoords) { | 131 if (!hasExplicitLocalCoords) { |
| 131 if (!matrix.isIdentity() && !matrix.invert(&invert)) { | 132 if (!viewMatrix.isIdentity() && !viewMatrix.invert(&invert)) { |
| 132 SkDebugf("Could not invert\n"); | 133 SkDebugf("Could not invert\n"); |
| 133 return; | 134 return; |
| 134 } | 135 } |
| 135 | 136 |
| 136 if (localMatrix) { | 137 if (localMatrix) { |
| 137 invert.preConcat(*localMatrix); | 138 invert.preConcat(*localMatrix); |
| 138 } | 139 } |
| 139 } | 140 } |
| 140 | 141 |
| 141 SkAutoTUnref<const GrGeometryProcessor> gp(create_rect_gp(hasExplicitLocalCo
ords, | 142 SkAutoTUnref<const GrGeometryProcessor> gp(create_rect_gp(hasExplicitLocalCo
ords, |
| 142 color, | 143 color, |
| 143 &invert)); | 144 &invert)); |
| 144 | 145 |
| 145 size_t vstride = gp->getVertexStride(); | 146 size_t vstride = gp->getVertexStride(); |
| 146 SkASSERT(vstride == sizeof(SkPoint) + sizeof(GrColor) + (SkToBool(localRect)
? sizeof(SkPoint) : | 147 SkASSERT(vstride == sizeof(SkPoint) + sizeof(GrColor) + (SkToBool(localRect)
? sizeof(SkPoint) : |
| 147
0)); | 148
0)); |
| 148 AutoReleaseGeometry geo(this, 4, vstride, 0); | 149 AutoReleaseGeometry geo(this, 4, vstride, 0); |
| 149 if (!geo.succeeded()) { | 150 if (!geo.succeeded()) { |
| 150 SkDebugf("Failed to get space for vertices!\n"); | 151 SkDebugf("Failed to get space for vertices!\n"); |
| 151 return; | 152 return; |
| 152 } | 153 } |
| 153 | 154 |
| 155 geo.positions()->setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom
, vstride); |
| 156 viewMatrix.mapPointsWithStride(geo.positions(), vstride, 4); |
| 157 |
| 154 // When the caller has provided an explicit source rect for a stage then we
don't want to | 158 // When the caller has provided an explicit source rect for a stage then we
don't want to |
| 155 // modify that stage's matrix. Otherwise if the effect is generating its sou
rce rect from | 159 // modify that stage's matrix. Otherwise if the effect is generating its sou
rce rect from |
| 156 // the vertex positions then we have to account for the view matrix change. | 160 // the vertex positions then we have to account for the view matrix |
| 157 GrDrawState::AutoViewMatrixRestore avmr(ds); | 161 SkRect devBounds; |
| 158 | 162 |
| 159 geo.positions()->setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom
, vstride); | |
| 160 matrix.mapPointsWithStride(geo.positions(), vstride, 4); | |
| 161 | |
| 162 SkRect devBounds; | |
| 163 // since we already computed the dev verts, set the bounds hint. This will h
elp us avoid | 163 // since we already computed the dev verts, set the bounds hint. This will h
elp us avoid |
| 164 // unnecessary clipping in our onDraw(). | 164 // unnecessary clipping in our onDraw(). |
| 165 get_vertex_bounds(geo.vertices(), vstride, 4, &devBounds); | 165 get_vertex_bounds(geo.vertices(), vstride, 4, &devBounds); |
| 166 | 166 |
| 167 if (localRect) { | 167 if (localRect) { |
| 168 static const int kLocalOffset = sizeof(SkPoint) + sizeof(GrColor); | 168 static const int kLocalOffset = sizeof(SkPoint) + sizeof(GrColor); |
| 169 SkPoint* coords = GrTCast<SkPoint*>(GrTCast<intptr_t>(geo.vertices()) +
kLocalOffset); | 169 SkPoint* coords = GrTCast<SkPoint*>(GrTCast<intptr_t>(geo.vertices()) +
kLocalOffset); |
| 170 coords->setRectFan(localRect->fLeft, localRect->fTop, | 170 coords->setRectFan(localRect->fLeft, localRect->fTop, |
| 171 localRect->fRight, localRect->fBottom, | 171 localRect->fRight, localRect->fBottom, |
| 172 vstride); | 172 vstride); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 | 268 |
| 269 void GrInOrderDrawBuffer::onStencilPath(const GrDrawState& ds, | 269 void GrInOrderDrawBuffer::onStencilPath(const GrDrawState& ds, |
| 270 const GrPathProcessor* pathProc, | 270 const GrPathProcessor* pathProc, |
| 271 const GrPath* path, | 271 const GrPath* path, |
| 272 const GrScissorState& scissorState, | 272 const GrScissorState& scissorState, |
| 273 const GrStencilSettings& stencilSettings
) { | 273 const GrStencilSettings& stencilSettings
) { |
| 274 StencilPath* sp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, StencilPath, | 274 StencilPath* sp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, StencilPath, |
| 275 (path, ds.getRenderTarget())); | 275 (path, ds.getRenderTarget())); |
| 276 sp->fScissor = scissorState; | 276 sp->fScissor = scissorState; |
| 277 sp->fUseHWAA = ds.isHWAntialias(); | 277 sp->fUseHWAA = ds.isHWAntialias(); |
| 278 sp->fViewMatrix = ds.getViewMatrix(); | 278 sp->fViewMatrix = pathProc->viewMatrix(); |
| 279 sp->fStencil = stencilSettings; | 279 sp->fStencil = stencilSettings; |
| 280 this->recordTraceMarkersIfNecessary(); | 280 this->recordTraceMarkersIfNecessary(); |
| 281 } | 281 } |
| 282 | 282 |
| 283 void GrInOrderDrawBuffer::onDrawPath(const GrDrawState& ds, | 283 void GrInOrderDrawBuffer::onDrawPath(const GrDrawState& ds, |
| 284 const GrPathProcessor* pathProc, | 284 const GrPathProcessor* pathProc, |
| 285 const GrPath* path, | 285 const GrPath* path, |
| 286 const GrScissorState& scissorState, | 286 const GrScissorState& scissorState, |
| 287 const GrStencilSettings& stencilSettings, | 287 const GrStencilSettings& stencilSettings, |
| 288 const GrDeviceCoordTexture* dstCopy) { | 288 const GrDeviceCoordTexture* dstCopy) { |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 | 536 |
| 537 void GrInOrderDrawBuffer::recordTraceMarkersIfNecessary() { | 537 void GrInOrderDrawBuffer::recordTraceMarkersIfNecessary() { |
| 538 SkASSERT(!fCmdBuffer.empty()); | 538 SkASSERT(!fCmdBuffer.empty()); |
| 539 SkASSERT(!cmd_has_trace_marker(fCmdBuffer.back().fType)); | 539 SkASSERT(!cmd_has_trace_marker(fCmdBuffer.back().fType)); |
| 540 const GrTraceMarkerSet& activeTraceMarkers = this->getActiveTraceMarkers(); | 540 const GrTraceMarkerSet& activeTraceMarkers = this->getActiveTraceMarkers(); |
| 541 if (activeTraceMarkers.count() > 0) { | 541 if (activeTraceMarkers.count() > 0) { |
| 542 fCmdBuffer.back().fType = add_trace_bit(fCmdBuffer.back().fType); | 542 fCmdBuffer.back().fType = add_trace_bit(fCmdBuffer.back().fType); |
| 543 fGpuCmdMarkers.push_back(activeTraceMarkers); | 543 fGpuCmdMarkers.push_back(activeTraceMarkers); |
| 544 } | 544 } |
| 545 } | 545 } |
| OLD | NEW |