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 GrGpu_DEFINED | 8 #ifndef GrGpu_DEFINED |
9 #define GrGpu_DEFINED | 9 #define GrGpu_DEFINED |
10 | 10 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 virtual ~GrGpu(); | 53 virtual ~GrGpu(); |
54 | 54 |
55 GrContext* getContext() { return fContext; } | 55 GrContext* getContext() { return fContext; } |
56 const GrContext* getContext() const { return fContext; } | 56 const GrContext* getContext() const { return fContext; } |
57 | 57 |
58 /** | 58 /** |
59 * Gets the capabilities of the draw target. | 59 * Gets the capabilities of the draw target. |
60 */ | 60 */ |
61 const GrDrawTargetCaps* caps() const { return fCaps.get(); } | 61 const GrDrawTargetCaps* caps() const { return fCaps.get(); } |
62 | 62 |
63 /** | |
64 * Sets the draw state object for the gpu. Note that this does not | |
65 * make a copy. The GrGpu will take a reference to passed object. | |
66 * Passing NULL will cause the GrGpu to use its own internal draw | |
67 * state object rather than an externally provided one. | |
68 */ | |
69 void setDrawState(GrDrawState* drawState); | |
70 | |
71 /** | |
72 * Read-only access to the GrGpu current draw state. | |
73 */ | |
74 const GrDrawState& getDrawState() const { return *fDrawState; } | |
75 | |
76 /** | |
77 * Read-write access to the GrGpu current draw state. Note that | |
78 * this doesn't ref. | |
79 */ | |
80 GrDrawState* drawState() { return fDrawState; } | |
81 | |
82 GrPathRendering* pathRendering() { | 63 GrPathRendering* pathRendering() { |
83 return fPathRendering.get(); | 64 return fPathRendering.get(); |
84 } | 65 } |
85 | 66 |
86 // Called by GrContext when the underlying backend context has been destroye
d. | 67 // Called by GrContext when the underlying backend context has been destroye
d. |
87 // GrGpu should use this to ensure that no backend API calls will be made fr
om | 68 // GrGpu should use this to ensure that no backend API calls will be made fr
om |
88 // here onward, including in its destructor. Subclasses should call | 69 // here onward, including in its destructor. Subclasses should call |
89 // INHERITED::contextAbandoned() if they override this. | 70 // INHERITED::contextAbandoned() if they override this. |
90 virtual void contextAbandoned(); | 71 virtual void contextAbandoned(); |
91 | 72 |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 * can be optionally cleared. | 276 * can be optionally cleared. |
296 */ | 277 */ |
297 void clear(const SkIRect* rect, | 278 void clear(const SkIRect* rect, |
298 GrColor color, | 279 GrColor color, |
299 bool canIgnoreRect, | 280 bool canIgnoreRect, |
300 GrRenderTarget* renderTarget); | 281 GrRenderTarget* renderTarget); |
301 | 282 |
302 | 283 |
303 void clearStencilClip(const SkIRect& rect, | 284 void clearStencilClip(const SkIRect& rect, |
304 bool insideClip, | 285 bool insideClip, |
305 GrRenderTarget* renderTarget = NULL); | 286 GrRenderTarget* renderTarget); |
306 | 287 |
307 /** | 288 /** |
308 * Discards the contents render target. NULL indicates that the current rend
er target should | 289 * Discards the contents render target. NULL indicates that the current rend
er target should |
309 * be discarded. | 290 * be discarded. |
310 **/ | 291 **/ |
311 virtual void discard(GrRenderTarget* = NULL) = 0; | 292 virtual void discard(GrRenderTarget* = NULL) = 0; |
312 | 293 |
313 /** | 294 /** |
314 * This is can be called before allocating a texture to be a dst for copySur
face. It will | 295 * This is can be called before allocating a texture to be a dst for copySur
face. It will |
315 * populate the origin, config, and flags fields of the desc such that copyS
urface is more | 296 * populate the origin, config, and flags fields of the desc such that copyS
urface is more |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 const SkIPoint& dstPoint) = 0; | 375 const SkIPoint& dstPoint) = 0; |
395 | 376 |
396 /** | 377 /** |
397 * Sets source of vertex data for the next draw. Data does not have to be | 378 * Sets source of vertex data for the next draw. Data does not have to be |
398 * in the buffer until drawIndexed, drawNonIndexed, or drawIndexedInstances. | 379 * in the buffer until drawIndexed, drawNonIndexed, or drawIndexedInstances. |
399 * | 380 * |
400 * @param buffer vertex buffer containing vertex data. Must be | 381 * @param buffer vertex buffer containing vertex data. Must be |
401 * unlocked before draw call. Vertex size is queried | 382 * unlocked before draw call. Vertex size is queried |
402 * from current GrDrawState. | 383 * from current GrDrawState. |
403 */ | 384 */ |
404 void setVertexSourceToBuffer(const GrVertexBuffer* buffer); | 385 void setVertexSourceToBuffer(const GrVertexBuffer* buffer, size_t vertexStri
de); |
405 | 386 |
406 /** | 387 /** |
407 * Sets source of index data for the next indexed draw. Data does not have | 388 * Sets source of index data for the next indexed draw. Data does not have |
408 * to be in the buffer until drawIndexed. | 389 * to be in the buffer until drawIndexed. |
409 * | 390 * |
410 * @param buffer index buffer containing indices. Must be unlocked | 391 * @param buffer index buffer containing indices. Must be unlocked |
411 * before indexed draw call. | 392 * before indexed draw call. |
412 */ | 393 */ |
413 void setIndexSourceToBuffer(const GrIndexBuffer* buffer); | 394 void setIndexSourceToBuffer(const GrIndexBuffer* buffer); |
414 | 395 |
415 virtual void draw(const GrDrawTarget::DrawInfo&, | 396 virtual void draw(const GrOptDrawState&, |
| 397 const GrDrawTarget::DrawInfo&, |
416 const GrClipMaskManager::ScissorState&); | 398 const GrClipMaskManager::ScissorState&); |
417 virtual void stencilPath(const GrPath*, | 399 virtual void stencilPath(const GrOptDrawState&, |
| 400 const GrPath*, |
418 const GrClipMaskManager::ScissorState&, | 401 const GrClipMaskManager::ScissorState&, |
419 const GrStencilSettings&); | 402 const GrStencilSettings&); |
420 virtual void drawPath(const GrPath*, | 403 virtual void drawPath(const GrOptDrawState&, |
| 404 const GrPath*, |
421 const GrClipMaskManager::ScissorState&, | 405 const GrClipMaskManager::ScissorState&, |
422 const GrStencilSettings&, | 406 const GrStencilSettings&, |
423 const GrDeviceCoordTexture* dstCopy); | 407 const GrDeviceCoordTexture* dstCopy); |
424 virtual void drawPaths(const GrPathRange*, | 408 virtual void drawPaths(const GrOptDrawState&, |
| 409 const GrPathRange*, |
425 const uint32_t indices[], | 410 const uint32_t indices[], |
426 int count, | 411 int count, |
427 const float transforms[], | 412 const float transforms[], |
428 GrDrawTarget::PathTransformType, | 413 GrDrawTarget::PathTransformType, |
429 const GrClipMaskManager::ScissorState&, | 414 const GrClipMaskManager::ScissorState&, |
430 const GrStencilSettings&, | 415 const GrStencilSettings&, |
431 const GrDeviceCoordTexture*); | 416 const GrDeviceCoordTexture*); |
432 | 417 |
433 protected: | 418 static DrawType PrimTypeToDrawType(GrPrimitiveType type) { |
434 DrawType PrimTypeToDrawType(GrPrimitiveType type) { | |
435 switch (type) { | 419 switch (type) { |
436 case kTriangles_GrPrimitiveType: | 420 case kTriangles_GrPrimitiveType: |
437 case kTriangleStrip_GrPrimitiveType: | 421 case kTriangleStrip_GrPrimitiveType: |
438 case kTriangleFan_GrPrimitiveType: | 422 case kTriangleFan_GrPrimitiveType: |
439 return kDrawTriangles_DrawType; | 423 return kDrawTriangles_DrawType; |
440 case kPoints_GrPrimitiveType: | 424 case kPoints_GrPrimitiveType: |
441 return kDrawPoints_DrawType; | 425 return kDrawPoints_DrawType; |
442 case kLines_GrPrimitiveType: | 426 case kLines_GrPrimitiveType: |
443 case kLineStrip_GrPrimitiveType: | 427 case kLineStrip_GrPrimitiveType: |
444 return kDrawLines_DrawType; | 428 return kDrawLines_DrawType; |
445 default: | 429 default: |
446 SkFAIL("Unexpected primitive type"); | 430 SkFAIL("Unexpected primitive type"); |
447 return kDrawTriangles_DrawType; | 431 return kDrawTriangles_DrawType; |
448 } | 432 } |
449 } | 433 } |
450 | 434 |
| 435 protected: |
451 // Functions used to map clip-respecting stencil tests into normal | 436 // Functions used to map clip-respecting stencil tests into normal |
452 // stencil funcs supported by GPUs. | 437 // stencil funcs supported by GPUs. |
453 static GrStencilFunc ConvertStencilFunc(bool stencilInClip, | 438 static GrStencilFunc ConvertStencilFunc(bool stencilInClip, |
454 GrStencilFunc func); | 439 GrStencilFunc func); |
455 static void ConvertStencilFuncAndMask(GrStencilFunc func, | 440 static void ConvertStencilFuncAndMask(GrStencilFunc func, |
456 bool clipInStencil, | 441 bool clipInStencil, |
457 unsigned int clipBit, | 442 unsigned int clipBit, |
458 unsigned int userBits, | 443 unsigned int userBits, |
459 unsigned int* ref, | 444 unsigned int* ref, |
460 unsigned int* mask); | 445 unsigned int* mask); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 bool canIgnoreRect) = 0; | 491 bool canIgnoreRect) = 0; |
507 | 492 |
508 | 493 |
509 // Overridden by backend specific classes to perform a clear of the stencil
clip bits. This is | 494 // Overridden by backend specific classes to perform a clear of the stencil
clip bits. This is |
510 // ONLY used by the the clip target | 495 // ONLY used by the the clip target |
511 virtual void onClearStencilClip(GrRenderTarget*, | 496 virtual void onClearStencilClip(GrRenderTarget*, |
512 const SkIRect& rect, | 497 const SkIRect& rect, |
513 bool insideClip) = 0; | 498 bool insideClip) = 0; |
514 | 499 |
515 // overridden by backend-specific derived class to perform the draw call. | 500 // overridden by backend-specific derived class to perform the draw call. |
516 virtual void onDraw(const GrDrawTarget::DrawInfo&) = 0; | 501 virtual void onDraw(const GrOptDrawState&, const GrDrawTarget::DrawInfo&) =
0; |
517 | 502 |
518 // overridden by backend-specific derived class to perform the read pixels. | 503 // overridden by backend-specific derived class to perform the read pixels. |
519 virtual bool onReadPixels(GrRenderTarget* target, | 504 virtual bool onReadPixels(GrRenderTarget* target, |
520 int left, int top, int width, int height, | 505 int left, int top, int width, int height, |
521 GrPixelConfig, | 506 GrPixelConfig, |
522 void* buffer, | 507 void* buffer, |
523 size_t rowBytes) = 0; | 508 size_t rowBytes) = 0; |
524 | 509 |
525 // overridden by backend-specific derived class to perform the texture updat
e | 510 // overridden by backend-specific derived class to perform the texture updat
e |
526 virtual bool onWriteTexturePixels(GrTexture* texture, | 511 virtual bool onWriteTexturePixels(GrTexture* texture, |
527 int left, int top, int width, int height, | 512 int left, int top, int width, int height, |
528 GrPixelConfig config, const void* buffer, | 513 GrPixelConfig config, const void* buffer, |
529 size_t rowBytes) = 0; | 514 size_t rowBytes) = 0; |
530 | 515 |
531 // overridden by backend-specific derived class to perform the resolve | 516 // overridden by backend-specific derived class to perform the resolve |
532 virtual void onResolveRenderTarget(GrRenderTarget* target) = 0; | 517 virtual void onResolveRenderTarget(GrRenderTarget* target) = 0; |
533 | 518 |
534 // width and height may be larger than rt (if underlying API allows it). | 519 // width and height may be larger than rt (if underlying API allows it). |
535 // Should attach the SB to the RT. Returns false if compatible sb could | 520 // Should attach the SB to the RT. Returns false if compatible sb could |
536 // not be created. | 521 // not be created. |
537 virtual bool createStencilBufferForRenderTarget(GrRenderTarget*, int width,
int height) = 0; | 522 virtual bool createStencilBufferForRenderTarget(GrRenderTarget*, int width,
int height) = 0; |
538 | 523 |
539 // attaches an existing SB to an existing RT. | 524 // attaches an existing SB to an existing RT. |
540 virtual bool attachStencilBufferToRenderTarget(GrStencilBuffer*, GrRenderTar
get*) = 0; | 525 virtual bool attachStencilBufferToRenderTarget(GrStencilBuffer*, GrRenderTar
get*) = 0; |
541 | 526 |
542 // The GrGpu typically records the clients requested state and then flushes | 527 // The GrGpu typically records the clients requested state and then flushes |
543 // deltas from previous state at draw time. This function does the | 528 // deltas from previous state at draw time. This function does the |
544 // backend-specific flush of the state. | 529 // backend-specific flush of the state. |
545 // returns false if current state is unsupported. | 530 // returns false if current state is unsupported. |
546 virtual bool flushGraphicsState(DrawType, | 531 virtual bool flushGraphicsState(const GrOptDrawState&, |
| 532 DrawType, |
547 const GrClipMaskManager::ScissorState&, | 533 const GrClipMaskManager::ScissorState&, |
548 const GrDeviceCoordTexture* dstCopy) = 0; | 534 const GrDeviceCoordTexture* dstCopy) = 0; |
549 | 535 |
550 // clears target's entire stencil buffer to 0 | 536 // clears target's entire stencil buffer to 0 |
551 virtual void clearStencil(GrRenderTarget* target) = 0; | 537 virtual void clearStencil(GrRenderTarget* target) = 0; |
552 | 538 |
553 // Given a rt, find or create a stencil buffer and attach it | 539 // Given a rt, find or create a stencil buffer and attach it |
554 bool attachStencilBufferToRenderTarget(GrRenderTarget* target); | 540 bool attachStencilBufferToRenderTarget(GrRenderTarget* target); |
555 | 541 |
556 virtual void didAddGpuTraceMarker() = 0; | 542 virtual void didAddGpuTraceMarker() = 0; |
557 virtual void didRemoveGpuTraceMarker() = 0; | 543 virtual void didRemoveGpuTraceMarker() = 0; |
558 | 544 |
559 void resetContext() { | 545 void resetContext() { |
560 this->onResetContext(fResetBits); | 546 this->onResetContext(fResetBits); |
561 fResetBits = 0; | 547 fResetBits = 0; |
562 ++fResetTimestamp; | 548 ++fResetTimestamp; |
563 } | 549 } |
564 | 550 |
565 void handleDirtyContext() { | 551 void handleDirtyContext() { |
566 if (fResetBits) { | 552 if (fResetBits) { |
567 this->resetContext(); | 553 this->resetContext(); |
568 } | 554 } |
569 } | 555 } |
570 | 556 |
571 GeometrySrcState fGeoSrcS
tate; | 557 GeometrySrcState fGeoSrcS
tate; |
572 ResetTimestamp fResetTi
mestamp; | 558 ResetTimestamp fResetTi
mestamp; |
573 uint32_t fResetBi
ts; | 559 uint32_t fResetBi
ts; |
574 // these are mutable so they can be created on-demand | 560 // these are mutable so they can be created on-demand |
575 mutable GrIndexBuffer* fQuadInd
exBuffer; | 561 mutable GrIndexBuffer* fQuadInd
exBuffer; |
576 GrDrawState fDefault
DrawState; | |
577 GrDrawState* fDrawSta
te; | |
578 // To keep track that we always have at least as many debug marker adds as r
emoves | 562 // To keep track that we always have at least as many debug marker adds as r
emoves |
579 int fGpuTrac
eMarkerCount; | 563 int fGpuTrac
eMarkerCount; |
580 GrTraceMarkerSet fActiveT
raceMarkers; | 564 GrTraceMarkerSet fActiveT
raceMarkers; |
581 GrTraceMarkerSet fStoredT
raceMarkers; | 565 GrTraceMarkerSet fStoredT
raceMarkers; |
582 // The context owns us, not vice-versa, so this ptr is not ref'ed by Gpu. | 566 // The context owns us, not vice-versa, so this ptr is not ref'ed by Gpu. |
583 GrContext* fContext
; | 567 GrContext* fContext
; |
584 | 568 |
585 typedef SkRefCnt INHERITED; | 569 typedef SkRefCnt INHERITED; |
586 }; | 570 }; |
587 | 571 |
588 #endif | 572 #endif |
OLD | NEW |