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

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

Issue 749903003: some cleanup around GrGpu/GrDrawTarget copySurface (Closed) Base URL: https://skia.googlesource.com/skia.git@isSameAs
Patch Set: fix regression Created 6 years 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 | « no previous file | src/gpu/GrDrawTarget.cpp » ('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 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 void setClip(const GrClipData* clip); 61 void setClip(const GrClipData* clip);
62 62
63 /** 63 /**
64 * Gets the current clip. 64 * Gets the current clip.
65 * 65 *
66 * @return the clip. 66 * @return the clip.
67 */ 67 */
68 const GrClipData* getClip() const; 68 const GrClipData* getClip() const;
69 69
70 /** 70 /**
71 * There are three types of "sources" of geometry (vertices and indices) for 71 * There are two types of "sources" of geometry (vertices and indices) for
72 * draw calls made on the target. When performing an indexed draw, the 72 * draw calls made on the target. When performing an indexed draw, the
73 * indices and vertices can use different source types. Once a source is 73 * indices and vertices can use different source types. Once a source is
74 * specified it can be used for multiple draws. However, the time at which 74 * specified it can be used for multiple draws. However, the time at which
75 * the geometry data is no longer editable depends on the source type. 75 * the geometry data is no longer editable depends on the source type.
76 * 76 *
77 * Sometimes it is necessary to perform a draw while upstack code has 77 * Sometimes it is necessary to perform a draw while upstack code has
78 * already specified geometry that it isn't finished with. So there are push 78 * already specified geometry that it isn't finished with. So there are push
79 * and pop methods. This allows the client to push the sources, draw 79 * and pop methods. This allows the client to push the sources, draw
80 * something using alternate sources, and then pop to restore the original 80 * something using alternate sources, and then pop to restore the original
81 * sources. 81 * sources.
82 * 82 *
83 * Aside from pushes and pops, a source remains valid until another source 83 * Aside from pushes and pops, a source remains valid until another source
84 * is set or resetVertexSource / resetIndexSource is called. Drawing from 84 * is set or resetVertexSource / resetIndexSource is called. Drawing from
85 * a reset source is an error. 85 * a reset source is an error.
86 * 86 *
87 * The three types of sources are: 87 * The two types of sources are:
88 * 88 *
89 * 1. A cpu array (set*SourceToArray). This is useful when the caller 89 * 1. Reserve. This is most useful when the caller has data it must
90 * already provided vertex data in a format compatible with a
91 * GrVertexLayout. The data in the array is consumed at the time that
92 * set*SourceToArray is called and subsequent edits to the array will not
93 * be reflected in draws.
94 *
95 * 2. Reserve. This is most useful when the caller has data it must
96 * transform before drawing and is not long-lived. The caller requests 90 * transform before drawing and is not long-lived. The caller requests
97 * that the draw target make room for some amount of vertex and/or index 91 * that the draw target make room for some amount of vertex and/or index
98 * data. The target provides ptrs to hold the vertex and/or index data. 92 * data. The target provides ptrs to hold the vertex and/or index data.
99 * 93 *
100 * The data is writable up until the next drawIndexed, drawNonIndexed, 94 * The data is writable up until the next drawIndexed, drawNonIndexed,
101 * drawIndexedInstances, drawRect, copySurface, or pushGeometrySource. At 95 * drawIndexedInstances, drawRect, copySurface, or pushGeometrySource. At
102 * this point the data is frozen and the ptrs are no longer valid. 96 * this point the data is frozen and the ptrs are no longer valid.
103 * 97 *
104 * Where the space is allocated and how it is uploaded to the GPU is 98 * Where the space is allocated and how it is uploaded to the GPU is
105 * subclass-dependent. 99 * subclass-dependent.
106 * 100 *
107 * 3. Vertex and Index Buffers. This is most useful for geometry that will 101 * 2. Vertex and Index Buffers. This is most useful for geometry that will
108 * is long-lived. When the data in the buffer is consumed depends on the 102 * is long-lived. When the data in the buffer is consumed depends on the
109 * GrDrawTarget subclass. For deferred subclasses the caller has to 103 * GrDrawTarget subclass. For deferred subclasses the caller has to
110 * guarantee that the data is still available in the buffers at playback. 104 * guarantee that the data is still available in the buffers at playback.
111 * (TODO: Make this more automatic as we have done for read/write pixels) 105 * (TODO: Make this more automatic as we have done for read/write pixels)
112 *
113 * The size of each vertex is determined by querying the current GrDrawState .
114 */ 106 */
115 107
116 /** 108 /**
117 * Reserves space for vertices and/or indices. Zero can be specifed as 109 * Reserves space for vertices and/or indices. Zero can be specifed as
118 * either the vertex or index count if the caller desires to only reserve 110 * either the vertex or index count if the caller desires to only reserve
119 * space for only indices or only vertices. If zero is specifed for 111 * space for only indices or only vertices. If zero is specifed for
120 * vertexCount then the vertex source will be unmodified and likewise for 112 * vertexCount then the vertex source will be unmodified and likewise for
121 * indexCount. 113 * indexCount.
122 * 114 *
123 * If the function returns true then the reserve suceeded and the vertices 115 * If the function returns true then the reserve suceeded and the vertices
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 * Copies a pixel rectangle from one surface to another. This call may final ize 398 * Copies a pixel rectangle from one surface to another. This call may final ize
407 * reserved vertex/index data (as though a draw call was made). The src pixe ls 399 * reserved vertex/index data (as though a draw call was made). The src pixe ls
408 * copied are specified by srcRect. They are copied to a rect of the same 400 * copied are specified by srcRect. They are copied to a rect of the same
409 * size in dst with top left at dstPoint. If the src rect is clipped by the 401 * size in dst with top left at dstPoint. If the src rect is clipped by the
410 * src bounds then pixel values in the dst rect corresponding to area clipp ed 402 * src bounds then pixel values in the dst rect corresponding to area clipp ed
411 * by the src rect are not overwritten. This method can fail and return fals e 403 * by the src rect are not overwritten. This method can fail and return fals e
412 * depending on the type of surface, configs, etc, and the backend-specific 404 * depending on the type of surface, configs, etc, and the backend-specific
413 * limitations. If rect is clipped out entirely by the src or dst bounds the n 405 * limitations. If rect is clipped out entirely by the src or dst bounds the n
414 * true is returned since there is no actual copy necessary to succeed. 406 * true is returned since there is no actual copy necessary to succeed.
415 */ 407 */
416 virtual bool copySurface(GrSurface* dst, 408 bool copySurface(GrSurface* dst,
417 GrSurface* src, 409 GrSurface* src,
418 const SkIRect& srcRect, 410 const SkIRect& srcRect,
419 const SkIPoint& dstPoint); 411 const SkIPoint& dstPoint);
420 /** 412 /**
421 * Function that determines whether a copySurface call would succeed without 413 * Function that determines whether a copySurface call would succeed without actually
422 * performing the copy. 414 * performing the copy.
423 */ 415 */
424 virtual bool canCopySurface(const GrSurface* dst, 416 bool canCopySurface(const GrSurface* dst,
425 const GrSurface* src, 417 const GrSurface* src,
426 const SkIRect& srcRect, 418 const SkIRect& srcRect,
427 const SkIPoint& dstPoint); 419 const SkIPoint& dstPoint);
428
429 /**
430 * This is can be called before allocating a texture to be a dst for copySur face. It will
431 * populate the origin, config, and flags fields of the desc such that copyS urface is more
432 * likely to succeed and be efficient.
433 */
434 virtual void initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* des c);
435
436 420
437 /** 421 /**
438 * Release any resources that are cached but not currently in use. This 422 * Release any resources that are cached but not currently in use. This
439 * is intended to give an application some recourse when resources are low. 423 * is intended to give an application some recourse when resources are low.
440 */ 424 */
441 virtual void purgeResources() {}; 425 virtual void purgeResources() {};
442 426
443 //////////////////////////////////////////////////////////////////////////// 427 ////////////////////////////////////////////////////////////////////////////
444 428
445 class AutoReleaseGeometry : public ::SkNoncopyable { 429 class AutoReleaseGeometry : public ::SkNoncopyable {
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 const GrTraceMarkerSet& getActiveTraceMarkers() { return fActiveTraceMarkers ; } 647 const GrTraceMarkerSet& getActiveTraceMarkers() { return fActiveTraceMarkers ; }
664 648
665 // Makes a copy of the dst if it is necessary for the draw. Returns false if a copy is required 649 // Makes a copy of the dst if it is necessary for the draw. Returns false if a copy is required
666 // but couldn't be made. Otherwise, returns true. This method needs to be p rotected because it 650 // but couldn't be made. Otherwise, returns true. This method needs to be p rotected because it
667 // needs to be accessed by GLPrograms to setup a correct drawstate 651 // needs to be accessed by GLPrograms to setup a correct drawstate
668 bool setupDstReadIfNecessary(GrDrawState*, 652 bool setupDstReadIfNecessary(GrDrawState*,
669 GrDeviceCoordTexture* dstCopy, 653 GrDeviceCoordTexture* dstCopy,
670 const SkRect* drawBounds); 654 const SkRect* drawBounds);
671 655
672 private: 656 private:
657 /**
658 * This will be called before allocating a texture as a dst for copySurface. This function
659 * populates the dstDesc's config, flags, and origin so as to maximize effic iency and guarantee
660 * success of the copySurface call.
661 */
662 void initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* dstDesc) {
663 if (!this->onInitCopySurfaceDstDesc(src, dstDesc)) {
664 dstDesc->fOrigin = kDefault_GrSurfaceOrigin;
665 dstDesc->fFlags = kRenderTarget_GrSurfaceFlag | kNoStencil_GrSurface Flag;
666 dstDesc->fConfig = src->config();
667 }
668 }
669
670 /** Internal implementation of canCopySurface. */
671 bool internalCanCopySurface(const GrSurface* dst,
672 const GrSurface* src,
673 const SkIRect& clippedSrcRect,
674 const SkIPoint& clippedDstRect);
675
673 // A subclass can optionally overload this function to be notified before 676 // A subclass can optionally overload this function to be notified before
674 // vertex and index space is reserved. 677 // vertex and index space is reserved.
675 virtual void willReserveVertexAndIndexSpace(int vertexCount, 678 virtual void willReserveVertexAndIndexSpace(int vertexCount,
676 size_t vertexStride, 679 size_t vertexStride,
677 int indexCount) {} 680 int indexCount) {}
678 681
679 // implemented by subclass to allocate space for reserved geom 682 // implemented by subclass to allocate space for reserved geom
680 virtual bool onReserveVertexSpace(size_t vertexSize, int vertexCount, void** vertices) = 0; 683 virtual bool onReserveVertexSpace(size_t vertexSize, int vertexCount, void** vertices) = 0;
681 virtual bool onReserveIndexSpace(int indexCount, void** indices) = 0; 684 virtual bool onReserveIndexSpace(int indexCount, void** indices) = 0;
682 // implemented by subclass to handle release of reserved geom space 685 // implemented by subclass to handle release of reserved geom space
(...skipping 29 matching lines...) Expand all
712 const float transformValues[], 715 const float transformValues[],
713 PathTransformType, 716 PathTransformType,
714 int count, 717 int count,
715 const GrClipMaskManager::ScissorState&, 718 const GrClipMaskManager::ScissorState&,
716 const GrStencilSettings&, 719 const GrStencilSettings&,
717 const GrDeviceCoordTexture*) = 0; 720 const GrDeviceCoordTexture*) = 0;
718 721
719 virtual void onClear(const SkIRect* rect, GrColor color, bool canIgnoreRect, 722 virtual void onClear(const SkIRect* rect, GrColor color, bool canIgnoreRect,
720 GrRenderTarget* renderTarget) = 0; 723 GrRenderTarget* renderTarget) = 0;
721 724
725 /** The subclass will get a chance to copy the surface for falling back to t he default
726 implementation, which simply draws a rectangle (and fails if dst isn't a render target). It
727 should assume that any clipping has already been performed on the rect a nd point. It won't
728 be called if the copy can be skipped. */
729 virtual bool onCopySurface(GrSurface* dst,
730 GrSurface* src,
731 const SkIRect& srcRect,
732 const SkIPoint& dstPoint) = 0;
733
734 /** Indicates whether onCopySurface would succeed. It should assume that any clipping has
735 already been performed on the rect and point. It won't be called if the copy can be
736 skipped. */
737 virtual bool onCanCopySurface(const GrSurface* dst,
738 const GrSurface* src,
739 const SkIRect& srcRect,
740 const SkIPoint& dstPoint) = 0;
741 /**
742 * This will be called before allocating a texture to be a dst for onCopySur face. Only the
743 * dstDesc's config, flags, and origin need be set by the function. If the s ubclass cannot
744 * create a surface that would succeed its implementation of onCopySurface, it should return
745 * false. The base class will fall back to creating a render target to draw into using the src.
746 */
747 virtual bool onInitCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* d stDesc) = 0;
722 748
723 // helpers for reserving vertex and index space. 749 // helpers for reserving vertex and index space.
724 bool reserveVertexSpace(size_t vertexSize, 750 bool reserveVertexSpace(size_t vertexSize,
725 int vertexCount, 751 int vertexCount,
726 void** vertices); 752 void** vertices);
727 bool reserveIndexSpace(int indexCount, void** indices); 753 bool reserveIndexSpace(int indexCount, void** indices);
728 754
729 // called by drawIndexed and drawNonIndexed. Use a negative indexCount to 755 // called by drawIndexed and drawNonIndexed. Use a negative indexCount to
730 // indicate non-indexed drawing. 756 // indicate non-indexed drawing.
731 bool checkDraw(const GrDrawState&, 757 bool checkDraw(const GrDrawState&,
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 virtual bool setupClip(const SkRect* devBounds, 833 virtual bool setupClip(const SkRect* devBounds,
808 GrDrawState::AutoRestoreEffects* are, 834 GrDrawState::AutoRestoreEffects* are,
809 GrDrawState::AutoRestoreStencil* ars, 835 GrDrawState::AutoRestoreStencil* ars,
810 GrDrawState*, 836 GrDrawState*,
811 GrClipMaskManager::ScissorState* scissorState) SK_OVE RRIDE; 837 GrClipMaskManager::ScissorState* scissorState) SK_OVE RRIDE;
812 838
813 typedef GrDrawTarget INHERITED; 839 typedef GrDrawTarget INHERITED;
814 }; 840 };
815 841
816 #endif 842 #endif
OLDNEW
« no previous file with comments | « no previous file | src/gpu/GrDrawTarget.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698