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 |
11 #include "GrDrawTarget.h" | 11 #include "GrDrawTarget.h" |
12 #include "GrPathRendering.h" | 12 #include "GrPathRendering.h" |
13 #include "GrProgramDesc.h" | 13 #include "GrProgramDesc.h" |
14 #include "SkPath.h" | 14 #include "SkPath.h" |
15 | 15 |
16 class GrContext; | 16 class GrContext; |
17 class GrIndexBufferAllocPool; | 17 class GrIndexBufferAllocPool; |
18 class GrPath; | 18 class GrPath; |
19 class GrPathRange; | 19 class GrPathRange; |
20 class GrPathRenderer; | 20 class GrPathRenderer; |
21 class GrPathRendererChain; | 21 class GrPathRendererChain; |
22 class GrPipeline; | 22 class GrPipeline; |
23 class GrPrimitiveProcessor; | 23 class GrPrimitiveProcessor; |
24 class GrStencilBuffer; | 24 class GrStencilAttachment; |
25 class GrVertexBufferAllocPool; | 25 class GrVertexBufferAllocPool; |
26 | 26 |
27 class GrGpu : public SkRefCnt { | 27 class GrGpu : public SkRefCnt { |
28 public: | 28 public: |
29 /** | 29 /** |
30 * Create an instance of GrGpu that matches the specified backend. If the re
quested backend is | 30 * Create an instance of GrGpu that matches the specified backend. If the re
quested backend is |
31 * not supported (at compile-time or run-time) this returns NULL. The contex
t will not be | 31 * not supported (at compile-time or run-time) this returns NULL. The contex
t will not be |
32 * fully constructed and should not be used by GrGpu until after this functi
on returns. | 32 * fully constructed and should not be used by GrGpu until after this functi
on returns. |
33 */ | 33 */ |
34 static GrGpu* Create(GrBackend, GrBackendContext, GrContext* context); | 34 static GrGpu* Create(GrBackend, GrBackendContext, GrContext* context); |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 class Stats { | 351 class Stats { |
352 public: | 352 public: |
353 #if GR_GPU_STATS | 353 #if GR_GPU_STATS |
354 Stats() { this->reset(); } | 354 Stats() { this->reset(); } |
355 | 355 |
356 void reset() { | 356 void reset() { |
357 fRenderTargetBinds = 0; | 357 fRenderTargetBinds = 0; |
358 fShaderCompilations = 0; | 358 fShaderCompilations = 0; |
359 fTextureCreates = 0; | 359 fTextureCreates = 0; |
360 fTextureUploads = 0; | 360 fTextureUploads = 0; |
361 fStencilBufferCreates = 0; | 361 fStencilAttachmentCreates = 0; |
362 } | 362 } |
363 | 363 |
364 int renderTargetBinds() const { return fRenderTargetBinds; } | 364 int renderTargetBinds() const { return fRenderTargetBinds; } |
365 void incRenderTargetBinds() { fRenderTargetBinds++; } | 365 void incRenderTargetBinds() { fRenderTargetBinds++; } |
366 int shaderCompilations() const { return fShaderCompilations; } | 366 int shaderCompilations() const { return fShaderCompilations; } |
367 void incShaderCompilations() { fShaderCompilations++; } | 367 void incShaderCompilations() { fShaderCompilations++; } |
368 int textureCreates() const { return fTextureCreates; } | 368 int textureCreates() const { return fTextureCreates; } |
369 void incTextureCreates() { fTextureCreates++; } | 369 void incTextureCreates() { fTextureCreates++; } |
370 int textureUploads() const { return fTextureUploads; } | 370 int textureUploads() const { return fTextureUploads; } |
371 void incTextureUploads() { fTextureUploads++; } | 371 void incTextureUploads() { fTextureUploads++; } |
372 void incStencilBufferCreates() { fStencilBufferCreates++; } | 372 void incStencilAttachmentCreates() { fStencilAttachmentCreates++; } |
373 void dump(SkString*); | 373 void dump(SkString*); |
374 | 374 |
375 private: | 375 private: |
376 int fRenderTargetBinds; | 376 int fRenderTargetBinds; |
377 int fShaderCompilations; | 377 int fShaderCompilations; |
378 int fTextureCreates; | 378 int fTextureCreates; |
379 int fTextureUploads; | 379 int fTextureUploads; |
380 int fStencilBufferCreates; | 380 int fStencilAttachmentCreates; |
381 #else | 381 #else |
382 void dump(SkString*) {}; | 382 void dump(SkString*) {}; |
383 void incRenderTargetBinds() {} | 383 void incRenderTargetBinds() {} |
384 void incShaderCompilations() {} | 384 void incShaderCompilations() {} |
385 void incTextureCreates() {} | 385 void incTextureCreates() {} |
386 void incTextureUploads() {} | 386 void incTextureUploads() {} |
387 void incStencilBufferCreates() {} | 387 void incStencilAttachmentCreates() {} |
388 #endif | 388 #endif |
389 }; | 389 }; |
390 | 390 |
391 Stats* stats() { return &fStats; } | 391 Stats* stats() { return &fStats; } |
392 | 392 |
393 /** | 393 /** |
394 * Called at start and end of gpu trace marking | 394 * Called at start and end of gpu trace marking |
395 * GR_CREATE_GPU_TRACE_MARKER(marker_str, target) will automatically call th
ese at the start | 395 * GR_CREATE_GPU_TRACE_MARKER(marker_str, target) will automatically call th
ese at the start |
396 * and end of a code block respectively | 396 * and end of a code block respectively |
397 */ | 397 */ |
398 void addGpuTraceMarker(const GrGpuTraceMarker* marker); | 398 void addGpuTraceMarker(const GrGpuTraceMarker* marker); |
399 void removeGpuTraceMarker(const GrGpuTraceMarker* marker); | 399 void removeGpuTraceMarker(const GrGpuTraceMarker* marker); |
400 | 400 |
401 /** | 401 /** |
402 * Takes the current active set of markers and stores them for later use. An
y current marker | 402 * Takes the current active set of markers and stores them for later use. An
y current marker |
403 * in the active set is removed from the active set and the targets remove f
unction is called. | 403 * in the active set is removed from the active set and the targets remove f
unction is called. |
404 * These functions do not work as a stack so you cannot call save a second t
ime before calling | 404 * These functions do not work as a stack so you cannot call save a second t
ime before calling |
405 * restore. Also, it is assumed that when restore is called the current acti
ve set of markers | 405 * restore. Also, it is assumed that when restore is called the current acti
ve set of markers |
406 * is empty. When the stored markers are added back into the active set, the
targets add marker | 406 * is empty. When the stored markers are added back into the active set, the
targets add marker |
407 * is called. | 407 * is called. |
408 */ | 408 */ |
409 void saveActiveTraceMarkers(); | 409 void saveActiveTraceMarkers(); |
410 void restoreActiveTraceMarkers(); | 410 void restoreActiveTraceMarkers(); |
411 | 411 |
412 // Given a rt, find or create a stencil buffer and attach it | 412 // Given a rt, find or create a stencil buffer and attach it |
413 bool attachStencilBufferToRenderTarget(GrRenderTarget* target); | 413 bool attachStencilAttachmentToRenderTarget(GrRenderTarget* target); |
414 | 414 |
415 protected: | 415 protected: |
416 // Functions used to map clip-respecting stencil tests into normal | 416 // Functions used to map clip-respecting stencil tests into normal |
417 // stencil funcs supported by GPUs. | 417 // stencil funcs supported by GPUs. |
418 static GrStencilFunc ConvertStencilFunc(bool stencilInClip, | 418 static GrStencilFunc ConvertStencilFunc(bool stencilInClip, |
419 GrStencilFunc func); | 419 GrStencilFunc func); |
420 static void ConvertStencilFuncAndMask(GrStencilFunc func, | 420 static void ConvertStencilFuncAndMask(GrStencilFunc func, |
421 bool clipInStencil, | 421 bool clipInStencil, |
422 unsigned int clipBit, | 422 unsigned int clipBit, |
423 unsigned int userBits, | 423 unsigned int userBits, |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 int left, int top, int width, int height, | 481 int left, int top, int width, int height, |
482 GrPixelConfig config, const void* buffer, | 482 GrPixelConfig config, const void* buffer, |
483 size_t rowBytes) = 0; | 483 size_t rowBytes) = 0; |
484 | 484 |
485 // overridden by backend-specific derived class to perform the resolve | 485 // overridden by backend-specific derived class to perform the resolve |
486 virtual void onResolveRenderTarget(GrRenderTarget* target) = 0; | 486 virtual void onResolveRenderTarget(GrRenderTarget* target) = 0; |
487 | 487 |
488 // width and height may be larger than rt (if underlying API allows it). | 488 // width and height may be larger than rt (if underlying API allows it). |
489 // Should attach the SB to the RT. Returns false if compatible sb could | 489 // Should attach the SB to the RT. Returns false if compatible sb could |
490 // not be created. | 490 // not be created. |
491 virtual bool createStencilBufferForRenderTarget(GrRenderTarget*, int width,
int height) = 0; | 491 virtual bool createStencilAttachmentForRenderTarget(GrRenderTarget*, int wid
th, int height) = 0; |
492 | 492 |
493 // attaches an existing SB to an existing RT. | 493 // attaches an existing SB to an existing RT. |
494 virtual bool attachStencilBufferToRenderTarget(GrStencilBuffer*, GrRenderTar
get*) = 0; | 494 virtual bool attachStencilAttachmentToRenderTarget(GrStencilAttachment*, GrR
enderTarget*) = 0; |
495 | 495 |
496 // clears target's entire stencil buffer to 0 | 496 // clears target's entire stencil buffer to 0 |
497 virtual void clearStencil(GrRenderTarget* target) = 0; | 497 virtual void clearStencil(GrRenderTarget* target) = 0; |
498 | 498 |
499 virtual void didAddGpuTraceMarker() = 0; | 499 virtual void didAddGpuTraceMarker() = 0; |
500 virtual void didRemoveGpuTraceMarker() = 0; | 500 virtual void didRemoveGpuTraceMarker() = 0; |
501 | 501 |
502 void resetContext() { | 502 void resetContext() { |
503 this->onResetContext(fResetBits); | 503 this->onResetContext(fResetBits); |
504 fResetBits = 0; | 504 fResetBits = 0; |
(...skipping 14 matching lines...) Expand all Loading... |
519 int fGpuTrac
eMarkerCount; | 519 int fGpuTrac
eMarkerCount; |
520 GrTraceMarkerSet fActiveT
raceMarkers; | 520 GrTraceMarkerSet fActiveT
raceMarkers; |
521 GrTraceMarkerSet fStoredT
raceMarkers; | 521 GrTraceMarkerSet fStoredT
raceMarkers; |
522 // The context owns us, not vice-versa, so this ptr is not ref'ed by Gpu. | 522 // The context owns us, not vice-versa, so this ptr is not ref'ed by Gpu. |
523 GrContext* fContext
; | 523 GrContext* fContext
; |
524 | 524 |
525 typedef SkRefCnt INHERITED; | 525 typedef SkRefCnt INHERITED; |
526 }; | 526 }; |
527 | 527 |
528 #endif | 528 #endif |
OLD | NEW |