OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2010 Google Inc. | 2 * Copyright 2010 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 GrDrawTarget_DEFINED | 8 #ifndef GrDrawTarget_DEFINED |
9 #define GrDrawTarget_DEFINED | 9 #define GrDrawTarget_DEFINED |
10 | 10 |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "SkPath.h" | 24 #include "SkPath.h" |
25 #include "SkStrokeRec.h" | 25 #include "SkStrokeRec.h" |
26 #include "SkTArray.h" | 26 #include "SkTArray.h" |
27 #include "SkTLazy.h" | 27 #include "SkTLazy.h" |
28 #include "SkTypes.h" | 28 #include "SkTypes.h" |
29 #include "SkXfermode.h" | 29 #include "SkXfermode.h" |
30 | 30 |
31 class GrBatch; | 31 class GrBatch; |
32 class GrClip; | 32 class GrClip; |
33 class GrDrawTargetCaps; | 33 class GrDrawTargetCaps; |
| 34 class GrIndexBufferAllocPool; |
34 class GrPath; | 35 class GrPath; |
35 class GrPathRange; | 36 class GrPathRange; |
36 class GrPipeline; | 37 class GrPipeline; |
| 38 class GrVertexBufferAllocPool; |
37 | 39 |
38 class GrDrawTarget : public SkRefCnt { | 40 class GrDrawTarget : public SkRefCnt { |
39 public: | 41 public: |
40 SK_DECLARE_INST_COUNT(GrDrawTarget) | 42 SK_DECLARE_INST_COUNT(GrDrawTarget) |
41 | 43 |
42 typedef GrPathRange::PathIndexType PathIndexType; | 44 typedef GrPathRange::PathIndexType PathIndexType; |
43 typedef GrPathRendering::PathTransformType PathTransformType; | 45 typedef GrPathRendering::PathTransformType PathTransformType; |
44 | 46 |
45 /////////////////////////////////////////////////////////////////////////// | 47 /////////////////////////////////////////////////////////////////////////// |
46 | 48 |
47 // The context may not be fully constructed and should not be used during Gr
DrawTarget | 49 // The context may not be fully constructed and should not be used during Gr
DrawTarget |
48 // construction. | 50 // construction. |
49 GrDrawTarget(GrContext* context); | 51 GrDrawTarget(GrContext* context, GrVertexBufferAllocPool*, GrIndexBufferAllo
cPool*); |
| 52 |
50 virtual ~GrDrawTarget() {} | 53 virtual ~GrDrawTarget() {} |
51 | 54 |
52 /** | 55 /** |
| 56 * Empties the draw buffer of any queued up draws. |
| 57 */ |
| 58 void reset(); |
| 59 |
| 60 /** |
| 61 * This plays any queued up draws to its GrGpu target. It also resets this o
bject (i.e. flushing |
| 62 * is destructive). |
| 63 */ |
| 64 void flush(); |
| 65 |
| 66 /** |
53 * Gets the capabilities of the draw target. | 67 * Gets the capabilities of the draw target. |
54 */ | 68 */ |
55 const GrDrawTargetCaps* caps() const { return fCaps.get(); } | 69 const GrDrawTargetCaps* caps() const { return fCaps.get(); } |
56 | 70 |
57 // TODO devbounds should live on the batch | 71 // TODO devbounds should live on the batch |
58 void drawBatch(GrPipelineBuilder*, GrBatch*, const SkRect* devBounds = NULL)
; | 72 void drawBatch(GrPipelineBuilder*, GrBatch*, const SkRect* devBounds = NULL)
; |
59 | 73 |
60 /** | 74 /** |
61 * Draws path into the stencil buffer. The fill must be either even/odd or | 75 * Draws path into the stencil buffer. The fill must be either even/odd or |
62 * winding (not inverse or hairline). It will respect the HW antialias flag | 76 * winding (not inverse or hairline). It will respect the HW antialias flag |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 }; | 308 }; |
295 | 309 |
296 bool programUnitTest(int maxStages); | 310 bool programUnitTest(int maxStages); |
297 | 311 |
298 protected: | 312 protected: |
299 friend class GrTargetCommands; // for PipelineInfo | 313 friend class GrTargetCommands; // for PipelineInfo |
300 | 314 |
301 GrContext* getContext() { return fContext; } | 315 GrContext* getContext() { return fContext; } |
302 const GrContext* getContext() const { return fContext; } | 316 const GrContext* getContext() const { return fContext; } |
303 | 317 |
304 // Subclass must initialize this in its constructor. | 318 GrGpu* getGpu() { |
305 SkAutoTUnref<const GrDrawTargetCaps> fCaps; | 319 SkASSERT(fContext && fContext->getGpu()); |
| 320 return fContext->getGpu(); |
| 321 } |
| 322 const GrGpu* getGpu() const { |
| 323 SkASSERT(fContext && fContext->getGpu()); |
| 324 return fContext->getGpu(); |
| 325 } |
| 326 |
| 327 GrVertexBufferAllocPool* getVertexAllocPool() { return fVertexPool; } |
| 328 GrIndexBufferAllocPool* getIndexAllocPool() { return fIndexPool; } |
306 | 329 |
307 const GrTraceMarkerSet& getActiveTraceMarkers() { return fActiveTraceMarkers
; } | 330 const GrTraceMarkerSet& getActiveTraceMarkers() { return fActiveTraceMarkers
; } |
308 | 331 |
309 // Makes a copy of the dst if it is necessary for the draw. Returns false if
a copy is required | 332 // Makes a copy of the dst if it is necessary for the draw. Returns false if
a copy is required |
310 // but couldn't be made. Otherwise, returns true. This method needs to be p
rotected because it | 333 // but couldn't be made. Otherwise, returns true. This method needs to be p
rotected because it |
311 // needs to be accessed by GLPrograms to setup a correct drawstate | 334 // needs to be accessed by GLPrograms to setup a correct drawstate |
312 bool setupDstReadIfNecessary(const GrPipelineBuilder&, | 335 bool setupDstReadIfNecessary(const GrPipelineBuilder&, |
313 const GrProcOptInfo& colorPOI, | 336 const GrProcOptInfo& colorPOI, |
314 const GrProcOptInfo& coveragePOI, | 337 const GrProcOptInfo& coveragePOI, |
315 GrDeviceCoordTexture* dstCopy, | 338 GrDeviceCoordTexture* dstCopy, |
(...skipping 19 matching lines...) Expand all Loading... |
335 GrPipelineBuilder* fPipelineBuilder; | 358 GrPipelineBuilder* fPipelineBuilder; |
336 GrScissorState* fScissor; | 359 GrScissorState* fScissor; |
337 GrProcOptInfo fColorPOI; | 360 GrProcOptInfo fColorPOI; |
338 GrProcOptInfo fCoveragePOI; | 361 GrProcOptInfo fCoveragePOI; |
339 GrDeviceCoordTexture fDstCopy; | 362 GrDeviceCoordTexture fDstCopy; |
340 }; | 363 }; |
341 | 364 |
342 void setupPipeline(const PipelineInfo& pipelineInfo, GrPipeline* pipeline); | 365 void setupPipeline(const PipelineInfo& pipelineInfo, GrPipeline* pipeline); |
343 | 366 |
344 private: | 367 private: |
345 /** | 368 virtual void onReset() = 0; |
346 * This will be called before allocating a texture as a dst for copySurface.
This function | |
347 * populates the dstDesc's config, flags, and origin so as to maximize effic
iency and guarantee | |
348 * success of the copySurface call. | |
349 */ | |
350 void initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* dstDesc) { | |
351 if (!this->onInitCopySurfaceDstDesc(src, dstDesc)) { | |
352 dstDesc->fOrigin = kDefault_GrSurfaceOrigin; | |
353 dstDesc->fFlags = kRenderTarget_GrSurfaceFlag; | |
354 dstDesc->fConfig = src->config(); | |
355 } | |
356 } | |
357 | 369 |
358 /** Internal implementation of canCopySurface. */ | 370 virtual void onFlush() = 0; |
359 bool internalCanCopySurface(const GrSurface* dst, | |
360 const GrSurface* src, | |
361 const SkIRect& clippedSrcRect, | |
362 const SkIPoint& clippedDstRect); | |
363 | 371 |
364 virtual void onDrawBatch(GrBatch*, const PipelineInfo&) = 0; | 372 virtual void onDrawBatch(GrBatch*, const PipelineInfo&) = 0; |
365 // TODO copy in order drawbuffer onDrawRect to here | 373 // TODO copy in order drawbuffer onDrawRect to here |
366 virtual void onDrawRect(GrPipelineBuilder*, | 374 virtual void onDrawRect(GrPipelineBuilder*, |
367 GrColor color, | 375 GrColor color, |
368 const SkMatrix& viewMatrix, | 376 const SkMatrix& viewMatrix, |
369 const SkRect& rect, | 377 const SkRect& rect, |
370 const SkRect* localRect, | 378 const SkRect* localRect, |
371 const SkMatrix* localMatrix) = 0; | 379 const SkMatrix* localMatrix) = 0; |
372 | 380 |
(...skipping 12 matching lines...) Expand all Loading... |
385 PathIndexType, | 393 PathIndexType, |
386 const float transformValues[], | 394 const float transformValues[], |
387 PathTransformType, | 395 PathTransformType, |
388 int count, | 396 int count, |
389 const GrStencilSettings&, | 397 const GrStencilSettings&, |
390 const PipelineInfo&) = 0; | 398 const PipelineInfo&) = 0; |
391 | 399 |
392 virtual void onClear(const SkIRect* rect, GrColor color, bool canIgnoreRect, | 400 virtual void onClear(const SkIRect* rect, GrColor color, bool canIgnoreRect, |
393 GrRenderTarget* renderTarget) = 0; | 401 GrRenderTarget* renderTarget) = 0; |
394 | 402 |
395 /** The subclass will get a chance to copy the surface for falling back to t
he default | 403 /** The subclass's copy surface implementation. It should assume that any cl
ipping has already |
396 implementation, which simply draws a rectangle (and fails if dst isn't a
render target). It | 404 been performed on the rect and point and that the GrGpu supports the cop
y. */ |
397 should assume that any clipping has already been performed on the rect a
nd point. It won't | 405 virtual void onCopySurface(GrSurface* dst, |
398 be called if the copy can be skipped. */ | |
399 virtual bool onCopySurface(GrSurface* dst, | |
400 GrSurface* src, | 406 GrSurface* src, |
401 const SkIRect& srcRect, | 407 const SkIRect& srcRect, |
402 const SkIPoint& dstPoint) = 0; | 408 const SkIPoint& dstPoint) = 0; |
403 | 409 |
404 /** Indicates whether onCopySurface would succeed. It should assume that any
clipping has | |
405 already been performed on the rect and point. It won't be called if the
copy can be | |
406 skipped. */ | |
407 virtual bool onCanCopySurface(const GrSurface* dst, | |
408 const GrSurface* src, | |
409 const SkIRect& srcRect, | |
410 const SkIPoint& dstPoint) = 0; | |
411 /** | |
412 * This will be called before allocating a texture to be a dst for onCopySur
face. Only the | |
413 * dstDesc's config, flags, and origin need be set by the function. If the s
ubclass cannot | |
414 * create a surface that would succeed its implementation of onCopySurface,
it should return | |
415 * false. The base class will fall back to creating a render target to draw
into using the src. | |
416 */ | |
417 virtual bool onInitCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* d
stDesc) = 0; | |
418 | |
419 // Check to see if this set of draw commands has been sent out | 410 // Check to see if this set of draw commands has been sent out |
420 virtual bool isIssued(uint32_t drawID) { return true; } | 411 virtual bool isIssued(uint32_t drawID) { return true; } |
421 void getPathStencilSettingsForFilltype(GrPathRendering::FillType, | 412 void getPathStencilSettingsForFilltype(GrPathRendering::FillType, |
422 const GrStencilAttachment*, | 413 const GrStencilAttachment*, |
423 GrStencilSettings*); | 414 GrStencilSettings*); |
424 virtual GrClipMaskManager* clipMaskManager() = 0; | 415 virtual GrClipMaskManager* clipMaskManager() = 0; |
425 virtual bool setupClip(GrPipelineBuilder*, | 416 virtual bool setupClip(GrPipelineBuilder*, |
426 GrPipelineBuilder::AutoRestoreFragmentProcessors*, | 417 GrPipelineBuilder::AutoRestoreFragmentProcessors*, |
427 GrPipelineBuilder::AutoRestoreStencil*, | 418 GrPipelineBuilder::AutoRestoreStencil*, |
428 GrScissorState*, | 419 GrScissorState*, |
429 const SkRect* devBounds) = 0; | 420 const SkRect* devBounds) = 0; |
430 | 421 |
431 // The context owns us, not vice-versa, so this ptr is not ref'ed by DrawTar
get. | 422 // The context owns us, not vice-versa, so this ptr is not ref'ed by DrawTar
get. |
432 GrContext* fContext; | 423 GrContext* fContext; |
| 424 SkAutoTUnref<const GrDrawTargetCaps> fCaps; |
433 // To keep track that we always have at least as many debug marker adds as r
emoves | 425 // To keep track that we always have at least as many debug marker adds as r
emoves |
434 int fGpuTraceMar
kerCount; | 426 int fGpuTraceMar
kerCount; |
435 GrTraceMarkerSet fActiveTrace
Markers; | 427 GrTraceMarkerSet fActiveTrace
Markers; |
436 GrTraceMarkerSet fStoredTrace
Markers; | 428 GrTraceMarkerSet fStoredTrace
Markers; |
| 429 GrVertexBufferAllocPool* fVertexPool; |
| 430 GrIndexBufferAllocPool* fIndexPool; |
| 431 bool fFlushing; |
437 | 432 |
438 typedef SkRefCnt INHERITED; | 433 typedef SkRefCnt INHERITED; |
439 }; | 434 }; |
440 | 435 |
441 /* | 436 /* |
442 * This class is JUST for clip mask manager. Everyone else should just use draw
target above. | 437 * This class is JUST for clip mask manager. Everyone else should just use draw
target above. |
443 */ | 438 */ |
444 class GrClipTarget : public GrDrawTarget { | 439 class GrClipTarget : public GrDrawTarget { |
445 public: | 440 public: |
446 GrClipTarget(GrContext* context) : INHERITED(context) { | 441 GrClipTarget(GrContext* context, |
| 442 GrVertexBufferAllocPool* vpool, |
| 443 GrIndexBufferAllocPool* ipool) |
| 444 : INHERITED(context, vpool, ipool) { |
447 fClipMaskManager.setClipTarget(this); | 445 fClipMaskManager.setClipTarget(this); |
448 } | 446 } |
449 | 447 |
450 /* Clip mask manager needs access to the context. | 448 /* Clip mask manager needs access to the context. |
451 * TODO we only need a very small subset of context in the CMM. | 449 * TODO we only need a very small subset of context in the CMM. |
452 */ | 450 */ |
453 GrContext* getContext() { return INHERITED::getContext(); } | 451 GrContext* getContext() { return INHERITED::getContext(); } |
454 const GrContext* getContext() const { return INHERITED::getContext(); } | 452 const GrContext* getContext() const { return INHERITED::getContext(); } |
455 | 453 |
456 /** | 454 /** |
(...skipping 23 matching lines...) Expand all Loading... |
480 virtual bool setupClip(GrPipelineBuilder*, | 478 virtual bool setupClip(GrPipelineBuilder*, |
481 GrPipelineBuilder::AutoRestoreFragmentProcessors*, | 479 GrPipelineBuilder::AutoRestoreFragmentProcessors*, |
482 GrPipelineBuilder::AutoRestoreStencil*, | 480 GrPipelineBuilder::AutoRestoreStencil*, |
483 GrScissorState* scissorState, | 481 GrScissorState* scissorState, |
484 const SkRect* devBounds) override; | 482 const SkRect* devBounds) override; |
485 | 483 |
486 typedef GrDrawTarget INHERITED; | 484 typedef GrDrawTarget INHERITED; |
487 }; | 485 }; |
488 | 486 |
489 #endif | 487 #endif |
OLD | NEW |