| 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 #ifndef GrInOrderDrawBuffer_DEFINED | 8 #ifndef GrInOrderDrawBuffer_DEFINED |
| 9 #define GrInOrderDrawBuffer_DEFINED | 9 #define GrInOrderDrawBuffer_DEFINED |
| 10 | 10 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 GrRenderTarget* renderTarget) SK_OVERRIDE; | 92 GrRenderTarget* renderTarget) SK_OVERRIDE; |
| 93 | 93 |
| 94 virtual void clearStencilClip(const SkIRect& rect, | 94 virtual void clearStencilClip(const SkIRect& rect, |
| 95 bool insideClip, | 95 bool insideClip, |
| 96 GrRenderTarget* renderTarget) SK_OVERRIDE; | 96 GrRenderTarget* renderTarget) SK_OVERRIDE; |
| 97 | 97 |
| 98 virtual void discard(GrRenderTarget*) SK_OVERRIDE; | 98 virtual void discard(GrRenderTarget*) SK_OVERRIDE; |
| 99 | 99 |
| 100 virtual void initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* des
c) SK_OVERRIDE; | 100 virtual void initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* des
c) SK_OVERRIDE; |
| 101 | 101 |
| 102 protected: | |
| 103 virtual void clipWillBeSet(const GrClipData* newClip) SK_OVERRIDE; | |
| 104 | |
| 105 private: | 102 private: |
| 103 typedef GrClipMaskManager::ScissorState ScissorState; |
| 106 enum { | 104 enum { |
| 107 kDraw_Cmd = 1, | 105 kDraw_Cmd = 1, |
| 108 kStencilPath_Cmd = 2, | 106 kStencilPath_Cmd = 2, |
| 109 kSetState_Cmd = 3, | 107 kSetState_Cmd = 3, |
| 110 kSetClip_Cmd = 4, | 108 kClear_Cmd = 4, |
| 111 kClear_Cmd = 5, | 109 kCopySurface_Cmd = 5, |
| 112 kCopySurface_Cmd = 6, | 110 kDrawPath_Cmd = 6, |
| 113 kDrawPath_Cmd = 7, | 111 kDrawPaths_Cmd = 7, |
| 114 kDrawPaths_Cmd = 8, | |
| 115 }; | 112 }; |
| 116 | 113 |
| 117 struct Cmd : ::SkNoncopyable { | 114 struct Cmd : ::SkNoncopyable { |
| 118 Cmd(uint8_t type) : fType(type) {} | 115 Cmd(uint8_t type) : fType(type) {} |
| 119 virtual ~Cmd() {} | 116 virtual ~Cmd() {} |
| 120 | 117 |
| 121 virtual void execute(GrClipTarget*) = 0; | 118 virtual void execute(GrClipTarget*) = 0; |
| 122 | 119 |
| 123 uint8_t fType; | 120 uint8_t fType; |
| 124 }; | 121 }; |
| 125 | 122 |
| 126 struct Draw : public Cmd { | 123 struct Draw : public Cmd { |
| 127 Draw(const DrawInfo& info, const GrVertexBuffer* vb, const GrIndexBuffer
* ib) | 124 Draw(const DrawInfo& info, const ScissorState& scissorState, |
| 125 const GrVertexBuffer* vb, const GrIndexBuffer* ib) |
| 128 : Cmd(kDraw_Cmd) | 126 : Cmd(kDraw_Cmd) |
| 129 , fInfo(info) | 127 , fInfo(info) |
| 128 , fScissorState(scissorState) |
| 130 , fVertexBuffer(vb) | 129 , fVertexBuffer(vb) |
| 131 , fIndexBuffer(ib) {} | 130 , fIndexBuffer(ib) {} |
| 132 | 131 |
| 133 const GrVertexBuffer* vertexBuffer() const { return fVertexBuffer.get();
} | 132 const GrVertexBuffer* vertexBuffer() const { return fVertexBuffer.get();
} |
| 134 const GrIndexBuffer* indexBuffer() const { return fIndexBuffer.get(); } | 133 const GrIndexBuffer* indexBuffer() const { return fIndexBuffer.get(); } |
| 135 | 134 |
| 136 virtual void execute(GrClipTarget*); | 135 virtual void execute(GrClipTarget*); |
| 137 | 136 |
| 138 DrawInfo fInfo; | 137 DrawInfo fInfo; |
| 138 ScissorState fScissorState; |
| 139 | 139 |
| 140 private: | 140 private: |
| 141 GrPendingIOResource<const GrVertexBuffer, kRead_GrIOType> fVertexBuff
er; | 141 GrPendingIOResource<const GrVertexBuffer, kRead_GrIOType> fVertexBuff
er; |
| 142 GrPendingIOResource<const GrIndexBuffer, kRead_GrIOType> fIndexBuffe
r; | 142 GrPendingIOResource<const GrIndexBuffer, kRead_GrIOType> fIndexBuffe
r; |
| 143 }; | 143 }; |
| 144 | 144 |
| 145 struct StencilPath : public Cmd { | 145 struct StencilPath : public Cmd { |
| 146 StencilPath(const GrPath* path) : Cmd(kStencilPath_Cmd), fPath(path) {} | 146 StencilPath(const GrPath* path) |
| 147 : Cmd(kStencilPath_Cmd), fPath(path) {} |
| 147 | 148 |
| 148 const GrPath* path() const { return fPath.get(); } | 149 const GrPath* path() const { return fPath.get(); } |
| 149 | 150 |
| 150 virtual void execute(GrClipTarget*); | 151 virtual void execute(GrClipTarget*); |
| 151 | 152 |
| 152 GrPathRendering::FillType fFill; | 153 ScissorState fScissorState; |
| 154 GrStencilSettings fStencilSettings; |
| 153 | 155 |
| 154 private: | 156 private: |
| 155 GrPendingIOResource<const GrPath, kRead_GrIOType> fPath; | 157 GrPendingIOResource<const GrPath, kRead_GrIOType> fPath; |
| 156 }; | 158 }; |
| 157 | 159 |
| 158 struct DrawPath : public Cmd { | 160 struct DrawPath : public Cmd { |
| 159 DrawPath(const GrPath* path) : Cmd(kDrawPath_Cmd), fPath(path) {} | 161 DrawPath(const GrPath* path) |
| 162 : Cmd(kDrawPath_Cmd), fPath(path) {} |
| 160 | 163 |
| 161 const GrPath* path() const { return fPath.get(); } | 164 const GrPath* path() const { return fPath.get(); } |
| 162 | 165 |
| 163 virtual void execute(GrClipTarget*); | 166 virtual void execute(GrClipTarget*); |
| 164 | 167 |
| 165 GrPathRendering::FillType fFill; | 168 GrDeviceCoordTexture fDstCopy; |
| 166 GrDeviceCoordTexture fDstCopy; | 169 ScissorState fScissorState; |
| 170 GrStencilSettings fStencilSettings; |
| 167 | 171 |
| 168 private: | 172 private: |
| 169 GrPendingIOResource<const GrPath, kRead_GrIOType> fPath; | 173 GrPendingIOResource<const GrPath, kRead_GrIOType> fPath; |
| 170 }; | 174 }; |
| 171 | 175 |
| 172 struct DrawPaths : public Cmd { | 176 struct DrawPaths : public Cmd { |
| 173 DrawPaths(const GrPathRange* pathRange) : Cmd(kDrawPaths_Cmd), fPathRang
e(pathRange) {} | 177 DrawPaths(const GrPathRange* pathRange) |
| 178 : Cmd(kDrawPaths_Cmd), fPathRange(pathRange) {} |
| 174 | 179 |
| 175 const GrPathRange* pathRange() const { return fPathRange.get(); } | 180 const GrPathRange* pathRange() const { return fPathRange.get(); } |
| 176 uint32_t* indices() { return reinterpret_cast<uint32_t*>(CmdBuffer::GetD
ataForItem(this)); } | 181 uint32_t* indices() { return reinterpret_cast<uint32_t*>(CmdBuffer::GetD
ataForItem(this)); } |
| 177 float* transforms() { return reinterpret_cast<float*>(&this->indices()[f
Count]); } | 182 float* transforms() { return reinterpret_cast<float*>(&this->indices()[f
Count]); } |
| 178 | 183 |
| 179 virtual void execute(GrClipTarget*); | 184 virtual void execute(GrClipTarget*); |
| 180 | 185 |
| 181 size_t fCount; | 186 size_t fCount; |
| 182 PathTransformType fTransformsType; | 187 PathTransformType fTransformsType; |
| 183 GrPathRendering::FillType fFill; | 188 GrDeviceCoordTexture fDstCopy; |
| 184 GrDeviceCoordTexture fDstCopy; | 189 ScissorState fScissorState; |
| 190 GrStencilSettings fStencilSettings; |
| 185 | 191 |
| 186 private: | 192 private: |
| 187 GrPendingIOResource<const GrPathRange, kRead_GrIOType> fPathRange; | 193 GrPendingIOResource<const GrPathRange, kRead_GrIOType> fPathRange; |
| 188 }; | 194 }; |
| 189 | 195 |
| 190 // This is also used to record a discard by setting the color to GrColor_ILL
EGAL | 196 // This is also used to record a discard by setting the color to GrColor_ILL
EGAL |
| 191 struct Clear : public Cmd { | 197 struct Clear : public Cmd { |
| 192 Clear(GrRenderTarget* rt) : Cmd(kClear_Cmd), fRenderTarget(rt) {} | 198 Clear(GrRenderTarget* rt) : Cmd(kClear_Cmd), fRenderTarget(rt) {} |
| 193 | 199 |
| 194 GrRenderTarget* renderTarget() const { return fRenderTarget.get(); } | 200 GrRenderTarget* renderTarget() const { return fRenderTarget.get(); } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 }; | 241 }; |
| 236 | 242 |
| 237 struct SetState : public Cmd { | 243 struct SetState : public Cmd { |
| 238 SetState(const GrDrawState& state) : Cmd(kSetState_Cmd), fState(state) {
} | 244 SetState(const GrDrawState& state) : Cmd(kSetState_Cmd), fState(state) {
} |
| 239 | 245 |
| 240 virtual void execute(GrClipTarget*); | 246 virtual void execute(GrClipTarget*); |
| 241 | 247 |
| 242 GrDrawState fState; | 248 GrDrawState fState; |
| 243 }; | 249 }; |
| 244 | 250 |
| 245 struct SetClip : public Cmd { | |
| 246 SetClip(const GrClipData* clipData) | |
| 247 : Cmd(kSetClip_Cmd), | |
| 248 fStackStorage(*clipData->fClipStack) { | |
| 249 fClipData.fClipStack = &fStackStorage; | |
| 250 fClipData.fOrigin = clipData->fOrigin; | |
| 251 } | |
| 252 | |
| 253 virtual void execute(GrClipTarget*); | |
| 254 | |
| 255 GrClipData fClipData; | |
| 256 | |
| 257 private: | |
| 258 SkClipStack fStackStorage; | |
| 259 }; | |
| 260 | |
| 261 typedef void* TCmdAlign; // This wouldn't be enough align if a command used
long double. | 251 typedef void* TCmdAlign; // This wouldn't be enough align if a command used
long double. |
| 262 typedef GrTRecorder<Cmd, TCmdAlign> CmdBuffer; | 252 typedef GrTRecorder<Cmd, TCmdAlign> CmdBuffer; |
| 263 | 253 |
| 264 // overrides from GrDrawTarget | 254 // overrides from GrDrawTarget |
| 265 virtual void onDraw(const DrawInfo&) SK_OVERRIDE; | 255 virtual void onDraw(const DrawInfo&, const GrClipMaskManager::ScissorState&)
SK_OVERRIDE; |
| 266 virtual void onDrawRect(const SkRect& rect, | 256 virtual void onDrawRect(const SkRect& rect, |
| 267 const SkRect* localRect, | 257 const SkRect* localRect, |
| 268 const SkMatrix* localMatrix) SK_OVERRIDE; | 258 const SkMatrix* localMatrix) SK_OVERRIDE; |
| 269 | 259 |
| 270 virtual void onStencilPath(const GrPath*, GrPathRendering::FillType) SK_OVER
RIDE; | 260 virtual void onStencilPath(const GrPath*, |
| 271 virtual void onDrawPath(const GrPath*, GrPathRendering::FillType, | 261 const GrClipMaskManager::ScissorState&, |
| 262 const GrStencilSettings&) SK_OVERRIDE; |
| 263 virtual void onDrawPath(const GrPath*, |
| 264 const GrClipMaskManager::ScissorState&, |
| 265 const GrStencilSettings&, |
| 272 const GrDeviceCoordTexture* dstCopy) SK_OVERRIDE; | 266 const GrDeviceCoordTexture* dstCopy) SK_OVERRIDE; |
| 273 virtual void onDrawPaths(const GrPathRange*, | 267 virtual void onDrawPaths(const GrPathRange*, |
| 274 const uint32_t indices[], int count, | 268 const uint32_t indices[], |
| 275 const float transforms[], PathTransformType, | 269 int count, |
| 276 GrPathRendering::FillType, const GrDeviceCoordTextu
re*) SK_OVERRIDE; | 270 const float transforms[], |
| 271 PathTransformType, |
| 272 const GrClipMaskManager::ScissorState&, |
| 273 const GrStencilSettings&, |
| 274 const GrDeviceCoordTexture*) SK_OVERRIDE; |
| 277 | 275 |
| 278 virtual bool onReserveVertexSpace(size_t vertexSize, | 276 virtual bool onReserveVertexSpace(size_t vertexSize, |
| 279 int vertexCount, | 277 int vertexCount, |
| 280 void** vertices) SK_OVERRIDE; | 278 void** vertices) SK_OVERRIDE; |
| 281 virtual bool onReserveIndexSpace(int indexCount, | 279 virtual bool onReserveIndexSpace(int indexCount, |
| 282 void** indices) SK_OVERRIDE; | 280 void** indices) SK_OVERRIDE; |
| 283 virtual void releaseReservedVertexSpace() SK_OVERRIDE; | 281 virtual void releaseReservedVertexSpace() SK_OVERRIDE; |
| 284 virtual void releaseReservedIndexSpace() SK_OVERRIDE; | 282 virtual void releaseReservedIndexSpace() SK_OVERRIDE; |
| 285 virtual void onSetVertexSourceToArray(const void* vertexArray, | 283 virtual void onSetVertexSourceToArray(const void* vertexArray, |
| 286 int vertexCount) SK_OVERRIDE; | 284 int vertexCount) SK_OVERRIDE; |
| 287 virtual void onSetIndexSourceToArray(const void* indexArray, | 285 virtual void onSetIndexSourceToArray(const void* indexArray, |
| 288 int indexCount) SK_OVERRIDE; | 286 int indexCount) SK_OVERRIDE; |
| 289 virtual void releaseVertexArray() SK_OVERRIDE; | 287 virtual void releaseVertexArray() SK_OVERRIDE; |
| 290 virtual void releaseIndexArray() SK_OVERRIDE; | 288 virtual void releaseIndexArray() SK_OVERRIDE; |
| 291 virtual void geometrySourceWillPush() SK_OVERRIDE; | 289 virtual void geometrySourceWillPush() SK_OVERRIDE; |
| 292 virtual void geometrySourceWillPop(const GeometrySrcState& restoredState) SK
_OVERRIDE; | 290 virtual void geometrySourceWillPop(const GeometrySrcState& restoredState) SK
_OVERRIDE; |
| 293 virtual void willReserveVertexAndIndexSpace(int vertexCount, | 291 virtual void willReserveVertexAndIndexSpace(int vertexCount, |
| 294 int indexCount) SK_OVERRIDE; | 292 int indexCount) SK_OVERRIDE; |
| 295 | 293 |
| 296 bool quickInsideClip(const SkRect& devBounds); | |
| 297 | |
| 298 virtual void didAddGpuTraceMarker() SK_OVERRIDE {} | 294 virtual void didAddGpuTraceMarker() SK_OVERRIDE {} |
| 299 virtual void didRemoveGpuTraceMarker() SK_OVERRIDE {} | 295 virtual void didRemoveGpuTraceMarker() SK_OVERRIDE {} |
| 300 | 296 |
| 301 // Attempts to concat instances from info onto the previous draw. info must
represent an | 297 // Attempts to concat instances from info onto the previous draw. info must
represent an |
| 302 // instanced draw. The caller must have already recorded a new draw state an
d clip if necessary. | 298 // instanced draw. The caller must have already recorded a new draw state an
d clip if necessary. |
| 303 int concatInstancedDraw(const DrawInfo& info); | 299 int concatInstancedDraw(const DrawInfo& info, const GrClipMaskManager::Sciss
orState&); |
| 304 | 300 |
| 305 // Determines whether the current draw operation requieres a new drawstate a
nd if so records it. | 301 // Determines whether the current draw operation requieres a new drawstate a
nd if so records it. |
| 306 void recordStateIfNecessary(); | 302 void recordStateIfNecessary(); |
| 307 // We lazily record clip changes in order to skip clips that have no effect. | 303 // We lazily record clip changes in order to skip clips that have no effect. |
| 308 void recordClipIfNecessary(); | 304 void recordClipIfNecessary(); |
| 309 // Records any trace markers for a command after adding it to the buffer. | 305 // Records any trace markers for a command after adding it to the buffer. |
| 310 void recordTraceMarkersIfNecessary(); | 306 void recordTraceMarkersIfNecessary(); |
| 311 | 307 |
| 312 virtual bool isIssued(uint32_t drawID) { return drawID != fDrawID; } | 308 virtual bool isIssued(uint32_t drawID) { return drawID != fDrawID; } |
| 313 | 309 |
| 314 // TODO: Use a single allocator for commands and records | 310 // TODO: Use a single allocator for commands and records |
| 315 enum { | 311 enum { |
| 316 kCmdBufferInitialSizeInBytes = 64 * 1024, | 312 kCmdBufferInitialSizeInBytes = 64 * 1024, |
| 317 kGeoPoolStatePreAllocCnt = 4, | 313 kGeoPoolStatePreAllocCnt = 4, |
| 318 }; | 314 }; |
| 319 | 315 |
| 320 CmdBuffer fCmdBuffer; | 316 CmdBuffer fCmdBuffer; |
| 321 GrDrawState* fLastState; | 317 GrDrawState* fLastState; |
| 322 GrClipData* fLastClip; | |
| 323 | |
| 324 SkTArray<GrTraceMarkerSet, false> fGpuCmdMarkers; | 318 SkTArray<GrTraceMarkerSet, false> fGpuCmdMarkers; |
| 325 GrClipTarget* fDstGpu; | 319 GrClipTarget* fDstGpu; |
| 326 bool fClipSet; | 320 GrVertexBufferAllocPool& fVertexPool; |
| 327 | 321 GrIndexBufferAllocPool& fIndexPool; |
| 328 enum ClipProxyState { | |
| 329 kUnknown_ClipProxyState, | |
| 330 kValid_ClipProxyState, | |
| 331 kInvalid_ClipProxyState | |
| 332 }; | |
| 333 | |
| 334 ClipProxyState fClipProxyState; | |
| 335 SkRect fClipProxy; | |
| 336 GrVertexBufferAllocPool& fVertexPool; | |
| 337 GrIndexBufferAllocPool& fIndexPool; | |
| 338 | 322 |
| 339 struct GeometryPoolState { | 323 struct GeometryPoolState { |
| 340 const GrVertexBuffer* fPoolVertexBuffer; | 324 const GrVertexBuffer* fPoolVertexBuffer; |
| 341 int fPoolStartVertex; | 325 int fPoolStartVertex; |
| 342 const GrIndexBuffer* fPoolIndexBuffer; | 326 const GrIndexBuffer* fPoolIndexBuffer; |
| 343 int fPoolStartIndex; | 327 int fPoolStartIndex; |
| 344 // caller may conservatively over reserve vertices / indices. | 328 // caller may conservatively over reserve vertices / indices. |
| 345 // we release unused space back to allocator if possible | 329 // we release unused space back to allocator if possible |
| 346 // can only do this if there isn't an intervening pushGeometrySource() | 330 // can only do this if there isn't an intervening pushGeometrySource() |
| 347 size_t fUsedPoolVertexBytes; | 331 size_t fUsedPoolVertexBytes; |
| 348 size_t fUsedPoolIndexBytes; | 332 size_t fUsedPoolIndexBytes; |
| 349 }; | 333 }; |
| 350 | 334 |
| 351 typedef SkSTArray<kGeoPoolStatePreAllocCnt, GeometryPoolState> GeoPoolStateS
tack; | 335 typedef SkSTArray<kGeoPoolStatePreAllocCnt, GeometryPoolState> GeoPoolStateS
tack; |
| 352 | 336 |
| 353 GeoPoolStateStack fGeoPoolStateStack; | 337 GeoPoolStateStack fGeoPoolStateStack; |
| 354 bool fFlushing; | 338 bool fFlushing; |
| 355 uint32_t fDrawID; | 339 uint32_t fDrawID; |
| 356 | 340 |
| 357 typedef GrClipTarget INHERITED; | 341 typedef GrClipTarget INHERITED; |
| 358 }; | 342 }; |
| 359 | 343 |
| 360 #endif | 344 #endif |
| OLD | NEW |