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

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

Issue 763593002: Revert of some cleanup around GrGpu/GrDrawTarget copySurface (Closed) Base URL: https://skia.googlesource.com/skia.git@isSameAs
Patch Set: 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 two types of "sources" of geometry (vertices and indices) for 71 * There are three 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 two types of sources are: 87 * The three types of sources are:
88 * 88 *
89 * 1. Reserve. This is most useful when the caller has data it must 89 * 1. A cpu array (set*SourceToArray). This is useful when the caller
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
90 * transform before drawing and is not long-lived. The caller requests 96 * transform before drawing and is not long-lived. The caller requests
91 * that the draw target make room for some amount of vertex and/or index 97 * that the draw target make room for some amount of vertex and/or index
92 * data. The target provides ptrs to hold the vertex and/or index data. 98 * data. The target provides ptrs to hold the vertex and/or index data.
93 * 99 *
94 * The data is writable up until the next drawIndexed, drawNonIndexed, 100 * The data is writable up until the next drawIndexed, drawNonIndexed,
95 * drawIndexedInstances, drawRect, copySurface, or pushGeometrySource. At 101 * drawIndexedInstances, drawRect, copySurface, or pushGeometrySource. At
96 * this point the data is frozen and the ptrs are no longer valid. 102 * this point the data is frozen and the ptrs are no longer valid.
97 * 103 *
98 * Where the space is allocated and how it is uploaded to the GPU is 104 * Where the space is allocated and how it is uploaded to the GPU is
99 * subclass-dependent. 105 * subclass-dependent.
100 * 106 *
101 * 2. Vertex and Index Buffers. This is most useful for geometry that will 107 * 3. Vertex and Index Buffers. This is most useful for geometry that will
102 * is long-lived. When the data in the buffer is consumed depends on the 108 * is long-lived. When the data in the buffer is consumed depends on the
103 * GrDrawTarget subclass. For deferred subclasses the caller has to 109 * GrDrawTarget subclass. For deferred subclasses the caller has to
104 * guarantee that the data is still available in the buffers at playback. 110 * guarantee that the data is still available in the buffers at playback.
105 * (TODO: Make this more automatic as we have done for read/write pixels) 111 * (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 .
106 */ 114 */
107 115
108 /** 116 /**
109 * Reserves space for vertices and/or indices. Zero can be specifed as 117 * Reserves space for vertices and/or indices. Zero can be specifed as
110 * either the vertex or index count if the caller desires to only reserve 118 * either the vertex or index count if the caller desires to only reserve
111 * space for only indices or only vertices. If zero is specifed for 119 * space for only indices or only vertices. If zero is specifed for
112 * vertexCount then the vertex source will be unmodified and likewise for 120 * vertexCount then the vertex source will be unmodified and likewise for
113 * indexCount. 121 * indexCount.
114 * 122 *
115 * If the function returns true then the reserve suceeded and the vertices 123 * If the function returns true then the reserve suceeded and the vertices
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 * Copies a pixel rectangle from one surface to another. This call may final ize 406 * Copies a pixel rectangle from one surface to another. This call may final ize
399 * reserved vertex/index data (as though a draw call was made). The src pixe ls 407 * reserved vertex/index data (as though a draw call was made). The src pixe ls
400 * copied are specified by srcRect. They are copied to a rect of the same 408 * copied are specified by srcRect. They are copied to a rect of the same
401 * size in dst with top left at dstPoint. If the src rect is clipped by the 409 * size in dst with top left at dstPoint. If the src rect is clipped by the
402 * src bounds then pixel values in the dst rect corresponding to area clipp ed 410 * src bounds then pixel values in the dst rect corresponding to area clipp ed
403 * by the src rect are not overwritten. This method can fail and return fals e 411 * by the src rect are not overwritten. This method can fail and return fals e
404 * depending on the type of surface, configs, etc, and the backend-specific 412 * depending on the type of surface, configs, etc, and the backend-specific
405 * limitations. If rect is clipped out entirely by the src or dst bounds the n 413 * limitations. If rect is clipped out entirely by the src or dst bounds the n
406 * true is returned since there is no actual copy necessary to succeed. 414 * true is returned since there is no actual copy necessary to succeed.
407 */ 415 */
408 bool copySurface(GrSurface* dst, 416 virtual bool copySurface(GrSurface* dst,
409 GrSurface* src, 417 GrSurface* src,
410 const SkIRect& srcRect, 418 const SkIRect& srcRect,
411 const SkIPoint& dstPoint); 419 const SkIPoint& dstPoint);
412 /** 420 /**
413 * Function that determines whether a copySurface call would succeed without actually 421 * Function that determines whether a copySurface call would succeed without
414 * performing the copy. 422 * performing the copy.
415 */ 423 */
416 bool canCopySurface(const GrSurface* dst, 424 virtual bool canCopySurface(const GrSurface* dst,
417 const GrSurface* src, 425 const GrSurface* src,
418 const SkIRect& srcRect, 426 const SkIRect& srcRect,
419 const SkIPoint& dstPoint); 427 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
420 436
421 /** 437 /**
422 * Release any resources that are cached but not currently in use. This 438 * Release any resources that are cached but not currently in use. This
423 * is intended to give an application some recourse when resources are low. 439 * is intended to give an application some recourse when resources are low.
424 */ 440 */
425 virtual void purgeResources() {}; 441 virtual void purgeResources() {};
426 442
427 //////////////////////////////////////////////////////////////////////////// 443 ////////////////////////////////////////////////////////////////////////////
428 444
429 class AutoReleaseGeometry : public ::SkNoncopyable { 445 class AutoReleaseGeometry : public ::SkNoncopyable {
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 const GrTraceMarkerSet& getActiveTraceMarkers() { return fActiveTraceMarkers ; } 663 const GrTraceMarkerSet& getActiveTraceMarkers() { return fActiveTraceMarkers ; }
648 664
649 // Makes a copy of the dst if it is necessary for the draw. Returns false if a copy is required 665 // Makes a copy of the dst if it is necessary for the draw. Returns false if a copy is required
650 // but couldn't be made. Otherwise, returns true. This method needs to be p rotected because it 666 // but couldn't be made. Otherwise, returns true. This method needs to be p rotected because it
651 // needs to be accessed by GLPrograms to setup a correct drawstate 667 // needs to be accessed by GLPrograms to setup a correct drawstate
652 bool setupDstReadIfNecessary(GrDrawState*, 668 bool setupDstReadIfNecessary(GrDrawState*,
653 GrDeviceCoordTexture* dstCopy, 669 GrDeviceCoordTexture* dstCopy,
654 const SkRect* drawBounds); 670 const SkRect* drawBounds);
655 671
656 private: 672 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
676 // A subclass can optionally overload this function to be notified before 673 // A subclass can optionally overload this function to be notified before
677 // vertex and index space is reserved. 674 // vertex and index space is reserved.
678 virtual void willReserveVertexAndIndexSpace(int vertexCount, 675 virtual void willReserveVertexAndIndexSpace(int vertexCount,
679 size_t vertexStride, 676 size_t vertexStride,
680 int indexCount) {} 677 int indexCount) {}
681 678
682 // implemented by subclass to allocate space for reserved geom 679 // implemented by subclass to allocate space for reserved geom
683 virtual bool onReserveVertexSpace(size_t vertexSize, int vertexCount, void** vertices) = 0; 680 virtual bool onReserveVertexSpace(size_t vertexSize, int vertexCount, void** vertices) = 0;
684 virtual bool onReserveIndexSpace(int indexCount, void** indices) = 0; 681 virtual bool onReserveIndexSpace(int indexCount, void** indices) = 0;
685 // implemented by subclass to handle release of reserved geom space 682 // implemented by subclass to handle release of reserved geom space
(...skipping 29 matching lines...) Expand all
715 const float transformValues[], 712 const float transformValues[],
716 PathTransformType, 713 PathTransformType,
717 int count, 714 int count,
718 const GrClipMaskManager::ScissorState&, 715 const GrClipMaskManager::ScissorState&,
719 const GrStencilSettings&, 716 const GrStencilSettings&,
720 const GrDeviceCoordTexture*) = 0; 717 const GrDeviceCoordTexture*) = 0;
721 718
722 virtual void onClear(const SkIRect* rect, GrColor color, bool canIgnoreRect, 719 virtual void onClear(const SkIRect* rect, GrColor color, bool canIgnoreRect,
723 GrRenderTarget* renderTarget) = 0; 720 GrRenderTarget* renderTarget) = 0;
724 721
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;
748 722
749 // helpers for reserving vertex and index space. 723 // helpers for reserving vertex and index space.
750 bool reserveVertexSpace(size_t vertexSize, 724 bool reserveVertexSpace(size_t vertexSize,
751 int vertexCount, 725 int vertexCount,
752 void** vertices); 726 void** vertices);
753 bool reserveIndexSpace(int indexCount, void** indices); 727 bool reserveIndexSpace(int indexCount, void** indices);
754 728
755 // called by drawIndexed and drawNonIndexed. Use a negative indexCount to 729 // called by drawIndexed and drawNonIndexed. Use a negative indexCount to
756 // indicate non-indexed drawing. 730 // indicate non-indexed drawing.
757 bool checkDraw(const GrDrawState&, 731 bool checkDraw(const GrDrawState&,
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
833 virtual bool setupClip(const SkRect* devBounds, 807 virtual bool setupClip(const SkRect* devBounds,
834 GrDrawState::AutoRestoreEffects* are, 808 GrDrawState::AutoRestoreEffects* are,
835 GrDrawState::AutoRestoreStencil* ars, 809 GrDrawState::AutoRestoreStencil* ars,
836 GrDrawState*, 810 GrDrawState*,
837 GrClipMaskManager::ScissorState* scissorState) SK_OVE RRIDE; 811 GrClipMaskManager::ScissorState* scissorState) SK_OVE RRIDE;
838 812
839 typedef GrDrawTarget INHERITED; 813 typedef GrDrawTarget INHERITED;
840 }; 814 };
841 815
842 #endif 816 #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