1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/gpu/GrSWMaskHelper.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,107 @@ 1.4 +/* 1.5 + * Copyright 2012 Google Inc. 1.6 + * 1.7 + * Use of this source code is governed by a BSD-style license that can be 1.8 + * found in the LICENSE file. 1.9 + */ 1.10 + 1.11 +#ifndef GrSWMaskHelper_DEFINED 1.12 +#define GrSWMaskHelper_DEFINED 1.13 + 1.14 +#include "GrColor.h" 1.15 +#include "GrDrawState.h" 1.16 +#include "SkBitmap.h" 1.17 +#include "SkDraw.h" 1.18 +#include "SkMatrix.h" 1.19 +#include "SkRasterClip.h" 1.20 +#include "SkRegion.h" 1.21 +#include "SkTypes.h" 1.22 + 1.23 +class GrAutoScratchTexture; 1.24 +class GrContext; 1.25 +class GrTexture; 1.26 +class SkPath; 1.27 +class SkStrokeRec; 1.28 +class GrDrawTarget; 1.29 + 1.30 +/** 1.31 + * The GrSWMaskHelper helps generate clip masks using the software rendering 1.32 + * path. It is intended to be used as: 1.33 + * 1.34 + * GrSWMaskHelper helper(context); 1.35 + * helper.init(...); 1.36 + * 1.37 + * draw one or more paths/rects specifying the required boolean ops 1.38 + * 1.39 + * toTexture(); // to get it from the internal bitmap to the GPU 1.40 + * 1.41 + * The result of this process will be the final mask (on the GPU) in the 1.42 + * upper left hand corner of the texture. 1.43 + */ 1.44 +class GrSWMaskHelper : public SkNoncopyable { 1.45 +public: 1.46 + GrSWMaskHelper(GrContext* context) 1.47 + : fContext(context) { 1.48 + } 1.49 + 1.50 + // set up the internal state in preparation for draws. Since many masks 1.51 + // may be accumulated in the helper during creation, "resultBounds" 1.52 + // allows the caller to specify the region of interest - to limit the 1.53 + // amount of work. 1.54 + bool init(const SkIRect& resultBounds, const SkMatrix* matrix); 1.55 + 1.56 + // Draw a single rect into the accumulation bitmap using the specified op 1.57 + void draw(const SkRect& rect, SkRegion::Op op, 1.58 + bool antiAlias, uint8_t alpha); 1.59 + 1.60 + // Draw a single path into the accumuation bitmap using the specified op 1.61 + void draw(const SkPath& path, const SkStrokeRec& stroke, SkRegion::Op op, 1.62 + bool antiAlias, uint8_t alpha); 1.63 + 1.64 + // Helper function to get a scratch texture suitable for capturing the 1.65 + // result (i.e., right size & format) 1.66 + bool getTexture(GrAutoScratchTexture* texture); 1.67 + 1.68 + // Move the mask generation results from the internal bitmap to the gpu. 1.69 + void toTexture(GrTexture* texture); 1.70 + 1.71 + // Reset the internal bitmap 1.72 + void clear(uint8_t alpha) { 1.73 + fBM.eraseColor(SkColorSetARGB(alpha, alpha, alpha, alpha)); 1.74 + } 1.75 + 1.76 + // Canonical usage utility that draws a single path and uploads it 1.77 + // to the GPU. The result is returned in "result". 1.78 + static GrTexture* DrawPathMaskToTexture(GrContext* context, 1.79 + const SkPath& path, 1.80 + const SkStrokeRec& stroke, 1.81 + const SkIRect& resultBounds, 1.82 + bool antiAlias, 1.83 + SkMatrix* matrix); 1.84 + 1.85 + // This utility routine is used to add a path's mask to some other draw. 1.86 + // The ClipMaskManager uses it to accumulate clip masks while the 1.87 + // GrSoftwarePathRenderer uses it to fulfill a drawPath call. 1.88 + // It draws with "texture" as a path mask into "target" using "rect" as 1.89 + // geometry and the current drawState. The current drawState is altered to 1.90 + // accommodate the mask. 1.91 + // Note that this method assumes that the GrPaint::kTotalStages slot in 1.92 + // the draw state can be used to hold the mask texture stage. 1.93 + // This method is really only intended to be used with the 1.94 + // output of DrawPathMaskToTexture. 1.95 + static void DrawToTargetWithPathMask(GrTexture* texture, 1.96 + GrDrawTarget* target, 1.97 + const SkIRect& rect); 1.98 + 1.99 +protected: 1.100 +private: 1.101 + GrContext* fContext; 1.102 + SkMatrix fMatrix; 1.103 + SkBitmap fBM; 1.104 + SkDraw fDraw; 1.105 + SkRasterClip fRasterClip; 1.106 + 1.107 + typedef SkNoncopyable INHERITED; 1.108 +}; 1.109 + 1.110 +#endif // GrSWMaskHelper_DEFINED