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

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

Issue 947443003: Move clip off of draw target (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: cleanup Created 5 years, 9 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
OLDNEW
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
11 #include "GrClipData.h" 11 #include "GrClip.h"
12 #include "GrClipMaskManager.h" 12 #include "GrClipMaskManager.h"
13 #include "GrContext.h" 13 #include "GrContext.h"
14 #include "GrPathProcessor.h" 14 #include "GrPathProcessor.h"
15 #include "GrPrimitiveProcessor.h" 15 #include "GrPrimitiveProcessor.h"
16 #include "GrIndexBuffer.h" 16 #include "GrIndexBuffer.h"
17 #include "GrPathRendering.h" 17 #include "GrPathRendering.h"
18 #include "GrPipelineBuilder.h" 18 #include "GrPipelineBuilder.h"
19 #include "GrTraceMarker.h" 19 #include "GrTraceMarker.h"
20 #include "GrVertexBuffer.h" 20 #include "GrVertexBuffer.h"
21 21
22 #include "SkClipStack.h" 22 #include "SkClipStack.h"
23 #include "SkMatrix.h" 23 #include "SkMatrix.h"
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 GrClipData; 32 class GrClip;
33 class GrDrawTargetCaps; 33 class GrDrawTargetCaps;
34 class GrPath; 34 class GrPath;
35 class GrPathRange; 35 class GrPathRange;
36 class GrPipeline; 36 class GrPipeline;
37 37
38 class GrDrawTarget : public SkRefCnt { 38 class GrDrawTarget : public SkRefCnt {
39 public: 39 public:
40 SK_DECLARE_INST_COUNT(GrDrawTarget) 40 SK_DECLARE_INST_COUNT(GrDrawTarget)
41 41
42 typedef GrPathRange::PathIndexType PathIndexType; 42 typedef GrPathRange::PathIndexType PathIndexType;
43 typedef GrPathRendering::PathTransformType PathTransformType; 43 typedef GrPathRendering::PathTransformType PathTransformType;
44 44
45 /////////////////////////////////////////////////////////////////////////// 45 ///////////////////////////////////////////////////////////////////////////
46 46
47 // The context may not be fully constructed and should not be used during Gr DrawTarget 47 // The context may not be fully constructed and should not be used during Gr DrawTarget
48 // construction. 48 // construction.
49 GrDrawTarget(GrContext* context); 49 GrDrawTarget(GrContext* context);
50 virtual ~GrDrawTarget(); 50 virtual ~GrDrawTarget();
51 51
52 /** 52 /**
53 * Gets the capabilities of the draw target. 53 * Gets the capabilities of the draw target.
54 */ 54 */
55 const GrDrawTargetCaps* caps() const { return fCaps.get(); } 55 const GrDrawTargetCaps* caps() const { return fCaps.get(); }
56 56
57 /** 57 /**
58 * Sets the current clip to the region specified by clip. All draws will be
59 * clipped against this clip if kClip_StateBit is enabled.
60 *
61 * Setting the clip may (or may not) zero out the client's stencil bits.
62 *
63 * @param description of the clipping region
64 */
65 void setClip(const GrClipData* clip);
66
67 /**
68 * Gets the current clip.
69 *
70 * @return the clip.
71 */
72 const GrClipData* getClip() const;
73
74 /**
75 * There are two types of "sources" of geometry (vertices and indices) for 58 * There are two types of "sources" of geometry (vertices and indices) for
76 * draw calls made on the target. When performing an indexed draw, the 59 * draw calls made on the target. When performing an indexed draw, the
77 * indices and vertices can use different source types. Once a source is 60 * indices and vertices can use different source types. Once a source is
78 * specified it can be used for multiple draws. However, the time at which 61 * specified it can be used for multiple draws. However, the time at which
79 * the geometry data is no longer editable depends on the source type. 62 * the geometry data is no longer editable depends on the source type.
80 * 63 *
81 * Sometimes it is necessary to perform a draw while upstack code has 64 * Sometimes it is necessary to perform a draw while upstack code has
82 * already specified geometry that it isn't finished with. So there are push 65 * already specified geometry that it isn't finished with. So there are push
83 * and pop methods. This allows the client to push the sources, draw 66 * and pop methods. This allows the client to push the sources, draw
84 * something using alternate sources, and then pop to restore the original 67 * something using alternate sources, and then pop to restore the original
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 * not a request for clipping. 240 * not a request for clipping.
258 */ 241 */
259 void drawNonIndexed(GrPipelineBuilder*, 242 void drawNonIndexed(GrPipelineBuilder*,
260 const GrGeometryProcessor*, 243 const GrGeometryProcessor*,
261 GrPrimitiveType type, 244 GrPrimitiveType type,
262 int startVertex, 245 int startVertex,
263 int vertexCount, 246 int vertexCount,
264 const SkRect* devBounds = NULL); 247 const SkRect* devBounds = NULL);
265 248
266 // TODO devbounds should live on the batch 249 // TODO devbounds should live on the batch
267 void drawBatch(GrPipelineBuilder*, 250 void drawBatch(GrPipelineBuilder*, GrBatch*, const SkRect* devBounds = NULL) ;
268 GrBatch*,
269 const SkRect* devBounds = NULL);
270 251
271 /** 252 /**
272 * Draws path into the stencil buffer. The fill must be either even/odd or 253 * Draws path into the stencil buffer. The fill must be either even/odd or
273 * winding (not inverse or hairline). It will respect the HW antialias flag 254 * winding (not inverse or hairline). It will respect the HW antialias flag
274 * on the GrPipelineBuilder (if possible in the 3D API). Note, we will neve r have an inverse 255 * on the GrPipelineBuilder (if possible in the 3D API). Note, we will neve r have an inverse
275 * fill with stencil path 256 * fill with stencil path
276 */ 257 */
277 void stencilPath(GrPipelineBuilder*, const GrPathProcessor*, const GrPath*, 258 void stencilPath(GrPipelineBuilder*,
259 const GrPathProcessor*,
260 const GrPath*,
278 GrPathRendering::FillType); 261 GrPathRendering::FillType);
279 262
280 /** 263 /**
281 * Draws a path. Fill must not be a hairline. It will respect the HW 264 * Draws a path. Fill must not be a hairline. It will respect the HW
282 * antialias flag on the GrPipelineBuilder (if possible in the 3D API). 265 * antialias flag on the GrPipelineBuilder (if possible in the 3D API).
283 */ 266 */
284 void drawPath(GrPipelineBuilder*, const GrPathProcessor*, const GrPath*, 267 void drawPath(GrPipelineBuilder*,
268 const GrPathProcessor*,
269 const GrPath*,
285 GrPathRendering::FillType); 270 GrPathRendering::FillType);
286 271
287 /** 272 /**
288 * Draws the aggregate path from combining multiple. Note that this will not 273 * Draws the aggregate path from combining multiple. Note that this will not
289 * always be equivalent to back-to-back calls to drawPath(). It will respect 274 * always be equivalent to back-to-back calls to drawPath(). It will respect
290 * the HW antialias flag on the GrPipelineBuilder (if possible in the 3D API ). 275 * the HW antialias flag on the GrPipelineBuilder (if possible in the 3D API ).
291 * 276 *
292 * @param pathRange Source paths to draw from 277 * @param pathRange Source paths to draw from
293 * @param indices Array of path indices to draw 278 * @param indices Array of path indices to draw
294 * @param indexType Data type of the array elements in indexBuffer 279 * @param indexType Data type of the array elements in indexBuffer
(...skipping 30 matching lines...) Expand all
325 const SkRect& rect, 310 const SkRect& rect,
326 const SkRect* localRect, 311 const SkRect* localRect,
327 const SkMatrix* localMatrix) { 312 const SkMatrix* localMatrix) {
328 AutoGeometryPush agp(this); 313 AutoGeometryPush agp(this);
329 this->onDrawRect(pipelineBuilder, color, viewMatrix, rect, localRect, lo calMatrix); 314 this->onDrawRect(pipelineBuilder, color, viewMatrix, rect, localRect, lo calMatrix);
330 } 315 }
331 316
332 /** 317 /**
333 * Helper for drawRect when the caller doesn't need separate local rects or matrices. 318 * Helper for drawRect when the caller doesn't need separate local rects or matrices.
334 */ 319 */
335 void drawSimpleRect(GrPipelineBuilder* ds, GrColor color, const SkMatrix& vi ewM, 320 void drawSimpleRect(GrPipelineBuilder* ds,
321 GrColor color,
322 const SkMatrix& viewM,
336 const SkRect& rect) { 323 const SkRect& rect) {
337 this->drawRect(ds, color, viewM, rect, NULL, NULL); 324 this->drawRect(ds, color, viewM, rect, NULL, NULL);
338 } 325 }
339 void drawSimpleRect(GrPipelineBuilder* ds, GrColor color, const SkMatrix& vi ewM, 326 void drawSimpleRect(GrPipelineBuilder* ds,
bsalomon 2015/02/23 19:31:29 A lot of the lines in this change are just wrappin
327 GrColor color,
328 const SkMatrix& viewM,
340 const SkIRect& irect) { 329 const SkIRect& irect) {
341 SkRect rect = SkRect::Make(irect); 330 SkRect rect = SkRect::Make(irect);
342 this->drawRect(ds, color, viewM, rect, NULL, NULL); 331 this->drawRect(ds, color, viewM, rect, NULL, NULL);
343 } 332 }
344 333
345 /** 334 /**
346 * This call is used to draw multiple instances of some geometry with a 335 * This call is used to draw multiple instances of some geometry with a
347 * given number of vertices (V) and indices (I) per-instance. The indices in 336 * given number of vertices (V) and indices (I) per-instance. The indices in
348 * the index source must have the form i[k+I] == i[k] + V. Also, all indices 337 * the index source must have the form i[k+I] == i[k] + V. Also, all indices
349 * i[kI] ... i[(k+1)I-1] must be elements of the range kV ... (k+1)V-1. As a 338 * i[kI] ... i[(k+1)I-1] must be elements of the range kV ... (k+1)V-1. As a
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 private: 457 private:
469 void reset(); 458 void reset();
470 459
471 GrDrawTarget* fTarget; 460 GrDrawTarget* fTarget;
472 void* fVertices; 461 void* fVertices;
473 void* fIndices; 462 void* fIndices;
474 }; 463 };
475 464
476 //////////////////////////////////////////////////////////////////////////// 465 ////////////////////////////////////////////////////////////////////////////
477 466
478 class AutoClipRestore : public ::SkNoncopyable {
479 public:
480 AutoClipRestore(GrDrawTarget* target) {
481 fTarget = target;
482 fClip = fTarget->getClip();
483 }
484
485 AutoClipRestore(GrDrawTarget* target, const SkIRect& newClip);
486
487 ~AutoClipRestore() {
488 fTarget->setClip(fClip);
489 }
490 private:
491 GrDrawTarget* fTarget;
492 const GrClipData* fClip;
493 SkTLazy<SkClipStack> fStack;
494 GrClipData fReplacementClip;
495 };
496
497 ////////////////////////////////////////////////////////////////////////////
498
499 /** 467 /**
500 * Saves the geometry src state at construction and restores in the destruct or. It also saves 468 * Saves the geometry src state at construction and restores in the destruct or. It also saves
501 * and then restores the vertex attrib state. 469 * and then restores the vertex attrib state.
502 */ 470 */
503 class AutoGeometryPush : public ::SkNoncopyable { 471 class AutoGeometryPush : public ::SkNoncopyable {
504 public: 472 public:
505 AutoGeometryPush(GrDrawTarget* target) { 473 AutoGeometryPush(GrDrawTarget* target) {
506 SkASSERT(target); 474 SkASSERT(target);
507 fTarget = target; 475 fTarget = target;
508 target->pushGeometrySource(); 476 target->pushGeometrySource();
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 // but couldn't be made. Otherwise, returns true. This method needs to be p rotected because it 649 // but couldn't be made. Otherwise, returns true. This method needs to be p rotected because it
682 // needs to be accessed by GLPrograms to setup a correct drawstate 650 // needs to be accessed by GLPrograms to setup a correct drawstate
683 bool setupDstReadIfNecessary(const GrPipelineBuilder&, 651 bool setupDstReadIfNecessary(const GrPipelineBuilder&,
684 const GrProcOptInfo& colorPOI, 652 const GrProcOptInfo& colorPOI,
685 const GrProcOptInfo& coveragePOI, 653 const GrProcOptInfo& coveragePOI,
686 GrDeviceCoordTexture* dstCopy, 654 GrDeviceCoordTexture* dstCopy,
687 const SkRect* drawBounds); 655 const SkRect* drawBounds);
688 656
689 struct PipelineInfo { 657 struct PipelineInfo {
690 PipelineInfo(GrPipelineBuilder* pipelineBuilder, GrScissorState* scissor , 658 PipelineInfo(GrPipelineBuilder* pipelineBuilder, GrScissorState* scissor ,
691 const GrPrimitiveProcessor* primProc, const SkRect* devBoun ds, 659 const GrPrimitiveProcessor* primProc,
692 GrDrawTarget* target); 660 const SkRect* devBounds, GrDrawTarget* target);
693 661
694 PipelineInfo(GrPipelineBuilder* pipelineBuilder, GrScissorState* scissor , 662 PipelineInfo(GrPipelineBuilder* pipelineBuilder, GrScissorState* scissor ,
695 const GrBatch* batch, const SkRect* devBounds, GrDrawTarget * target); 663 const GrBatch* batch, const SkRect* devBounds,
664 GrDrawTarget* target);
696 665
697 bool willBlendWithDst(const GrPrimitiveProcessor* primProc) const { 666 bool willBlendWithDst(const GrPrimitiveProcessor* primProc) const {
698 return fPipelineBuilder->willBlendWithDst(primProc); 667 return fPipelineBuilder->willBlendWithDst(primProc);
699 } 668 }
700 private: 669 private:
701 friend class GrDrawTarget; 670 friend class GrDrawTarget;
702 671
703 bool mustSkipDraw() const { return (NULL == fPipelineBuilder); } 672 bool mustSkipDraw() const { return (NULL == fPipelineBuilder); }
704 673
705 GrPipelineBuilder* fPipelineBuilder; 674 GrPipelineBuilder* fPipelineBuilder;
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
831 virtual bool setupClip(GrPipelineBuilder*, 800 virtual bool setupClip(GrPipelineBuilder*,
832 GrPipelineBuilder::AutoRestoreEffects* are, 801 GrPipelineBuilder::AutoRestoreEffects* are,
833 GrPipelineBuilder::AutoRestoreStencil* ars, 802 GrPipelineBuilder::AutoRestoreStencil* ars,
834 GrScissorState* scissorState, 803 GrScissorState* scissorState,
835 const SkRect* devBounds) = 0; 804 const SkRect* devBounds) = 0;
836 805
837 enum { 806 enum {
838 kPreallocGeoSrcStateStackCnt = 4, 807 kPreallocGeoSrcStateStackCnt = 4,
839 }; 808 };
840 SkSTArray<kPreallocGeoSrcStateStackCnt, GeometrySrcState, true> fGeoSrcState Stack; 809 SkSTArray<kPreallocGeoSrcStateStackCnt, GeometrySrcState, true> fGeoSrcState Stack;
841 const GrClipData* fClip;
842 // The context owns us, not vice-versa, so this ptr is not ref'ed by DrawTar get. 810 // The context owns us, not vice-versa, so this ptr is not ref'ed by DrawTar get.
843 GrContext* fContext; 811 GrContext* fContext;
844 // To keep track that we always have at least as many debug marker adds as r emoves 812 // To keep track that we always have at least as many debug marker adds as r emoves
845 int fGpuTraceMar kerCount; 813 int fGpuTraceMar kerCount;
846 GrTraceMarkerSet fActiveTrace Markers; 814 GrTraceMarkerSet fActiveTrace Markers;
847 GrTraceMarkerSet fStoredTrace Markers; 815 GrTraceMarkerSet fStoredTrace Markers;
848 816
849 typedef SkRefCnt INHERITED; 817 typedef SkRefCnt INHERITED;
850 }; 818 };
851 819
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 virtual bool setupClip(GrPipelineBuilder*, 859 virtual bool setupClip(GrPipelineBuilder*,
892 GrPipelineBuilder::AutoRestoreEffects* are, 860 GrPipelineBuilder::AutoRestoreEffects* are,
893 GrPipelineBuilder::AutoRestoreStencil* ars, 861 GrPipelineBuilder::AutoRestoreStencil* ars,
894 GrScissorState* scissorState, 862 GrScissorState* scissorState,
895 const SkRect* devBounds) SK_OVERRIDE; 863 const SkRect* devBounds) SK_OVERRIDE;
896 864
897 typedef GrDrawTarget INHERITED; 865 typedef GrDrawTarget INHERITED;
898 }; 866 };
899 867
900 #endif 868 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698