Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / skia / src / gpu / gl / GrGpuGL.h
index 1a3f1a2..65816b5 100644 (file)
@@ -8,18 +8,17 @@
 #ifndef GrGpuGL_DEFINED
 #define GrGpuGL_DEFINED
 
-#include "GrBinHashKey.h"
 #include "GrDrawState.h"
 #include "GrGLContext.h"
 #include "GrGLIRect.h"
 #include "GrGLIndexBuffer.h"
+#include "GrGLPathRendering.h"
 #include "GrGLProgram.h"
 #include "GrGLStencilBuffer.h"
 #include "GrGLTexture.h"
 #include "GrGLVertexArray.h"
 #include "GrGLVertexBuffer.h"
 #include "GrGpu.h"
-#include "GrTHashTable.h"
 #include "SkTypes.h"
 
 #ifdef SK_DEVELOPER
@@ -31,31 +30,27 @@ public:
     GrGpuGL(const GrGLContext& ctx, GrContext* context);
     virtual ~GrGpuGL();
 
+    virtual void contextAbandoned() SK_OVERRIDE;
+
     const GrGLContext& glContext() const { return fGLContext; }
 
     const GrGLInterface* glInterface() const { return fGLContext.interface(); }
-    const GrGLContextInfo& ctxInfo() const { return fGLContext.info(); }
-    GrGLBinding glBinding() const { return fGLContext.info().binding(); }
-    GrGLVersion glVersion() const { return fGLContext.info().version(); }
-    GrGLSLGeneration glslGeneration() const { return fGLContext.info().glslGeneration(); }
+    const GrGLContextInfo& ctxInfo() const { return fGLContext; }
+    GrGLStandard glStandard() const { return fGLContext.standard(); }
+    GrGLVersion glVersion() const { return fGLContext.version(); }
+    GrGLSLGeneration glslGeneration() const { return fGLContext.glslGeneration(); }
+    const GrGLCaps& glCaps() const { return *fGLContext.caps(); }
+
+    GrGLPathRendering* glPathRendering() {
+        SkASSERT(glCaps().pathRenderingSupport());
+        return static_cast<GrGLPathRendering*>(pathRendering());
+    }
+
+    virtual void discard(GrRenderTarget*) SK_OVERRIDE;
 
-    // Used by GrGLProgram and GrGLTexGenProgramEffects to configure OpenGL state.
+    // Used by GrGLProgram and GrGLPathTexGenProgramEffects to configure OpenGL
+    // state.
     void bindTexture(int unitIdx, const GrTextureParams& params, GrGLTexture* texture);
-    void setProjectionMatrix(const SkMatrix& matrix,
-                             const SkISize& renderTargetSize,
-                             GrSurfaceOrigin renderTargetOrigin);
-    enum TexGenComponents {
-        kS_TexGenComponents = 1,
-        kST_TexGenComponents = 2,
-        kSTR_TexGenComponents = 3
-    };
-    void enableTexGen(int unitIdx, TexGenComponents, const GrGLfloat* coefficients);
-    void enableTexGen(int unitIdx, TexGenComponents, const SkMatrix& matrix);
-    void flushTexGenSettings(int numUsedTexCoordSets);
-    bool shouldUseFixedFunctionTexturing() const {
-        return this->glCaps().fixedFunctionSupport() &&
-               this->glCaps().pathRenderingSupport();
-    }
 
     bool programUnitTest(int maxStages);
 
@@ -75,10 +70,6 @@ public:
 
     virtual void initCopySurfaceDstDesc(const GrSurface* src, GrTextureDesc* desc) SK_OVERRIDE;
 
