1 /* 2 * Copyright 2018 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef GrCCPerFlushResources_DEFINED 9 #define GrCCPerFlushResources_DEFINED 10 11 #include "src/gpu/GrNonAtomicRef.h" 12 #include "src/gpu/ccpr/GrCCAtlas.h" 13 14 class GrOnFlushResourceProvider; 15 16 /** 17 * This class wraps all the GPU resources that CCPR builds at flush time. It is allocated in CCPR's 18 * preFlush() method, and referenced by all the GrCCPerOpsTaskPaths objects that are being flushed. 19 * It is deleted in postFlush() once all the flushing GrCCPerOpsTaskPaths objects are deleted. 20 */ 21 class GrCCPerFlushResources : public GrNonAtomicRef<GrCCPerFlushResources> { 22 public: 23 GrCCPerFlushResources(GrOnFlushResourceProvider*, const GrCCAtlas::Specs&); 24 25 // Renders a path into an atlas. 26 // 27 // If the return value is non-null, it means the given path did not fit in the then-current 28 // atlas, so it was retired and a new one was added to the stack. The return value is the 29 // newly-retired atlas. (*NOT* the atlas the path was just drawn into.) The caller must call 30 // assignAtlasTexture on all GrCCClipPaths that will use the retired atlas. 31 std::unique_ptr<GrCCAtlas> renderDeviceSpacePathInAtlas( 32 GrOnFlushResourceProvider*, const SkIRect& clipIBounds, const SkPath& devPath, 33 const SkIRect& devPathIBounds, GrFillRule fillRule, SkIVector* devToAtlasOffset); 34 35 // Finishes off the GPU buffers and renders the atlas(es). 36 std::unique_ptr<GrCCAtlas> finalize(GrOnFlushResourceProvider*); 37 38 private: 39 // If the return value is non-null, it means the given path did not fit in the then-current 40 // atlas, so it was retired and a new one was added to the stack. The return value is the 41 // newly-retired atlas. (*NOT* the atlas the path was just drawn into.) The caller must call 42 // assignAtlasTexture on all GrCCClipPaths that will use the retired atlas. 43 std::unique_ptr<GrCCAtlas> placeRenderedPathInAtlas( 44 GrOnFlushResourceProvider*, const SkIRect& clippedPathIBounds, GrScissorTest, 45 SkIVector* devToAtlasOffset); 46 47 // Enqueues the given path to be rendered during the next call to flushRenderedPaths(). 48 void enqueueRenderedPath(const SkPath&, GrFillRule, const SkIRect& clippedDevIBounds, 49 const SkMatrix& pathToAtlasMatrix, GrScissorTest enableScissorInAtlas, 50 SkIVector devToAtlasOffset); 51 52 // Renders all enqueued paths into the given atlas and clears our path queue. 53 void flushRenderedPaths(GrOnFlushResourceProvider*); 54 55 const GrCCAtlas::Specs fAtlasSpecs; 56 57 // Paths to be rendered in the atlas we are currently building. 58 struct AtlasPaths { 59 SkPath fUberPath; // Contains all contours from all non-scissored paths. 60 SkSTArray<32, std::tuple<SkPath, SkIRect>> fScissoredPaths; 61 }; 62 static_assert((int)GrFillRule::kNonzero == 0); 63 static_assert((int)GrFillRule::kEvenOdd == 1); 64 AtlasPaths fAtlasPaths[2]; // One for "nonzero" fill rule and one for "even-odd". 65 66 std::unique_ptr<GrCCAtlas> fAtlas; 67 }; 68 69 #endif 70