| OLD | NEW | 
|    1 /* |    1 /* | 
|    2  * Copyright 2011 Google Inc. |    2  * Copyright 2011 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 GrGpuGL_DEFINED |    8 #ifndef GrGpuGL_DEFINED | 
|    9 #define GrGpuGL_DEFINED |    9 #define GrGpuGL_DEFINED | 
|   10  |   10  | 
|   11 #include "GrDrawState.h" |   11 #include "GrDrawState.h" | 
|   12 #include "GrGLContext.h" |   12 #include "GrGLContext.h" | 
|   13 #include "GrGLIRect.h" |   13 #include "GrGLIRect.h" | 
|   14 #include "GrGLIndexBuffer.h" |   14 #include "GrGLIndexBuffer.h" | 
 |   15 #include "GrGLPathRendering.h" | 
|   15 #include "GrGLProgram.h" |   16 #include "GrGLProgram.h" | 
|   16 #include "GrGLStencilBuffer.h" |   17 #include "GrGLStencilBuffer.h" | 
|   17 #include "GrGLTexture.h" |   18 #include "GrGLTexture.h" | 
|   18 #include "GrGLVertexArray.h" |   19 #include "GrGLVertexArray.h" | 
|   19 #include "GrGLVertexBuffer.h" |   20 #include "GrGLVertexBuffer.h" | 
|   20 #include "GrGpu.h" |   21 #include "GrGpu.h" | 
|   21 #include "SkTypes.h" |   22 #include "SkTypes.h" | 
|   22  |   23  | 
|   23 #ifdef SK_DEVELOPER |   24 #ifdef SK_DEVELOPER | 
|   24 #define PROGRAM_CACHE_STATS |   25 #define PROGRAM_CACHE_STATS | 
|   25 #endif |   26 #endif | 
|   26  |   27  | 
|   27 class GrGLPathRendering; |  | 
|   28  |  | 
|   29 class GrGpuGL : public GrGpu { |   28 class GrGpuGL : public GrGpu { | 
|   30 public: |   29 public: | 
|   31     GrGpuGL(const GrGLContext& ctx, GrContext* context); |   30     GrGpuGL(const GrGLContext& ctx, GrContext* context); | 
|   32     virtual ~GrGpuGL(); |   31     virtual ~GrGpuGL(); | 
|   33  |   32  | 
|   34     const GrGLContext& glContext() const { return fGLContext; } |   33     const GrGLContext& glContext() const { return fGLContext; } | 
|   35  |   34  | 
|   36     const GrGLInterface* glInterface() const { return fGLContext.interface(); } |   35     const GrGLInterface* glInterface() const { return fGLContext.interface(); } | 
|   37     const GrGLContextInfo& ctxInfo() const { return fGLContext; } |   36     const GrGLContextInfo& ctxInfo() const { return fGLContext; } | 
|   38     GrGLStandard glStandard() const { return fGLContext.standard(); } |   37     GrGLStandard glStandard() const { return fGLContext.standard(); } | 
|   39     GrGLVersion glVersion() const { return fGLContext.version(); } |   38     GrGLVersion glVersion() const { return fGLContext.version(); } | 
|   40     GrGLSLGeneration glslGeneration() const { return fGLContext.glslGeneration()
     ; } |   39     GrGLSLGeneration glslGeneration() const { return fGLContext.glslGeneration()
     ; } | 
|   41     const GrGLCaps& glCaps() const { return *fGLContext.caps(); } |   40     const GrGLCaps& glCaps() const { return *fGLContext.caps(); } | 
|   42  |   41  | 
|   43     GrGLPathRendering* pathRendering() const { |   42     GrGLPathRendering* glPathRendering() { | 
|   44         SkASSERT(glCaps().pathRenderingSupport()); |   43         SkASSERT(glCaps().pathRenderingSupport()); | 
|   45         return fPathRendering.get(); |   44         return static_cast<GrGLPathRendering*>(pathRendering()); | 
|   46     } |   45     } | 
|   47  |   46  | 
|   48     virtual void discard(GrRenderTarget*) SK_OVERRIDE; |   47     virtual void discard(GrRenderTarget*) SK_OVERRIDE; | 
|   49  |   48  | 
|   50     // Used by GrGLProgram and GrGLPathTexGenProgramEffects to configure OpenGL |   49     // Used by GrGLProgram and GrGLPathTexGenProgramEffects to configure OpenGL | 
|   51     // state. |   50     // state. | 
|   52     void bindTexture(int unitIdx, const GrTextureParams& params, GrGLTexture* te
     xture); |   51     void bindTexture(int unitIdx, const GrTextureParams& params, GrGLTexture* te
     xture); | 
|   53     void setProjectionMatrix(const SkMatrix& matrix, |   52  | 
|   54                              const SkISize& renderTargetSize, |  | 
|   55                              GrSurfaceOrigin renderTargetOrigin); |  | 
|   56     enum PathTexGenComponents { |  | 
|   57         kS_PathTexGenComponents = 1, |  | 
|   58         kST_PathTexGenComponents = 2, |  | 
|   59         kSTR_PathTexGenComponents = 3 |  | 
|   60     }; |  | 
|   61     void enablePathTexGen(int unitIdx, PathTexGenComponents, const GrGLfloat* co
     efficients); |  | 
|   62     void enablePathTexGen(int unitIdx, PathTexGenComponents, const SkMatrix& mat
     rix); |  | 
|   63     void flushPathTexGenSettings(int numUsedTexCoordSets); |  | 
|   64     bool shouldUseFixedFunctionTexturing() const { |   53     bool shouldUseFixedFunctionTexturing() const { | 
|   65         return this->glCaps().pathRenderingSupport(); |   54         return this->glCaps().pathRenderingSupport(); | 
|   66     } |   55     } | 
|   67  |   56  | 
|   68     bool programUnitTest(int maxStages); |   57     bool programUnitTest(int maxStages); | 
|   69  |   58  | 
|   70     // GrGpu overrides |   59     // GrGpu overrides | 
|   71     virtual GrPixelConfig preferredReadPixelsConfig(GrPixelConfig readConfig, |   60     virtual GrPixelConfig preferredReadPixelsConfig(GrPixelConfig readConfig, | 
|   72                                                     GrPixelConfig surfaceConfig)
      const SK_OVERRIDE; |   61                                                     GrPixelConfig surfaceConfig)
      const SK_OVERRIDE; | 
|   73     virtual GrPixelConfig preferredWritePixelsConfig(GrPixelConfig writeConfig, |   62     virtual GrPixelConfig preferredWritePixelsConfig(GrPixelConfig writeConfig, | 
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  124     // GrGpu overrides |  113     // GrGpu overrides | 
|  125     virtual void onResetContext(uint32_t resetBits) SK_OVERRIDE; |  114     virtual void onResetContext(uint32_t resetBits) SK_OVERRIDE; | 
|  126  |  115  | 
|  127     virtual GrTexture* onCreateTexture(const GrTextureDesc& desc, |  116     virtual GrTexture* onCreateTexture(const GrTextureDesc& desc, | 
|  128                                        const void* srcData, |  117                                        const void* srcData, | 
|  129                                        size_t rowBytes) SK_OVERRIDE; |  118                                        size_t rowBytes) SK_OVERRIDE; | 
|  130     virtual GrTexture* onCreateCompressedTexture(const GrTextureDesc& desc, |  119     virtual GrTexture* onCreateCompressedTexture(const GrTextureDesc& desc, | 
|  131                                                  const void* srcData) SK_OVERRID
     E; |  120                                                  const void* srcData) SK_OVERRID
     E; | 
|  132     virtual GrVertexBuffer* onCreateVertexBuffer(size_t size, bool dynamic) SK_O
     VERRIDE; |  121     virtual GrVertexBuffer* onCreateVertexBuffer(size_t size, bool dynamic) SK_O
     VERRIDE; | 
|  133     virtual GrIndexBuffer* onCreateIndexBuffer(size_t size, bool dynamic) SK_OVE
     RRIDE; |  122     virtual GrIndexBuffer* onCreateIndexBuffer(size_t size, bool dynamic) SK_OVE
     RRIDE; | 
|  134     virtual GrPath* onCreatePath(const SkPath&, const SkStrokeRec&) SK_OVERRIDE; |  | 
|  135     virtual GrPathRange* onCreatePathRange(size_t size, const SkStrokeRec&) SK_O
     VERRIDE; |  | 
|  136     virtual GrTexture* onWrapBackendTexture(const GrBackendTextureDesc&) SK_OVER
     RIDE; |  123     virtual GrTexture* onWrapBackendTexture(const GrBackendTextureDesc&) SK_OVER
     RIDE; | 
|  137     virtual GrRenderTarget* onWrapBackendRenderTarget(const GrBackendRenderTarge
     tDesc&) SK_OVERRIDE; |  124     virtual GrRenderTarget* onWrapBackendRenderTarget(const GrBackendRenderTarge
     tDesc&) SK_OVERRIDE; | 
|  138     virtual bool createStencilBufferForRenderTarget(GrRenderTarget* rt, |  125     virtual bool createStencilBufferForRenderTarget(GrRenderTarget* rt, | 
|  139                                                     int width, |  126                                                     int width, | 
|  140                                                     int height) SK_OVERRIDE; |  127                                                     int height) SK_OVERRIDE; | 
|  141     virtual bool attachStencilBufferToRenderTarget( |  128     virtual bool attachStencilBufferToRenderTarget( | 
|  142         GrStencilBuffer* sb, |  129         GrStencilBuffer* sb, | 
|  143         GrRenderTarget* rt) SK_OVERRIDE; |  130         GrRenderTarget* rt) SK_OVERRIDE; | 
|  144  |  131  | 
|  145     virtual void onClear(const SkIRect* rect, GrColor color, bool canIgnoreRect)
      SK_OVERRIDE; |  132     virtual void onClear(const SkIRect* rect, GrColor color, bool canIgnoreRect)
      SK_OVERRIDE; | 
|  146  |  133  | 
|  147     virtual bool onReadPixels(GrRenderTarget* target, |  134     virtual bool onReadPixels(GrRenderTarget* target, | 
|  148                               int left, int top, |  135                               int left, int top, | 
|  149                               int width, int height, |  136                               int width, int height, | 
|  150                               GrPixelConfig, |  137                               GrPixelConfig, | 
|  151                               void* buffer, |  138                               void* buffer, | 
|  152                               size_t rowBytes) SK_OVERRIDE; |  139                               size_t rowBytes) SK_OVERRIDE; | 
|  153  |  140  | 
|  154     virtual bool onWriteTexturePixels(GrTexture* texture, |  141     virtual bool onWriteTexturePixels(GrTexture* texture, | 
|  155                                       int left, int top, int width, int height, |  142                                       int left, int top, int width, int height, | 
|  156                                       GrPixelConfig config, const void* buffer, |  143                                       GrPixelConfig config, const void* buffer, | 
|  157                                       size_t rowBytes) SK_OVERRIDE; |  144                                       size_t rowBytes) SK_OVERRIDE; | 
|  158  |  145  | 
|  159     virtual void onResolveRenderTarget(GrRenderTarget* target) SK_OVERRIDE; |  146     virtual void onResolveRenderTarget(GrRenderTarget* target) SK_OVERRIDE; | 
|  160  |  147  | 
|  161     virtual void onGpuDraw(const DrawInfo&) SK_OVERRIDE; |  148     virtual void onGpuDraw(const DrawInfo&) SK_OVERRIDE; | 
|  162  |  149  | 
|  163     virtual void onGpuStencilPath(const GrPath*, SkPath::FillType) SK_OVERRIDE; |  | 
|  164     virtual void onGpuDrawPath(const GrPath*, SkPath::FillType) SK_OVERRIDE; |  | 
|  165     virtual void onGpuDrawPaths(const GrPathRange*, |  | 
|  166                                 const uint32_t indices[], int count, |  | 
|  167                                 const float transforms[], PathTransformType, |  | 
|  168                                 SkPath::FillType) SK_OVERRIDE; |  | 
|  169  |  150  | 
|  170     virtual void clearStencil() SK_OVERRIDE; |  151     virtual void clearStencil() SK_OVERRIDE; | 
|  171     virtual void clearStencilClip(const SkIRect& rect, |  152     virtual void clearStencilClip(const SkIRect& rect, | 
|  172                                   bool insideClip) SK_OVERRIDE; |  153                                   bool insideClip) SK_OVERRIDE; | 
|  173     virtual bool flushGraphicsState(DrawType, const GrDeviceCoordTexture* dstCop
     y) SK_OVERRIDE; |  154     virtual bool flushGraphicsState(DrawType, const GrDeviceCoordTexture* dstCop
     y) SK_OVERRIDE; | 
|  174  |  155  | 
|  175     // GrDrawTarget ovverides |  156     // GrDrawTarget ovverides | 
|  176     virtual void didAddGpuTraceMarker() SK_OVERRIDE; |  157     virtual void didAddGpuTraceMarker() SK_OVERRIDE; | 
|  177     virtual void didRemoveGpuTraceMarker() SK_OVERRIDE; |  158     virtual void didRemoveGpuTraceMarker() SK_OVERRIDE; | 
|  178  |  159  | 
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  250  |  231  | 
|  251     // sets a texture unit to use for texture operations other than binding a te
     xture to a program. |  232     // sets a texture unit to use for texture operations other than binding a te
     xture to a program. | 
|  252     // ensures that such operations don't negatively interact with tracking boun
     d textures. |  233     // ensures that such operations don't negatively interact with tracking boun
     d textures. | 
|  253     void setScratchTextureUnit(); |  234     void setScratchTextureUnit(); | 
|  254  |  235  | 
|  255     // bound is region that may be modified and therefore has to be resolved. |  236     // bound is region that may be modified and therefore has to be resolved. | 
|  256     // NULL means whole target. Can be an empty rect. |  237     // NULL means whole target. Can be an empty rect. | 
|  257     void flushRenderTarget(const SkIRect* bound); |  238     void flushRenderTarget(const SkIRect* bound); | 
|  258     void flushStencil(DrawType); |  239     void flushStencil(DrawType); | 
|  259     void flushAAState(DrawType); |  240     void flushAAState(DrawType); | 
|  260     void flushPathStencilSettings(SkPath::FillType fill); |  | 
|  261  |  241  | 
|  262     bool configToGLFormats(GrPixelConfig config, |  242     bool configToGLFormats(GrPixelConfig config, | 
|  263                            bool getSizedInternal, |  243                            bool getSizedInternal, | 
|  264                            GrGLenum* internalFormat, |  244                            GrGLenum* internalFormat, | 
|  265                            GrGLenum* externalFormat, |  245                            GrGLenum* externalFormat, | 
|  266                            GrGLenum* externalType); |  246                            GrGLenum* externalType); | 
|  267     // helper for onCreateTexture and writeTexturePixels |  247     // helper for onCreateTexture and writeTexturePixels | 
|  268     bool uploadTexData(const GrGLTexture::Desc& desc, |  248     bool uploadTexData(const GrGLTexture::Desc& desc, | 
|  269                        bool isNewTexture, |  249                        bool isNewTexture, | 
|  270                        int left, int top, int width, int height, |  250                        int left, int top, int width, int height, | 
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  438         void invalidate() { |  418         void invalidate() { | 
|  439             fSrcCoeff = kInvalid_GrBlendCoeff; |  419             fSrcCoeff = kInvalid_GrBlendCoeff; | 
|  440             fDstCoeff = kInvalid_GrBlendCoeff; |  420             fDstCoeff = kInvalid_GrBlendCoeff; | 
|  441             fConstColorValid = false; |  421             fConstColorValid = false; | 
|  442             fEnabled = kUnknown_TriState; |  422             fEnabled = kUnknown_TriState; | 
|  443         } |  423         } | 
|  444     } fHWBlendState; |  424     } fHWBlendState; | 
|  445  |  425  | 
|  446     TriState fMSAAEnabled; |  426     TriState fMSAAEnabled; | 
|  447  |  427  | 
|  448     GrGLProgram::MatrixState    fHWProjectionMatrixState; |  | 
|  449  |  | 
|  450     GrStencilSettings           fHWStencilSettings; |  428     GrStencilSettings           fHWStencilSettings; | 
|  451     TriState                    fHWStencilTestEnabled; |  429     TriState                    fHWStencilTestEnabled; | 
|  452     GrStencilSettings           fHWPathStencilSettings; |  430  | 
|  453  |  431  | 
|  454     GrDrawState::DrawFace       fHWDrawFace; |  432     GrDrawState::DrawFace       fHWDrawFace; | 
|  455     TriState                    fHWWriteToColor; |  433     TriState                    fHWWriteToColor; | 
|  456     TriState                    fHWDitherEnabled; |  434     TriState                    fHWDitherEnabled; | 
|  457     uint32_t                    fHWBoundRenderTargetUniqueID; |  435     uint32_t                    fHWBoundRenderTargetUniqueID; | 
|  458     SkTArray<uint32_t, true>    fHWBoundTextureUniqueIDs; |  436     SkTArray<uint32_t, true>    fHWBoundTextureUniqueIDs; | 
|  459  |  437  | 
|  460     struct PathTexGenData { |  | 
|  461         GrGLenum  fMode; |  | 
|  462         GrGLint   fNumComponents; |  | 
|  463         GrGLfloat fCoefficients[3 * 3]; |  | 
|  464     }; |  | 
|  465     int                         fHWActivePathTexGenSets; |  | 
|  466     SkTArray<PathTexGenData, true>  fHWPathTexGenSettings; |  | 
|  467     ///@} |  438     ///@} | 
|  468  |  439  | 
|  469     // we record what stencil format worked last time to hopefully exit early |  440     // we record what stencil format worked last time to hopefully exit early | 
|  470     // from our loop that tries stencil formats and calls check fb status. |  441     // from our loop that tries stencil formats and calls check fb status. | 
|  471     int fLastSuccessfulStencilFmtIdx; |  442     int fLastSuccessfulStencilFmtIdx; | 
|  472  |  443  | 
|  473     SkAutoTDelete<GrGLPathRendering> fPathRendering; |  | 
|  474  |  | 
|  475     typedef GrGpu INHERITED; |  444     typedef GrGpu INHERITED; | 
 |  445     friend class GrGLPathRendering; // For accessing setTextureUnit. | 
|  476 }; |  446 }; | 
|  477  |  447  | 
|  478 #endif |  448 #endif | 
| OLD | NEW |