-    virtual void abandonResources() SK_OVERRIDE;
-
-    const GrGLCaps& glCaps() const { return *fGLContext.info().caps(); }
-
     // These functions should be used to bind GL objects. They track the GL state and skip redundant
     // bindings. Making the equivalent glBind calls directly will confuse the state tracking.
     void bindVertexArray(GrGLuint id) {
@@ -102,8 +93,6 @@ public:
     void notifyIndexBufferDelete(GrGLuint id) {
         fHWGeometryState.notifyIndexBufferDelete(id);
     }
-    void notifyTextureDelete(GrGLTexture* texture);
-    void notifyRenderTargetDelete(GrRenderTarget* renderTarget);
 
 protected:
     virtual bool onCopySurface(GrSurface* dst,
@@ -123,9 +112,10 @@ private:
     virtual GrTexture* onCreateTexture(const GrTextureDesc& desc,
                                        const void* srcData,
                                        size_t rowBytes) SK_OVERRIDE;
+    virtual GrTexture* onCreateCompressedTexture(const GrTextureDesc& desc,
+                                                 const void* srcData) SK_OVERRIDE;
     virtual GrVertexBuffer* onCreateVertexBuffer(size_t size, bool dynamic) SK_OVERRIDE;
     virtual GrIndexBuffer* onCreateIndexBuffer(size_t size, bool dynamic) SK_OVERRIDE;
-    virtual GrPath* onCreatePath(const SkPath&, const SkStrokeRec&) SK_OVERRIDE;
     virtual GrTexture* onWrapBackendTexture(const GrBackendTextureDesc&) SK_OVERRIDE;
     virtual GrRenderTarget* onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&) SK_OVERRIDE;
     virtual bool createStencilBufferForRenderTarget(GrRenderTarget* rt,
@@ -135,9 +125,8 @@ private:
         GrStencilBuffer* sb,
         GrRenderTarget* rt) SK_OVERRIDE;
 
-    virtual void onClear(const SkIRect* rect, GrColor color, bool canIgnoreRect) SK_OVERRIDE;
-
-    virtual void onForceRenderTargetFlush() SK_OVERRIDE;
+    virtual void onClear(GrRenderTarget*, const SkIRect* rect, GrColor color,
+                         bool canIgnoreRect) SK_OVERRIDE;
 
     virtual bool onReadPixels(GrRenderTarget* target,
                               int left, int top,
@@ -155,14 +144,16 @@ private:
 
     virtual void onGpuDraw(const DrawInfo&) SK_OVERRIDE;
 
-    virtual void onGpuStencilPath(const GrPath*, SkPath::FillType) SK_OVERRIDE;
-    virtual void onGpuDrawPath(const GrPath*, SkPath::FillType) SK_OVERRIDE;
 
-    virtual void clearStencil() SK_OVERRIDE;
-    virtual void clearStencilClip(const SkIRect& rect,
+    virtual void clearStencil(GrRenderTarget*) SK_OVERRIDE;
+    virtual void clearStencilClip(GrRenderTarget*, const SkIRect& rect,
                                   bool insideClip) SK_OVERRIDE;
     virtual bool flushGraphicsState(DrawType, const GrDeviceCoordTexture* dstCopy) SK_OVERRIDE;
 
+    // GrDrawTarget overrides
+    virtual void didAddGpuTraceMarker() SK_OVERRIDE;
+    virtual void didRemoveGpuTraceMarker() SK_OVERRIDE;
+
     // binds texture unit in GL
     void setTextureUnit(int unitIdx);
 
@@ -175,9 +166,10 @@ private:
     // The params should be the final coefficients to apply
     // (after any blending optimizations or dual source blending considerations
     // have been accounted for).
-    void flushBlend(bool isLines, GrBlendCoeff srcCoeff, GrBlendCoeff dstCoeff);
+    void flushBlend(const GrOptDrawState& optState, bool isLines,
+                    GrBlendCoeff srcCoeff, GrBlendCoeff dstCoeff);
 
-    bool hasExtension(const char* ext) const { return fGLContext.info().hasExtension(ext); }
+    bool hasExtension(const char* ext) const { return fGLContext.hasExtension(ext); }
 
     static bool BlendCoeffReferencesConstant(GrBlendCoeff coeff);
 
@@ -188,14 +180,15 @@ private:
 
         void abandon();
         GrGLProgram* getProgram(const GrGLProgramDesc& desc,
-                                const GrEffectStage* colorStages[],
-                                const GrEffectStage* coverageStages[]);
+                                const GrGeometryStage* geometryProcessor,
+                                const GrFragmentStage* colorStages[],
+                                const GrFragmentStage* coverageStages[]);
 
     private:
         enum {
             // We may actually have kMaxEntries+1 shaders in the GL context because we create a new
             // shader before evicting from the cache.
-            kMaxEntries = 32,
+            kMaxEntries = 128,
             kHashBits = 6,
         };
 
@@ -224,11 +217,11 @@ private:
     };
 
     // flushes dithering, color-mask, and face culling stat
-    void flushMiscFixedFunctionState();
+    void flushMiscFixedFunctionState(const GrOptDrawState&);
 
     // flushes the scissor. see the note on flushBoundTextureAndParams about
     // flushing the scissor after that function is called.
-    void flushScissor();
+    void flushScissor(const GrGLIRect& rtViewport, GrSurfaceOrigin rtOrigin);
 
     void initFSAASupport();
 
@@ -239,12 +232,12 @@ private:
     // ensures that such operations don't negatively interact with tracking bound textures.
     void setScratchTextureUnit();
 
-    // bound is region that may be modified and therefore has to be resolved.
+    // bounds is region that may be modified and therefore has to be resolved.
     // NULL means whole target. Can be an empty rect.
-    void flushRenderTarget(const SkIRect* bound);
+    void flushRenderTarget(GrGLRenderTarget*, const SkIRect* bounds);
+
     void flushStencil(DrawType);
-    void flushAAState(DrawType);
-    void flushPathStencilSettings(SkPath::FillType fill);
+    void flushAAState(const GrOptDrawState&, DrawType);
 
     bool configToGLFormats(GrPixelConfig config,
                            bool getSizedInternal,
@@ -259,10 +252,24 @@ private:
                        const void* data,
                        size_t rowBytes);
 
+    // helper for onCreateCompressedTexture. If width and height are
+    // set to -1, then this function will use desc.fWidth and desc.fHeight
+    // for the size of the data. The isNewTexture flag should be set to true
+    // whenever a new texture needs to be created. Otherwise, we assume that
+    // the texture is already in GPU memory and that it's going to be updated
+    // with new data.
+    bool uploadCompressedTexData(const GrGLTexture::Desc& desc,
+                                 const void* data,
+                                 bool isNewTexture = true,
+                                 int left = 0, int top = 0,
+                                 int width = -1, int height = -1);
+
     bool createRenderTargetObjects(int width, int height,
                                    GrGLuint texID,
                                    GrGLRenderTarget::Desc* desc);
 
+    GrGLuint bindSurfaceAsFBO(GrSurface* surface, GrGLenum fboTarget, GrGLIRect* viewport);
+
     GrGLContext fGLContext;
 
     // GL program-related state
@@ -310,7 +317,7 @@ private:
             fDefaultVertexArrayBoundIndexBufferID = false;
             fDefaultVertexArrayBoundIndexBufferIDIsValid = false;
             fDefaultVertexArrayAttribState.invalidate();
-            if (NULL != fVBOVertexArray) {
+            if (fVBOVertexArray) {
                 fVBOVertexArray->invalidateCachedState();
             }
         }
@@ -338,7 +345,7 @@ private:
             if (fBoundVertexBufferIDIsValid && id == fBoundVertexBufferID) {
                 fBoundVertexBufferID = 0;
             }
-            if (NULL != fVBOVertexArray) {
+            if (fVBOVertexArray) {
                 fVBOVertexArray->notifyVertexBufferDelete(id);
             }
             fDefaultVertexArrayAttribState.notifyVertexBufferDelete(id);
@@ -349,7 +356,7 @@ private:
                 id == fDefaultVertexArrayBoundIndexBufferID) {
                 fDefaultVertexArrayBoundIndexBufferID = 0;
             }
-            if (NULL != fVBOVertexArray) {
+            if (fVBOVertexArray) {
                 fVBOVertexArray->notifyIndexBufferDelete(id);
             }
         }
@@ -418,35 +425,18 @@ private:
         }
     } fHWBlendState;
 
