Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/gpu/GrGpu.h

Issue 894013002: patch from issue 886233004 at patchset 40001 (http://crrev.com/886233004#ps40001) (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/GrContext.cpp ('k') | src/gpu/GrResourceCache2.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 GrStencilBuffer;
25 class GrVertexBufferAllocPool; 25 class GrVertexBufferAllocPool;
26 26
27 class GrGpu : public SkRefCnt { 27 class GrGpu : public SkRefCnt {
28 public: 28 public:
29
30 /** 29 /**
31 * Additional blend coefficients for dual source blending, not exposed 30 * Additional blend coefficients for dual source blending, not exposed
32 * through GrPaint/GrContext. 31 * through GrPaint/GrContext.
33 */ 32 */
34 enum ExtendedBlendCoeffs { 33 enum ExtendedBlendCoeffs {
35 // source 2 refers to second output color when 34 // source 2 refers to second output color when
36 // using dual source blending. 35 // using dual source blending.
37 kS2C_GrBlendCoeff = kPublicGrBlendCoeffCount, 36 kS2C_GrBlendCoeff = kPublicGrBlendCoeffCount,
38 kIS2C_GrBlendCoeff, 37 kIS2C_GrBlendCoeff,
39 kS2A_GrBlendCoeff, 38 kS2A_GrBlendCoeff,
(...skipping 15 matching lines...) Expand all
55 ~GrGpu() SK_OVERRIDE; 54 ~GrGpu() SK_OVERRIDE;
56 55
57 GrContext* getContext() { return fContext; } 56 GrContext* getContext() { return fContext; }
58 const GrContext* getContext() const { return fContext; } 57 const GrContext* getContext() const { return fContext; }
59 58
60 /** 59 /**
61 * Gets the capabilities of the draw target. 60 * Gets the capabilities of the draw target.
62 */ 61 */
63 const GrDrawTargetCaps* caps() const { return fCaps.get(); } 62 const GrDrawTargetCaps* caps() const { return fCaps.get(); }
64 63
65 GrPathRendering* pathRendering() { 64 GrPathRendering* pathRendering() { return fPathRendering.get(); }
66 return fPathRendering.get();
67 }
68 65
69 // Called by GrContext when the underlying backend context has been destroye d. 66 // Called by GrContext when the underlying backend context has been destroye d.
70 // GrGpu should use this to ensure that no backend API calls will be made fr om 67 // GrGpu should use this to ensure that no backend API calls will be made fr om
71 // here onward, including in its destructor. Subclasses should call 68 // here onward, including in its destructor. Subclasses should call
72 // INHERITED::contextAbandoned() if they override this. 69 // INHERITED::contextAbandoned() if they override this.
73 virtual void contextAbandoned(); 70 virtual void contextAbandoned();
74 71
75 /** 72 /**
76 * The GrGpu object normally assumes that no outsider is setting state 73 * The GrGpu object normally assumes that no outsider is setting state
77 * within the underlying 3D API's context/device/whatever. This call informs 74 * within the underlying 3D API's context/device/whatever. This call informs
78 * the GrGpu that the state was modified and it shouldn't make assumptions 75 * the GrGpu that the state was modified and it shouldn't make assumptions
79 * about the state. 76 * about the state.
80 */ 77 */
81 void markContextDirty(uint32_t state = kAll_GrBackendState) { 78 void markContextDirty(uint32_t state = kAll_GrBackendState) { fResetBits |= state; }
82 fResetBits |= state;
83 }
84
85 void unimpl(const char[]);
86 79
87 /** 80 /**
88 * Creates a texture object. If kRenderTarget_GrSurfaceFlag the texture can 81 * Creates a texture object. If kRenderTarget_GrSurfaceFlag the texture can
89 * be used as a render target by calling GrTexture::asRenderTarget(). Not al l 82 * be used as a render target by calling GrTexture::asRenderTarget(). Not al l
90 * pixel configs can be used as render targets. Support for configs as textu res 83 * pixel configs can be used as render targets. Support for configs as textu res
91 * or render targets can be checked using GrDrawTargetCaps. 84 * or render targets can be checked using GrDrawTargetCaps.
92 * 85 *
93 * @param desc describes the texture to be created. 86 * @param desc describes the texture to be created.
94 * @param budgeted does this texture count against the resource cache bud get? 87 * @param budgeted does this texture count against the resource cache bud get?
95 * @param srcData texel data to load texture. Begins with full-size 88 * @param srcData texel data to load texture. Begins with full-size
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 // a billion years. 288 // a billion years.
296 typedef uint64_t ResetTimestamp; 289 typedef uint64_t ResetTimestamp;
297 290
298 // This timestamp is always older than the current timestamp 291 // This timestamp is always older than the current timestamp
299 static const ResetTimestamp kExpiredTimestamp = 0; 292 static const ResetTimestamp kExpiredTimestamp = 0;
300 // Returns a timestamp based on the number of times the context was reset. 293 // Returns a timestamp based on the number of times the context was reset.
301 // This timestamp can be used to lazily detect when cached 3D context state 294 // This timestamp can be used to lazily detect when cached 3D context state
302 // is dirty. 295 // is dirty.
303 ResetTimestamp getResetTimestamp() const { return fResetTimestamp; } 296 ResetTimestamp getResetTimestamp() const { return fResetTimestamp; }
304 297
305 GrContext::GPUStats* gpuStats() { return &fGPUStats; }
306
307 virtual void buildProgramDesc(GrProgramDesc*, 298 virtual void buildProgramDesc(GrProgramDesc*,
308 const GrPrimitiveProcessor&, 299 const GrPrimitiveProcessor&,
309 const GrPipeline&, 300 const GrPipeline&,
310 const GrProgramDesc::DescInfo&, 301 const GrProgramDesc::DescInfo&,
311 const GrBatchTracker&) const = 0; 302 const GrBatchTracker&) const = 0;
312 303
313 /**
314 * Called at start and end of gpu trace marking
315 * GR_CREATE_GPU_TRACE_MARKER(marker_str, target) will automatically call th ese at the start
316 * and end of a code block respectively
317 */
318 void addGpuTraceMarker(const GrGpuTraceMarker* marker);
319 void removeGpuTraceMarker(const GrGpuTraceMarker* marker);
320
321 /**
322 * Takes the current active set of markers and stores them for later use. An y current marker
323 * in the active set is removed from the active set and the targets remove f unction is called.
324 * These functions do not work as a stack so you cannot call save a second t ime before calling
325 * restore. Also, it is assumed that when restore is called the current acti ve set of markers
326 * is empty. When the stored markers are added back into the active set, the targets add marker
327 * is called.
328 */
329 void saveActiveTraceMarkers();
330 void restoreActiveTraceMarkers();
331
332 // Called to determine whether a copySurface call would succeed or not. Deri ved 304 // Called to determine whether a copySurface call would succeed or not. Deri ved
333 // classes must keep this consistent with their implementation of onCopySurf ace(). Fallbacks 305 // classes must keep this consistent with their implementation of onCopySurf ace(). Fallbacks
334 // to issuing a draw from the src to dst take place at the GrDrawTarget leve l and this function 306 // to issuing a draw from the src to dst take place at the GrDrawTarget leve l and this function
335 // should only return true if a faster copy path exists. The rect and point are pre-clipped. The 307 // should only return true if a faster copy path exists. The rect and point are pre-clipped. The
336 // src rect and implied dst rect are guaranteed to be within the src/dst bou nds and non-empty. 308 // src rect and implied dst rect are guaranteed to be within the src/dst bou nds and non-empty.
337 virtual bool canCopySurface(const GrSurface* dst, 309 virtual bool canCopySurface(const GrSurface* dst,
338 const GrSurface* src, 310 const GrSurface* src,
339 const SkIRect& srcRect, 311 const SkIRect& srcRect,
340 const SkIPoint& dstPoint) = 0; 312 const SkIPoint& dstPoint) = 0;
341 313
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 void drawPath(const DrawArgs&, const GrPath*, const GrStencilSettings&); 354 void drawPath(const DrawArgs&, const GrPath*, const GrStencilSettings&);
383 void drawPaths(const DrawArgs&, 355 void drawPaths(const DrawArgs&,
384 const GrPathRange*, 356 const GrPathRange*,
385 const void* indices, 357 const void* indices,
386 GrDrawTarget::PathIndexType, 358 GrDrawTarget::PathIndexType,
387 const float transformValues[], 359 const float transformValues[],
388 GrDrawTarget::PathTransformType, 360 GrDrawTarget::PathTransformType,
389 int count, 361 int count,
390 const GrStencilSettings&); 362 const GrStencilSettings&);
391 363
364 ///////////////////////////////////////////////////////////////////////////
365 // Debugging and Stats
366
367 class Stats {
368 public:
369 #if GR_GPU_STATS
370 Stats() { this->reset(); }
371
372 void reset() { fRenderTargetBinds = 0; fShaderCompilations = 0; }
373
374 int renderTargetBinds() const { return fRenderTargetBinds; }
375 void incRenderTargetBinds() { fRenderTargetBinds++; }
376 int shaderCompilations() const { return fShaderCompilations; }
377 void incShaderCompilations() { fShaderCompilations++; }
378 void dump(SkString*);
379
380 private:
381 int fRenderTargetBinds;
382 int fShaderCompilations;
383 #else
384 void dump(SkString*) {};
385 void incRenderTargetBinds() {}
386 void incShaderCompilations() {}
387 #endif
388 };
389
390 Stats* stats() { return &fStats; }
391
392 /**
393 * Called at start and end of gpu trace marking
394 * GR_CREATE_GPU_TRACE_MARKER(marker_str, target) will automatically call th ese at the start
395 * and end of a code block respectively
396 */
397 void addGpuTraceMarker(const GrGpuTraceMarker* marker);
398 void removeGpuTraceMarker(const GrGpuTraceMarker* marker);
399
400 /**
401 * Takes the current active set of markers and stores them for later use. An y current marker
402 * in the active set is removed from the active set and the targets remove f unction is called.
403 * These functions do not work as a stack so you cannot call save a second t ime before calling
404 * restore. Also, it is assumed that when restore is called the current acti ve set of markers
405 * is empty. When the stored markers are added back into the active set, the targets add marker
406 * is called.
407 */
408 void saveActiveTraceMarkers();
409 void restoreActiveTraceMarkers();
410
392 protected: 411 protected:
393 // Functions used to map clip-respecting stencil tests into normal 412 // Functions used to map clip-respecting stencil tests into normal
394 // stencil funcs supported by GPUs. 413 // stencil funcs supported by GPUs.
395 static GrStencilFunc ConvertStencilFunc(bool stencilInClip, 414 static GrStencilFunc ConvertStencilFunc(bool stencilInClip,
396 GrStencilFunc func); 415 GrStencilFunc func);
397 static void ConvertStencilFuncAndMask(GrStencilFunc func, 416 static void ConvertStencilFuncAndMask(GrStencilFunc func,
398 bool clipInStencil, 417 bool clipInStencil,
399 unsigned int clipBit, 418 unsigned int clipBit,
400 unsigned int userBits, 419 unsigned int userBits,
401 unsigned int* ref, 420 unsigned int* ref,
402 unsigned int* mask); 421 unsigned int* mask);
403 422
404 const GrTraceMarkerSet& getActiveTraceMarkers() { return fActiveTraceMarkers ; } 423 const GrTraceMarkerSet& getActiveTraceMarkers() const { return fActiveTraceM arkers; }
405 424
406 GrContext::GPUStats fGPUStats; 425 Stats fStats;
407 426 SkAutoTDelete<GrPathRendering> fPathRendering;
408 SkAutoTDelete<GrPathRendering> fPathRendering;
409
410 // Subclass must initialize this in its constructor. 427 // Subclass must initialize this in its constructor.
411 SkAutoTUnref<const GrDrawTargetCaps> fCaps; 428 SkAutoTUnref<const GrDrawTargetCaps> fCaps;
412 429
413 private: 430 private:
414 // called when the 3D context state is unknown. Subclass should emit any 431 // called when the 3D context state is unknown. Subclass should emit any
415 // assumed 3D context state and dirty any state cache. 432 // assumed 3D context state and dirty any state cache.
416 virtual void onResetContext(uint32_t resetBits) = 0; 433 virtual void onResetContext(uint32_t resetBits) = 0;
417 434
418 // overridden by backend-specific derived class to create objects. 435 // overridden by backend-specific derived class to create objects.
419 virtual GrTexture* onCreateTexture(const GrSurfaceDesc& desc, bool budgeted, 436 virtual GrTexture* onCreateTexture(const GrSurfaceDesc& desc, bool budgeted,
420 const void* srcData, size_t rowBytes) = 0 ; 437 const void* srcData, size_t rowBytes) = 0 ;
421 virtual GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc, bool budgeted, 438 virtual GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc, bool budgeted,
422 const void* srcData) = 0; 439 const void* srcData) = 0;
423 virtual GrTexture* onWrapBackendTexture(const GrBackendTextureDesc&) = 0; 440 virtual GrTexture* onWrapBackendTexture(const GrBackendTextureDesc&) = 0;
424 virtual GrRenderTarget* onWrapBackendRenderTarget(const GrBackendRenderTarge tDesc&) = 0; 441 virtual GrRenderTarget* onWrapBackendRenderTarget(const GrBackendRenderTarge tDesc&) = 0;
425 virtual GrVertexBuffer* onCreateVertexBuffer(size_t size, bool dynamic) = 0; 442 virtual GrVertexBuffer* onCreateVertexBuffer(size_t size, bool dynamic) = 0;
426 virtual GrIndexBuffer* onCreateIndexBuffer(size_t size, bool dynamic) = 0; 443 virtual GrIndexBuffer* onCreateIndexBuffer(size_t size, bool dynamic) = 0;
427 444
428 // overridden by backend-specific derived class to perform the clear. 445 // overridden by backend-specific derived class to perform the clear.
429 virtual void onClear(GrRenderTarget*, const SkIRect* rect, GrColor color, 446 virtual void onClear(GrRenderTarget*, const SkIRect* rect, GrColor color,
430 bool canIgnoreRect) = 0; 447 bool canIgnoreRect) = 0;
431 448
432 449
433 // Overridden by backend specific classes to perform a clear of the stencil clip bits. This is 450 // Overridden by backend specific classes to perform a clear of the stencil clip bits. This is
434 // ONLY used by the the clip target 451 // ONLY used by the the clip target
435 virtual void onClearStencilClip(GrRenderTarget*, 452 virtual void onClearStencilClip(GrRenderTarget*, const SkIRect& rect, bool i nsideClip) = 0;
436 const SkIRect& rect,
437 bool insideClip) = 0;
438 453
439 // overridden by backend-specific derived class to perform the draw call. 454 // overridden by backend-specific derived class to perform the draw call.
440 virtual void onDraw(const DrawArgs&, const GrDrawTarget::DrawInfo&) = 0; 455 virtual void onDraw(const DrawArgs&, const GrDrawTarget::DrawInfo&) = 0;
441 virtual void onStencilPath(const GrPath*, const StencilPathState&) = 0; 456 virtual void onStencilPath(const GrPath*, const StencilPathState&) = 0;
442 457
443 virtual void onDrawPath(const DrawArgs&, const GrPath*, const GrStencilSetti ngs&) = 0; 458 virtual void onDrawPath(const DrawArgs&, const GrPath*, const GrStencilSetti ngs&) = 0;
444 virtual void onDrawPaths(const DrawArgs&, 459 virtual void onDrawPaths(const DrawArgs&,
445 const GrPathRange*, 460 const GrPathRange*,
446 const void* indices, 461 const void* indices,
447 GrDrawTarget::PathIndexType, 462 GrDrawTarget::PathIndexType,
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 int fGpuTrac eMarkerCount; 519 int fGpuTrac eMarkerCount;
505 GrTraceMarkerSet fActiveT raceMarkers; 520 GrTraceMarkerSet fActiveT raceMarkers;
506 GrTraceMarkerSet fStoredT raceMarkers; 521 GrTraceMarkerSet fStoredT raceMarkers;
507 // 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.
508 GrContext* fContext ; 523 GrContext* fContext ;
509 524
510 typedef SkRefCnt INHERITED; 525 typedef SkRefCnt INHERITED;
511 }; 526 };
512 527
513 #endif 528 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrContext.cpp ('k') | src/gpu/GrResourceCache2.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698