Home | History | Annotate | Download | only in pdf
      1 
      2 /*
      3  * Copyright 2011 Google Inc.
      4  *
      5  * Use of this source code is governed by a BSD-style license that can be
      6  * found in the LICENSE file.
      7  */
      8 
      9 
     10 #ifndef SkPDFShader_DEFINED
     11 #define SkPDFShader_DEFINED
     12 
     13 #include "SkPDFStream.h"
     14 #include "SkPDFTypes.h"
     15 #include "SkMatrix.h"
     16 #include "SkRefCnt.h"
     17 #include "SkShader.h"
     18 
     19 class SkObjRef;
     20 class SkPDFCatalog;
     21 
     22 /** \class SkPDFShader
     23 
     24     In PDF parlance, this is a pattern, used in place of a color when the
     25     pattern color space is selected.
     26 */
     27 
     28 class SkPDFShader {
     29 public:
     30     /** Get the PDF shader for the passed SkShader. If the SkShader is
     31      *  invalid in some way, returns NULL. The reference count of
     32      *  the object is incremented and it is the caller's responsibility to
     33      *  unreference it when done.  This is needed to accommodate the weak
     34      *  reference pattern used when the returned object is new and has no
     35      *  other references.
     36      *  @param shader     The SkShader to emulate.
     37      *  @param matrix     The current transform. (PDF shaders are absolutely
     38      *                    positioned, relative to where the page is drawn.)
     39      *  @param surfceBBox The bounding box of the drawing surface (with matrix
     40      *                    already applied).
     41      */
     42     static SkPDFObject* GetPDFShader(const SkShader& shader,
     43                                      const SkMatrix& matrix,
     44                                      const SkIRect& surfaceBBox);
     45 
     46 protected:
     47     class State;
     48 
     49     class ShaderCanonicalEntry {
     50     public:
     51         ShaderCanonicalEntry(SkPDFObject* pdfShader, const State* state);
     52         bool operator==(const ShaderCanonicalEntry& b) const;
     53 
     54         SkPDFObject* fPDFShader;
     55         const State* fState;
     56     };
     57     // This should be made a hash table if performance is a problem.
     58     static SkTDArray<ShaderCanonicalEntry>& CanonicalShaders();
     59     static SkBaseMutex& CanonicalShadersMutex();
     60     static void RemoveShader(SkPDFObject* shader);
     61 
     62     SkPDFShader();
     63 };
     64 
     65 #endif
     66