-    struct {
-        TriState fMSAAEnabled;
-        TriState fSmoothLineEnabled;
-        void invalidate() {
-            fMSAAEnabled = kUnknown_TriState;
-            fSmoothLineEnabled = kUnknown_TriState;
-        }
-    } fHWAAState;
-
-
-    GrGLProgram::MatrixState    fHWProjectionMatrixState;
+    TriState fMSAAEnabled;
 
     GrStencilSettings           fHWStencilSettings;
     TriState                    fHWStencilTestEnabled;
-    GrStencilSettings           fHWPathStencilSettings;
+
 
     GrDrawState::DrawFace       fHWDrawFace;
     TriState                    fHWWriteToColor;
     TriState                    fHWDitherEnabled;
-    GrRenderTarget*             fHWBoundRenderTarget;
-    SkTArray<GrTexture*, true>  fHWBoundTextures;
+    uint32_t                    fHWBoundRenderTargetUniqueID;
+    SkTArray<uint32_t, true>    fHWBoundTextureUniqueIDs;
 
-    struct TexGenData {
-        GrGLenum  fMode;
-        GrGLint   fNumComponents;
-        GrGLfloat fCoefficients[3 * 3];
-    };
-    int                         fHWActiveTexGenSets;
-    SkTArray<TexGenData, true>  fHWTexGenSettings;
     ///@}
 
     // we record what stencil format worked last time to hopefully exit early
@@ -454,6 +444,7 @@ private:
     int fLastSuccessfulStencilFmtIdx;
 
     typedef GrGpu INHERITED;
+    friend class GrGLPathRendering; // For accessing setTextureUnit.
 };
 
 #endif