1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com/* 2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2011 Google Inc. 3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * 4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be 5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file. 6ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 7ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 8ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#ifndef GrGpuGL_DEFINED 9ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#define GrGpuGL_DEFINED 10ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 11c1d2a58ec8510b226e080f5415a05723a686aab3bsalomon@google.com#include "GrBinHashKey.h" 12d8f856c32b679d9f5a9926feac005e2c0186f83ftomhudson@google.com#include "GrDrawState.h" 136177e6999d23a4268ffd98dedfb1da00e272a89brobertphillips@google.com#include "GrGLContext.h" 148895a7a0e222de4530e506e43eaa5e6030e8c5edbsalomon@google.com#include "GrGLIRect.h" 15a0b40280a49a8a43af7929ead3b3489951c58501commit-bot@chromium.org#include "GrGLIndexBuffer.h" 165739d2c168819394502e20cbe6071979b9c1038cbsalomon@google.com#include "GrGLProgram.h" 1781c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com#include "GrGLStencilBuffer.h" 18ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#include "GrGLTexture.h" 196918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com#include "GrGLVertexArray.h" 20ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#include "GrGLVertexBuffer.h" 21a0b40280a49a8a43af7929ead3b3489951c58501commit-bot@chromium.org#include "GrGpu.h" 224c2af7407818f6f2d4e4b57da6bbca16524e04b9mtklein@google.com#include "GrTHashTable.h" 23a0b40280a49a8a43af7929ead3b3489951c58501commit-bot@chromium.org#include "SkTypes.h" 24ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 25174db77d1aa9bfa779cdb5ea2aac070af2883cddcommit-bot@chromium.org#ifdef SK_DEVELOPER 26948787737b77555318fa2433e7ff941516fe950ejvanverth@google.com#define PROGRAM_CACHE_STATS 27948787737b77555318fa2433e7ff941516fe950ejvanverth@google.com#endif 28948787737b77555318fa2433e7ff941516fe950ejvanverth@google.com 29511923443facc611b3735b4688342c12071feaa0cdaltonclass GrGLNameAllocator; 30511923443facc611b3735b4688342c12071feaa0cdalton 31ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.comclass GrGpuGL : public GrGpu { 32ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.compublic: 336177e6999d23a4268ffd98dedfb1da00e272a89brobertphillips@google.com GrGpuGL(const GrGLContext& ctx, GrContext* context); 34ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com virtual ~GrGpuGL(); 35ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 36c9424b8e6dc204fc304c021480a04a468899aa34commit-bot@chromium.org const GrGLContext& glContext() const { return fGLContext; } 37c9424b8e6dc204fc304c021480a04a468899aa34commit-bot@chromium.org 386177e6999d23a4268ffd98dedfb1da00e272a89brobertphillips@google.com const GrGLInterface* glInterface() const { return fGLContext.interface(); } 39b1854a85095f9924947bc00e665da47b0c0bdfb9commit-bot@chromium.org const GrGLContextInfo& ctxInfo() const { return fGLContext; } 40b1854a85095f9924947bc00e665da47b0c0bdfb9commit-bot@chromium.org GrGLStandard glStandard() const { return fGLContext.standard(); } 41b1854a85095f9924947bc00e665da47b0c0bdfb9commit-bot@chromium.org GrGLVersion glVersion() const { return fGLContext.version(); } 42b1854a85095f9924947bc00e665da47b0c0bdfb9commit-bot@chromium.org GrGLSLGeneration glslGeneration() const { return fGLContext.glslGeneration(); } 43b1854a85095f9924947bc00e665da47b0c0bdfb9commit-bot@chromium.org const GrGLCaps& glCaps() const { return *fGLContext.caps(); } 440b77d6892b067ad402c9678b0226bff70599fbe2bsalomon@google.com 4528361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org virtual void discard(GrRenderTarget*) SK_OVERRIDE; 4628361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org 470a6fe71f1bc0e601b41b7ae6d28b8c96a2c41116commit-bot@chromium.org // Used by GrGLProgram and GrGLPathTexGenProgramEffects to configure OpenGL 480a6fe71f1bc0e601b41b7ae6d28b8c96a2c41116commit-bot@chromium.org // state. 4934cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com void bindTexture(int unitIdx, const GrTextureParams& params, GrGLTexture* texture); 506b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org void setProjectionMatrix(const SkMatrix& matrix, 516b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org const SkISize& renderTargetSize, 526b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org GrSurfaceOrigin renderTargetOrigin); 530a6fe71f1bc0e601b41b7ae6d28b8c96a2c41116commit-bot@chromium.org enum PathTexGenComponents { 540a6fe71f1bc0e601b41b7ae6d28b8c96a2c41116commit-bot@chromium.org kS_PathTexGenComponents = 1, 550a6fe71f1bc0e601b41b7ae6d28b8c96a2c41116commit-bot@chromium.org kST_PathTexGenComponents = 2, 560a6fe71f1bc0e601b41b7ae6d28b8c96a2c41116commit-bot@chromium.org kSTR_PathTexGenComponents = 3 576b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org }; 580a6fe71f1bc0e601b41b7ae6d28b8c96a2c41116commit-bot@chromium.org void enablePathTexGen(int unitIdx, PathTexGenComponents, const GrGLfloat* coefficients); 590a6fe71f1bc0e601b41b7ae6d28b8c96a2c41116commit-bot@chromium.org void enablePathTexGen(int unitIdx, PathTexGenComponents, const SkMatrix& matrix); 600a6fe71f1bc0e601b41b7ae6d28b8c96a2c41116commit-bot@chromium.org void flushPathTexGenSettings(int numUsedTexCoordSets); 618e919add406c5d20918a7f0ca811317312e6ce67commit-bot@chromium.org bool shouldUseFixedFunctionTexturing() const { 620a6fe71f1bc0e601b41b7ae6d28b8c96a2c41116commit-bot@chromium.org return this->glCaps().pathRenderingSupport(); 638e919add406c5d20918a7f0ca811317312e6ce67commit-bot@chromium.org } 6434cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com 65a45afcf14b1707cc8075bdd4bd882c8a1aea64b7bsalomon@google.com bool programUnitTest(int maxStages); 6634cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com 6756d11e097b1975371d0e0b1452ac0c4d5fc46930bsalomon@google.com // GrGpu overrides 685d1d79a1f9d351e6f2390d844e6a7361d7d607cacommit-bot@chromium.org virtual GrPixelConfig preferredReadPixelsConfig(GrPixelConfig readConfig, 695d1d79a1f9d351e6f2390d844e6a7361d7d607cacommit-bot@chromium.org GrPixelConfig surfaceConfig) const SK_OVERRIDE; 705d1d79a1f9d351e6f2390d844e6a7361d7d607cacommit-bot@chromium.org virtual GrPixelConfig preferredWritePixelsConfig(GrPixelConfig writeConfig, 715d1d79a1f9d351e6f2390d844e6a7361d7d607cacommit-bot@chromium.org GrPixelConfig surfaceConfig) const SK_OVERRIDE; 729c68058b679aee81e6e0158e7fcbfb5d8479c91absalomon@google.com virtual bool canWriteTexturePixels(const GrTexture*, GrPixelConfig srcConfig) const SK_OVERRIDE; 73c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com virtual bool readPixelsWillPayForYFlip( 74c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com GrRenderTarget* renderTarget, 75c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com int left, int top, 76c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com int width, int height, 77c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com GrPixelConfig config, 7856d11e097b1975371d0e0b1452ac0c4d5fc46930bsalomon@google.com size_t rowBytes) const SK_OVERRIDE; 7956d11e097b1975371d0e0b1452ac0c4d5fc46930bsalomon@google.com virtual bool fullReadPixelsIsFasterThanPartial() const SK_OVERRIDE; 8075f9f25d8bf2adc0494f9afbbd5965809ee13acabsalomon@google.com 81eb85117c05471e1a55ce387cbc38279f857a4584bsalomon@google.com virtual void initCopySurfaceDstDesc(const GrSurface* src, GrTextureDesc* desc) SK_OVERRIDE; 82eb85117c05471e1a55ce387cbc38279f857a4584bsalomon@google.com 835739d2c168819394502e20cbe6071979b9c1038cbsalomon@google.com virtual void abandonResources() SK_OVERRIDE; 845739d2c168819394502e20cbe6071979b9c1038cbsalomon@google.com 856918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com // These functions should be used to bind GL objects. They track the GL state and skip redundant 86754a3eb73b796398062f09cc98eae224262a3bc8skia.committer@gmail.com // bindings. Making the equivalent glBind calls directly will confuse the state tracking. 876918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com void bindVertexArray(GrGLuint id) { 886918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com fHWGeometryState.setVertexArrayID(this, id); 896918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com } 906918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com void bindIndexBufferAndDefaultVertexArray(GrGLuint id) { 916918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com fHWGeometryState.setIndexBufferIDOnDefaultVertexArray(this, id); 926918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com } 936918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com void bindVertexBuffer(GrGLuint id) { 946918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com fHWGeometryState.setVertexBufferID(this, id); 956918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com } 966918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com 976918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com // These callbacks update state tracking when GL objects are deleted. They are called from 986918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com // GrGLResource onRelease functions. 996918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com void notifyVertexArrayDelete(GrGLuint id) { 1006918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com fHWGeometryState.notifyVertexArrayDelete(id); 1016918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com } 1026918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com void notifyVertexBufferDelete(GrGLuint id) { 1036918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com fHWGeometryState.notifyVertexBufferDelete(id); 1046918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com } 1056918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com void notifyIndexBufferDelete(GrGLuint id) { 1066918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com fHWGeometryState.notifyIndexBufferDelete(id); 1076918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com } 108880b8fcf255e67a15687e8b7cc47397372db683cbsalomon@google.com void notifyTextureDelete(GrGLTexture* texture); 109880b8fcf255e67a15687e8b7cc47397372db683cbsalomon@google.com void notifyRenderTargetDelete(GrRenderTarget* renderTarget); 110880b8fcf255e67a15687e8b7cc47397372db683cbsalomon@google.com 111511923443facc611b3735b4688342c12071feaa0cdalton // These functions should be used to generate and delete GL path names. They have their own 112511923443facc611b3735b4688342c12071feaa0cdalton // allocator that runs on the client side, so they are much faster than going through GenPaths. 113511923443facc611b3735b4688342c12071feaa0cdalton GrGLuint createGLPathObject(); 114511923443facc611b3735b4688342c12071feaa0cdalton void deleteGLPathObject(GrGLuint); 115511923443facc611b3735b4688342c12071feaa0cdalton 11663150afcc0c4120370db6f5566cd404584345668commit-bot@chromium.orgprotected: 11763150afcc0c4120370db6f5566cd404584345668commit-bot@chromium.org virtual bool onCopySurface(GrSurface* dst, 11863150afcc0c4120370db6f5566cd404584345668commit-bot@chromium.org GrSurface* src, 11963150afcc0c4120370db6f5566cd404584345668commit-bot@chromium.org const SkIRect& srcRect, 12063150afcc0c4120370db6f5566cd404584345668commit-bot@chromium.org const SkIPoint& dstPoint) SK_OVERRIDE; 12163150afcc0c4120370db6f5566cd404584345668commit-bot@chromium.org 12263150afcc0c4120370db6f5566cd404584345668commit-bot@chromium.org virtual bool onCanCopySurface(GrSurface* dst, 12363150afcc0c4120370db6f5566cd404584345668commit-bot@chromium.org GrSurface* src, 12463150afcc0c4120370db6f5566cd404584345668commit-bot@chromium.org const SkIRect& srcRect, 12563150afcc0c4120370db6f5566cd404584345668commit-bot@chromium.org const SkIPoint& dstPoint) SK_OVERRIDE; 12663150afcc0c4120370db6f5566cd404584345668commit-bot@chromium.org 12702ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.comprivate: 1281c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com // GrGpu overrides 1290a208a117b2d7f2c2231aa357f1db4864dbdcba3bsalomon@google.com virtual void onResetContext(uint32_t resetBits) SK_OVERRIDE; 130a7f84e150cb9e821267a8ca9e59c1ae9a3cfa300bsalomon@google.com 131fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com virtual GrTexture* onCreateTexture(const GrTextureDesc& desc, 132bcdbbe61e1a3f89545b2c1461164f0f8bf5f0797bsalomon@google.com const void* srcData, 13313f1b6f1569bb5c639ca762f6b153133173c6295bsalomon@google.com size_t rowBytes) SK_OVERRIDE; 1349c0e629c64c0fa93ac9bf5c2eaa1821370a6fbe5krajcevski virtual GrTexture* onCreateCompressedTexture(const GrTextureDesc& desc, 1359c0e629c64c0fa93ac9bf5c2eaa1821370a6fbe5krajcevski const void* srcData) SK_OVERRIDE; 136adacc7067ad617cdc7bbef39192ca80f4b4d27f9robertphillips@google.com virtual GrVertexBuffer* onCreateVertexBuffer(size_t size, bool dynamic) SK_OVERRIDE; 137adacc7067ad617cdc7bbef39192ca80f4b4d27f9robertphillips@google.com virtual GrIndexBuffer* onCreateIndexBuffer(size_t size, bool dynamic) SK_OVERRIDE; 13832184d81629e39809bb9e915286d8fe971a8ed68commit-bot@chromium.org virtual GrPath* onCreatePath(const SkPath&, const SkStrokeRec&) SK_OVERRIDE; 13916e3ddea6a80972aced04b21b1d66377fa95e7c7bsalomon@google.com virtual GrTexture* onWrapBackendTexture(const GrBackendTextureDesc&) SK_OVERRIDE; 14016e3ddea6a80972aced04b21b1d66377fa95e7c7bsalomon@google.com virtual GrRenderTarget* onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&) SK_OVERRIDE; 14181c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com virtual bool createStencilBufferForRenderTarget(GrRenderTarget* rt, 14213f1b6f1569bb5c639ca762f6b153133173c6295bsalomon@google.com int width, 14313f1b6f1569bb5c639ca762f6b153133173c6295bsalomon@google.com int height) SK_OVERRIDE; 14413f1b6f1569bb5c639ca762f6b153133173c6295bsalomon@google.com virtual bool attachStencilBufferToRenderTarget( 14513f1b6f1569bb5c639ca762f6b153133173c6295bsalomon@google.com GrStencilBuffer* sb, 14613f1b6f1569bb5c639ca762f6b153133173c6295bsalomon@google.com GrRenderTarget* rt) SK_OVERRIDE; 147a7f84e150cb9e821267a8ca9e59c1ae9a3cfa300bsalomon@google.com 14856ce48ade325f6f49acb0da31d6252806e4ed7efrobertphillips@google.com virtual void onClear(const SkIRect* rect, GrColor color, bool canIgnoreRect) SK_OVERRIDE; 149a7f84e150cb9e821267a8ca9e59c1ae9a3cfa300bsalomon@google.com 1505877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com virtual bool onReadPixels(GrRenderTarget* target, 151d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com int left, int top, 152c69809745e6496564639e42ef998ad39adf7dfb8bsalomon@google.com int width, int height, 153d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com GrPixelConfig, 154c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com void* buffer, 1553cb406bb88f5aa09cf9f5a9554b4b1314cf1a2eesenorblanco@chromium.org size_t rowBytes) SK_OVERRIDE; 156a7f84e150cb9e821267a8ca9e59c1ae9a3cfa300bsalomon@google.com 1579c68058b679aee81e6e0158e7fcbfb5d8479c91absalomon@google.com virtual bool onWriteTexturePixels(GrTexture* texture, 1586f3795105b2b458079e53a721c1735c9518f6bb5bsalomon@google.com int left, int top, int width, int height, 1596f3795105b2b458079e53a721c1735c9518f6bb5bsalomon@google.com GrPixelConfig config, const void* buffer, 1606f3795105b2b458079e53a721c1735c9518f6bb5bsalomon@google.com size_t rowBytes) SK_OVERRIDE; 1616f3795105b2b458079e53a721c1735c9518f6bb5bsalomon@google.com 16275f9f25d8bf2adc0494f9afbbd5965809ee13acabsalomon@google.com virtual void onResolveRenderTarget(GrRenderTarget* target) SK_OVERRIDE; 16375f9f25d8bf2adc0494f9afbbd5965809ee13acabsalomon@google.com 16474749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com virtual void onGpuDraw(const DrawInfo&) SK_OVERRIDE; 165ded4f4b163f5aa19c22c871178c55ecb34623846bsalomon@google.com 16612b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com virtual void onGpuStencilPath(const GrPath*, SkPath::FillType) SK_OVERRIDE; 16732184d81629e39809bb9e915286d8fe971a8ed68commit-bot@chromium.org virtual void onGpuDrawPath(const GrPath*, SkPath::FillType) SK_OVERRIDE; 168ecc45365b6429ee4cbe1748dc6667b862d5f0f71commit-bot@chromium.org virtual void onGpuDrawPaths(int, const GrPath**, const SkMatrix*, 1699b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org SkPath::FillType, 1709b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org SkStrokeRec::Style) SK_OVERRIDE; 171730ebe5e0058da5fc2c615c042819a82df29e7c0robertphillips@google.com 17213f1b6f1569bb5c639ca762f6b153133173c6295bsalomon@google.com virtual void clearStencil() SK_OVERRIDE; 173fd03d4a829efe2d77a712fd991927c55f59a2ffecommit-bot@chromium.org virtual void clearStencilClip(const SkIRect& rect, 17413f1b6f1569bb5c639ca762f6b153133173c6295bsalomon@google.com bool insideClip) SK_OVERRIDE; 17526e18b593ab65e4d92dfbce92579d8bc180d4c2cbsalomon@google.com virtual bool flushGraphicsState(DrawType, const GrDeviceCoordTexture* dstCopy) SK_OVERRIDE; 1765739d2c168819394502e20cbe6071979b9c1038cbsalomon@google.com 177a3baf3be0e2a3128fb73bd41d40d130f75a4dc86commit-bot@chromium.org // GrDrawTarget ovverides 1782a05de0c049a8648942a55016126a1f92e1c14d6commit-bot@chromium.org virtual void didAddGpuTraceMarker() SK_OVERRIDE; 1792a05de0c049a8648942a55016126a1f92e1c14d6commit-bot@chromium.org virtual void didRemoveGpuTraceMarker() SK_OVERRIDE; 180a3baf3be0e2a3128fb73bd41d40d130f75a4dc86commit-bot@chromium.org 1811c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com // binds texture unit in GL 1828531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com void setTextureUnit(int unitIdx); 183ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 184880b8fcf255e67a15687e8b7cc47397372db683cbsalomon@google.com // Sets up vertex attribute pointers and strides. On return indexOffsetInBytes gives the offset 185880b8fcf255e67a15687e8b7cc47397372db683cbsalomon@google.com // an into the index buffer. It does not account for drawInfo.startIndex() but rather the start 186880b8fcf255e67a15687e8b7cc47397372db683cbsalomon@google.com // index is relative to the returned offset. 187880b8fcf255e67a15687e8b7cc47397372db683cbsalomon@google.com void setupGeometry(const DrawInfo& info, size_t* indexOffsetInBytes); 1887acdb8e1d29fe50454431d768ddc862b693db8b0bsalomon@google.com 18986c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com // Subclasses should call this to flush the blend state. 19074749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com // The params should be the final coefficients to apply 19186c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com // (after any blending optimizations or dual source blending considerations 19286c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com // have been accounted for). 19302ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com void flushBlend(bool isLines, GrBlendCoeff srcCoeff, GrBlendCoeff dstCoeff); 194271cffc77bd2fcb3458559e509634442517ca1e9bsalomon@google.com 195b1854a85095f9924947bc00e665da47b0c0bdfb9commit-bot@chromium.org bool hasExtension(const char* ext) const { return fGLContext.hasExtension(ext); } 19696399948dc2f1afd2e9d9e5be7d646c01d17f82bbsalomon@google.com 197271cffc77bd2fcb3458559e509634442517ca1e9bsalomon@google.com static bool BlendCoeffReferencesConstant(GrBlendCoeff coeff); 198080773ca79cbdc230730d295441255e9254d76a6bsalomon@google.com 199a0b40280a49a8a43af7929ead3b3489951c58501commit-bot@chromium.org class ProgramCache : public ::SkNoncopyable { 200c1d2a58ec8510b226e080f5415a05723a686aab3bsalomon@google.com public: 2019188a15f846ae79892c332aed2a72ee38116bdc6commit-bot@chromium.org ProgramCache(GrGpuGL* gpu); 202948787737b77555318fa2433e7ff941516fe950ejvanverth@google.com ~ProgramCache(); 203c1d2a58ec8510b226e080f5415a05723a686aab3bsalomon@google.com 204c1d2a58ec8510b226e080f5415a05723a686aab3bsalomon@google.com void abandon(); 2052c84aa35988c661b3e5513c8ba9b3959832ff288bsalomon@google.com GrGLProgram* getProgram(const GrGLProgramDesc& desc, 2062c84aa35988c661b3e5513c8ba9b3959832ff288bsalomon@google.com const GrEffectStage* colorStages[], 2072c84aa35988c661b3e5513c8ba9b3959832ff288bsalomon@google.com const GrEffectStage* coverageStages[]); 2082db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com 209c1d2a58ec8510b226e080f5415a05723a686aab3bsalomon@google.com private: 210c1d2a58ec8510b226e080f5415a05723a686aab3bsalomon@google.com enum { 2119ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com // We may actually have kMaxEntries+1 shaders in the GL context because we create a new 2129ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com // shader before evicting from the cache. 213b556422de723ba176f6b453818c49bd85b836957commit-bot@chromium.org kMaxEntries = 128, 2142db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com kHashBits = 6, 215c1d2a58ec8510b226e080f5415a05723a686aab3bsalomon@google.com }; 216c1d2a58ec8510b226e080f5415a05723a686aab3bsalomon@google.com 2172db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com struct Entry; 2182db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com 2192db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com struct ProgDescLess; 2202db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com 2212db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com // binary search for entry matching desc. returns index into fEntries that matches desc or ~ 2222db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com // of the index of where it should be inserted. 2232db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com int search(const GrGLProgramDesc& desc) const; 224c1d2a58ec8510b226e080f5415a05723a686aab3bsalomon@google.com 2252db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com // sorted array of all the entries 2262db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com Entry* fEntries[kMaxEntries]; 2272db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com // hash table based on lowest kHashBits bits of the program key. Used to avoid binary 2282db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com // searching fEntries. 2292db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com Entry* fHashTable[1 << kHashBits]; 230c1d2a58ec8510b226e080f5415a05723a686aab3bsalomon@google.com 231c1d2a58ec8510b226e080f5415a05723a686aab3bsalomon@google.com int fCount; 232c1d2a58ec8510b226e080f5415a05723a686aab3bsalomon@google.com unsigned int fCurrLRUStamp; 2339188a15f846ae79892c332aed2a72ee38116bdc6commit-bot@chromium.org GrGpuGL* fGpu; 234948787737b77555318fa2433e7ff941516fe950ejvanverth@google.com#ifdef PROGRAM_CACHE_STATS 235948787737b77555318fa2433e7ff941516fe950ejvanverth@google.com int fTotalRequests; 236948787737b77555318fa2433e7ff941516fe950ejvanverth@google.com int fCacheMisses; 2372db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com int fHashMisses; // cache hit but hash table missed 238948787737b77555318fa2433e7ff941516fe950ejvanverth@google.com#endif 239c1d2a58ec8510b226e080f5415a05723a686aab3bsalomon@google.com }; 2405739d2c168819394502e20cbe6071979b9c1038cbsalomon@google.com 241c96cb3a929f954cd2e7b6319efdfa6b758b20bd3bsalomon@google.com // flushes dithering, color-mask, and face culling stat 242c96cb3a929f954cd2e7b6319efdfa6b758b20bd3bsalomon@google.com void flushMiscFixedFunctionState(); 243c96cb3a929f954cd2e7b6319efdfa6b758b20bd3bsalomon@google.com 244a320194e4242ef0e5e758aea896bfd52bcb3dac7bsalomon@google.com // flushes the scissor. see the note on flushBoundTextureAndParams about 245a320194e4242ef0e5e758aea896bfd52bcb3dac7bsalomon@google.com // flushing the scissor after that function is called. 246a320194e4242ef0e5e758aea896bfd52bcb3dac7bsalomon@google.com void flushScissor(); 247a320194e4242ef0e5e758aea896bfd52bcb3dac7bsalomon@google.com 24818c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com void initFSAASupport(); 2496aa25c3f555dc2a6711365d14279db3ec909e064bsalomon@google.com 2502c17fcdc45f9fa9a2dc785786347040fbe30928bbsalomon@google.com // determines valid stencil formats 25118c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com void initStencilFormats(); 2522c17fcdc45f9fa9a2dc785786347040fbe30928bbsalomon@google.com 253a15f7e5b96ee3d71fdbcb4f9cf02f6a09b4b11accommit-bot@chromium.org // sets a texture unit to use for texture operations other than binding a texture to a program. 254a15f7e5b96ee3d71fdbcb4f9cf02f6a09b4b11accommit-bot@chromium.org // ensures that such operations don't negatively interact with tracking bound textures. 255a15f7e5b96ee3d71fdbcb4f9cf02f6a09b4b11accommit-bot@chromium.org void setScratchTextureUnit(); 256ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 2578295dc1474db279df08d816b2115e807c681fad5bsalomon@google.com // bound is region that may be modified and therefore has to be resolved. 2588295dc1474db279df08d816b2115e807c681fad5bsalomon@google.com // NULL means whole target. Can be an empty rect. 259fd03d4a829efe2d77a712fd991927c55f59a2ffecommit-bot@chromium.org void flushRenderTarget(const SkIRect* bound); 260ded4f4b163f5aa19c22c871178c55ecb34623846bsalomon@google.com void flushStencil(DrawType); 261ded4f4b163f5aa19c22c871178c55ecb34623846bsalomon@google.com void flushAAState(DrawType); 262c4dc0ad8e252a7e30d19b47d3d0d9f2c69faf854commit-bot@chromium.org void flushPathStencilSettings(SkPath::FillType fill); 2630650e811b537f21a3a9d09a953960626cf5cfce4bsalomon@google.com 264280e99f1a61f2cf66a8ee9b9e6c517f3d2290de7bsalomon@google.com bool configToGLFormats(GrPixelConfig config, 265280e99f1a61f2cf66a8ee9b9e6c517f3d2290de7bsalomon@google.com bool getSizedInternal, 266280e99f1a61f2cf66a8ee9b9e6c517f3d2290de7bsalomon@google.com GrGLenum* internalFormat, 267280e99f1a61f2cf66a8ee9b9e6c517f3d2290de7bsalomon@google.com GrGLenum* externalFormat, 268280e99f1a61f2cf66a8ee9b9e6c517f3d2290de7bsalomon@google.com GrGLenum* externalType); 2696f3795105b2b458079e53a721c1735c9518f6bb5bsalomon@google.com // helper for onCreateTexture and writeTexturePixels 270136f55b61752e01b0f140f4b7fbc8db00205a06bbsalomon@google.com bool uploadTexData(const GrGLTexture::Desc& desc, 2711e0e6079219de9cea6ad4b74b1ca5498fa9d3597bsalomon@google.com bool isNewTexture, 2726f3795105b2b458079e53a721c1735c9518f6bb5bsalomon@google.com int left, int top, int width, int height, 2736f3795105b2b458079e53a721c1735c9518f6bb5bsalomon@google.com GrPixelConfig dataConfig, 2746f3795105b2b458079e53a721c1735c9518f6bb5bsalomon@google.com const void* data, 2756f3795105b2b458079e53a721c1735c9518f6bb5bsalomon@google.com size_t rowBytes); 2760650e811b537f21a3a9d09a953960626cf5cfce4bsalomon@google.com 277145d48c4ccf1024ce0878e5110c0be7d414b7ddekrajcevski // helper for onCreateCompressedTexture. If width and height are 278145d48c4ccf1024ce0878e5110c0be7d414b7ddekrajcevski // set to -1, then this function will use desc.fWidth and desc.fHeight 279145d48c4ccf1024ce0878e5110c0be7d414b7ddekrajcevski // for the size of the data. The isNewTexture flag should be set to true 280145d48c4ccf1024ce0878e5110c0be7d414b7ddekrajcevski // whenever a new texture needs to be created. Otherwise, we assume that 281145d48c4ccf1024ce0878e5110c0be7d414b7ddekrajcevski // the texture is already in GPU memory and that it's going to be updated 282145d48c4ccf1024ce0878e5110c0be7d414b7ddekrajcevski // with new data. 2839c0e629c64c0fa93ac9bf5c2eaa1821370a6fbe5krajcevski bool uploadCompressedTexData(const GrGLTexture::Desc& desc, 284145d48c4ccf1024ce0878e5110c0be7d414b7ddekrajcevski const void* data, 285145d48c4ccf1024ce0878e5110c0be7d414b7ddekrajcevski bool isNewTexture = true, 286145d48c4ccf1024ce0878e5110c0be7d414b7ddekrajcevski int left = 0, int top = 0, 287145d48c4ccf1024ce0878e5110c0be7d414b7ddekrajcevski int width = -1, int height = -1); 2889c0e629c64c0fa93ac9bf5c2eaa1821370a6fbe5krajcevski 28981c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com bool createRenderTargetObjects(int width, int height, 29081c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com GrGLuint texID, 29181c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com GrGLRenderTarget::Desc* desc); 29281c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com 2936177e6999d23a4268ffd98dedfb1da00e272a89brobertphillips@google.com GrGLContext fGLContext; 2942c17fcdc45f9fa9a2dc785786347040fbe30928bbsalomon@google.com 2955739d2c168819394502e20cbe6071979b9c1038cbsalomon@google.com // GL program-related state 2965739d2c168819394502e20cbe6071979b9c1038cbsalomon@google.com ProgramCache* fProgramCache; 2979ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com SkAutoTUnref<GrGLProgram> fCurrentProgram; 298492093951ae2a7d7c14aa22f48faa8942f045cafbsalomon@google.com 299492093951ae2a7d7c14aa22f48faa8942f045cafbsalomon@google.com /////////////////////////////////////////////////////////////////////////// 300492093951ae2a7d7c14aa22f48faa8942f045cafbsalomon@google.com ///@name Caching of GL State 301492093951ae2a7d7c14aa22f48faa8942f045cafbsalomon@google.com ///@{ 302492093951ae2a7d7c14aa22f48faa8942f045cafbsalomon@google.com int fHWActiveTextureUnitIdx; 3035739d2c168819394502e20cbe6071979b9c1038cbsalomon@google.com GrGLuint fHWProgramID; 30491207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com 30591207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com GrGLProgram::SharedGLState fSharedGLProgramState; 3065739d2c168819394502e20cbe6071979b9c1038cbsalomon@google.com 307492093951ae2a7d7c14aa22f48faa8942f045cafbsalomon@google.com enum TriState { 308492093951ae2a7d7c14aa22f48faa8942f045cafbsalomon@google.com kNo_TriState, 309492093951ae2a7d7c14aa22f48faa8942f045cafbsalomon@google.com kYes_TriState, 310492093951ae2a7d7c14aa22f48faa8942f045cafbsalomon@google.com kUnknown_TriState 311492093951ae2a7d7c14aa22f48faa8942f045cafbsalomon@google.com }; 312492093951ae2a7d7c14aa22f48faa8942f045cafbsalomon@google.com 313a320194e4242ef0e5e758aea896bfd52bcb3dac7bsalomon@google.com // last scissor / viewport scissor state seen by the GL. 314a320194e4242ef0e5e758aea896bfd52bcb3dac7bsalomon@google.com struct { 315a320194e4242ef0e5e758aea896bfd52bcb3dac7bsalomon@google.com TriState fEnabled; 316a320194e4242ef0e5e758aea896bfd52bcb3dac7bsalomon@google.com GrGLIRect fRect; 317a320194e4242ef0e5e758aea896bfd52bcb3dac7bsalomon@google.com void invalidate() { 318a320194e4242ef0e5e758aea896bfd52bcb3dac7bsalomon@google.com fEnabled = kUnknown_TriState; 319a320194e4242ef0e5e758aea896bfd52bcb3dac7bsalomon@google.com fRect.invalidate(); 320a320194e4242ef0e5e758aea896bfd52bcb3dac7bsalomon@google.com } 321a320194e4242ef0e5e758aea896bfd52bcb3dac7bsalomon@google.com } fHWScissorSettings; 322a320194e4242ef0e5e758aea896bfd52bcb3dac7bsalomon@google.com 323a320194e4242ef0e5e758aea896bfd52bcb3dac7bsalomon@google.com GrGLIRect fHWViewport; 324a320194e4242ef0e5e758aea896bfd52bcb3dac7bsalomon@google.com 325880b8fcf255e67a15687e8b7cc47397372db683cbsalomon@google.com /** 326880b8fcf255e67a15687e8b7cc47397372db683cbsalomon@google.com * Tracks bound vertex and index buffers and vertex attrib array state. 327880b8fcf255e67a15687e8b7cc47397372db683cbsalomon@google.com */ 328880b8fcf255e67a15687e8b7cc47397372db683cbsalomon@google.com class HWGeometryState { 329880b8fcf255e67a15687e8b7cc47397372db683cbsalomon@google.com public: 3306918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com HWGeometryState() { fVBOVertexArray = NULL; this->invalidate(); } 331754a3eb73b796398062f09cc98eae224262a3bc8skia.committer@gmail.com 3326918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com ~HWGeometryState() { SkSafeUnref(fVBOVertexArray); } 333880b8fcf255e67a15687e8b7cc47397372db683cbsalomon@google.com 334880b8fcf255e67a15687e8b7cc47397372db683cbsalomon@google.com void invalidate() { 3356918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com fBoundVertexArrayIDIsValid = false; 336880b8fcf255e67a15687e8b7cc47397372db683cbsalomon@google.com fBoundVertexBufferIDIsValid = false; 3376918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com fDefaultVertexArrayBoundIndexBufferID = false; 3386918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com fDefaultVertexArrayBoundIndexBufferIDIsValid = false; 3396918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com fDefaultVertexArrayAttribState.invalidate(); 340ce6da4d96ae00a66c56c45a3b902224d8b3e6cf7commit-bot@chromium.org if (NULL != fVBOVertexArray) { 341ce6da4d96ae00a66c56c45a3b902224d8b3e6cf7commit-bot@chromium.org fVBOVertexArray->invalidateCachedState(); 342ce6da4d96ae00a66c56c45a3b902224d8b3e6cf7commit-bot@chromium.org } 343880b8fcf255e67a15687e8b7cc47397372db683cbsalomon@google.com } 344880b8fcf255e67a15687e8b7cc47397372db683cbsalomon@google.com 3456918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com void notifyVertexArrayDelete(GrGLuint id) { 3466918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com if (fBoundVertexArrayIDIsValid && fBoundVertexArrayID == id) { 3476918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com // Does implicit bind to 0 3486918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com fBoundVertexArrayID = 0; 349880b8fcf255e67a15687e8b7cc47397372db683cbsalomon@google.com } 350880b8fcf255e67a15687e8b7cc47397372db683cbsalomon@google.com } 351880b8fcf255e67a15687e8b7cc47397372db683cbsalomon@google.com 3526918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com void setVertexArrayID(GrGpuGL* gpu, GrGLuint arrayID) { 3536918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com if (!gpu->glCaps().vertexArrayObjectSupport()) { 354f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org SkASSERT(0 == arrayID); 3556918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com return; 3566918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com } 3576918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com if (!fBoundVertexArrayIDIsValid || arrayID != fBoundVertexArrayID) { 3586918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com GR_GL_CALL(gpu->glInterface(), BindVertexArray(arrayID)); 3596918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com fBoundVertexArrayIDIsValid = true; 3606918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com fBoundVertexArrayID = arrayID; 361880b8fcf255e67a15687e8b7cc47397372db683cbsalomon@google.com } 362880b8fcf255e67a15687e8b7cc47397372db683cbsalomon@google.com } 363880b8fcf255e67a15687e8b7cc47397372db683cbsalomon@google.com 3646918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com void notifyVertexBufferDelete(GrGLuint id) { 3656918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com if (fBoundVertexBufferIDIsValid && id == fBoundVertexBufferID) { 3666918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com fBoundVertexBufferID = 0; 3676918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com } 3686918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com if (NULL != fVBOVertexArray) { 3696918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com fVBOVertexArray->notifyVertexBufferDelete(id); 3706918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com } 3716918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com fDefaultVertexArrayAttribState.notifyVertexBufferDelete(id); 372880b8fcf255e67a15687e8b7cc47397372db683cbsalomon@google.com } 373880b8fcf255e67a15687e8b7cc47397372db683cbsalomon@google.com 3746918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com void notifyIndexBufferDelete(GrGLuint id) { 3756918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com if (fDefaultVertexArrayBoundIndexBufferIDIsValid && 3766918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com id == fDefaultVertexArrayBoundIndexBufferID) { 3776918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com fDefaultVertexArrayBoundIndexBufferID = 0; 3786918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com } 3796918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com if (NULL != fVBOVertexArray) { 3806918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com fVBOVertexArray->notifyIndexBufferDelete(id); 3816918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com } 382880b8fcf255e67a15687e8b7cc47397372db683cbsalomon@google.com } 383880b8fcf255e67a15687e8b7cc47397372db683cbsalomon@google.com 3846918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com void setVertexBufferID(GrGpuGL* gpu, GrGLuint id) { 3856918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com if (!fBoundVertexBufferIDIsValid || id != fBoundVertexBufferID) { 3866918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com GR_GL_CALL(gpu->glInterface(), BindBuffer(GR_GL_ARRAY_BUFFER, id)); 3876918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com fBoundVertexBufferIDIsValid = true; 3886918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com fBoundVertexBufferID = id; 3896918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com } 390880b8fcf255e67a15687e8b7cc47397372db683cbsalomon@google.com } 391880b8fcf255e67a15687e8b7cc47397372db683cbsalomon@google.com 3926918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com /** 3936918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com * Binds the default vertex array and binds the index buffer. This is used when binding 3946918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com * an index buffer in order to update it. 3956918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com */ 3966918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com void setIndexBufferIDOnDefaultVertexArray(GrGpuGL* gpu, GrGLuint id) { 3976918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com this->setVertexArrayID(gpu, 0); 3986918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com if (!fDefaultVertexArrayBoundIndexBufferIDIsValid || 3996918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com id != fDefaultVertexArrayBoundIndexBufferID) { 4006918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com GR_GL_CALL(gpu->glInterface(), BindBuffer(GR_GL_ELEMENT_ARRAY_BUFFER, id)); 4016918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com fDefaultVertexArrayBoundIndexBufferIDIsValid = true; 4026918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com fDefaultVertexArrayBoundIndexBufferID = id; 403880b8fcf255e67a15687e8b7cc47397372db683cbsalomon@google.com } 404880b8fcf255e67a15687e8b7cc47397372db683cbsalomon@google.com } 405880b8fcf255e67a15687e8b7cc47397372db683cbsalomon@google.com 4066918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com /** 4076918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com * Binds the vertex array object that should be used to render from the vertex buffer. 4086918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com * The vertex array is bound and its attrib array state object is returned. The vertex 4096918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com * buffer is bound. The index buffer (if non-NULL) is bound to the vertex array. The 410754a3eb73b796398062f09cc98eae224262a3bc8skia.committer@gmail.com * returned GrGLAttribArrayState should be used to set vertex attribute arrays. 4116918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com */ 4126918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com GrGLAttribArrayState* bindArrayAndBuffersToDraw(GrGpuGL* gpu, 4136918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com const GrGLVertexBuffer* vbuffer, 4146918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com const GrGLIndexBuffer* ibuffer); 4156918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com 416880b8fcf255e67a15687e8b7cc47397372db683cbsalomon@google.com private: 4176918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com GrGLuint fBoundVertexArrayID; 418880b8fcf255e67a15687e8b7cc47397372db683cbsalomon@google.com GrGLuint fBoundVertexBufferID; 4196918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com bool fBoundVertexArrayIDIsValid; 420880b8fcf255e67a15687e8b7cc47397372db683cbsalomon@google.com bool fBoundVertexBufferIDIsValid; 421880b8fcf255e67a15687e8b7cc47397372db683cbsalomon@google.com 4226918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com GrGLuint fDefaultVertexArrayBoundIndexBufferID; 4236918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com bool fDefaultVertexArrayBoundIndexBufferIDIsValid; 4246918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com // We return a non-const pointer to this from bindArrayAndBuffersToDraw when vertex array 0 4256918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com // is bound. However, this class is internal to GrGpuGL and this object never leaks out of 4266918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com // GrGpuGL. 4276918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com GrGLAttribArrayState fDefaultVertexArrayAttribState; 428880b8fcf255e67a15687e8b7cc47397372db683cbsalomon@google.com 4296918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com // This is used when we're using a core profile and the vertices are in a VBO. 4306918d482d64f045a4c980b2fb267bc939953638ebsalomon@google.com GrGLVertexArray* fVBOVertexArray; 431492093951ae2a7d7c14aa22f48faa8942f045cafbsalomon@google.com } fHWGeometryState; 4325782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com 433a4d8fc24736e77fd8c588c4be63e3c15a4154860bsalomon@google.com struct { 434a4d8fc24736e77fd8c588c4be63e3c15a4154860bsalomon@google.com GrBlendCoeff fSrcCoeff; 435a4d8fc24736e77fd8c588c4be63e3c15a4154860bsalomon@google.com GrBlendCoeff fDstCoeff; 436a4d8fc24736e77fd8c588c4be63e3c15a4154860bsalomon@google.com GrColor fConstColor; 437a4d8fc24736e77fd8c588c4be63e3c15a4154860bsalomon@google.com bool fConstColorValid; 438a4d8fc24736e77fd8c588c4be63e3c15a4154860bsalomon@google.com TriState fEnabled; 439a4d8fc24736e77fd8c588c4be63e3c15a4154860bsalomon@google.com 440a4d8fc24736e77fd8c588c4be63e3c15a4154860bsalomon@google.com void invalidate() { 44147059542e7aa153926377456a6c611e55c8e428cbsalomon@google.com fSrcCoeff = kInvalid_GrBlendCoeff; 44247059542e7aa153926377456a6c611e55c8e428cbsalomon@google.com fDstCoeff = kInvalid_GrBlendCoeff; 443a4d8fc24736e77fd8c588c4be63e3c15a4154860bsalomon@google.com fConstColorValid = false; 444a4d8fc24736e77fd8c588c4be63e3c15a4154860bsalomon@google.com fEnabled = kUnknown_TriState; 445a4d8fc24736e77fd8c588c4be63e3c15a4154860bsalomon@google.com } 446a4d8fc24736e77fd8c588c4be63e3c15a4154860bsalomon@google.com } fHWBlendState; 447a4d8fc24736e77fd8c588c4be63e3c15a4154860bsalomon@google.com 4484d5f3fe581a50ed5d57121d09faa8e613e47b16dbsalomon@google.com struct { 4494d5f3fe581a50ed5d57121d09faa8e613e47b16dbsalomon@google.com TriState fMSAAEnabled; 4504d5f3fe581a50ed5d57121d09faa8e613e47b16dbsalomon@google.com TriState fSmoothLineEnabled; 4514d5f3fe581a50ed5d57121d09faa8e613e47b16dbsalomon@google.com void invalidate() { 4524d5f3fe581a50ed5d57121d09faa8e613e47b16dbsalomon@google.com fMSAAEnabled = kUnknown_TriState; 4534d5f3fe581a50ed5d57121d09faa8e613e47b16dbsalomon@google.com fSmoothLineEnabled = kUnknown_TriState; 4544d5f3fe581a50ed5d57121d09faa8e613e47b16dbsalomon@google.com } 4554d5f3fe581a50ed5d57121d09faa8e613e47b16dbsalomon@google.com } fHWAAState; 4564d5f3fe581a50ed5d57121d09faa8e613e47b16dbsalomon@google.com 457ded4f4b163f5aa19c22c871178c55ecb34623846bsalomon@google.com 45846fbfe0cd1bbe60fd15ce52e784f5d51450ff5fdcommit-bot@chromium.org GrGLProgram::MatrixState fHWProjectionMatrixState; 4596a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com 4606a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com GrStencilSettings fHWStencilSettings; 4616a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com TriState fHWStencilTestEnabled; 462c4dc0ad8e252a7e30d19b47d3d0d9f2c69faf854commit-bot@chromium.org GrStencilSettings fHWPathStencilSettings; 463457b8a3b49d5cf946674bbaa959a86bd137bf582bsalomon@google.com 4646a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com GrDrawState::DrawFace fHWDrawFace; 4656a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com TriState fHWWriteToColor; 4666a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com TriState fHWDitherEnabled; 4676a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com GrRenderTarget* fHWBoundRenderTarget; 468a15f7e5b96ee3d71fdbcb4f9cf02f6a09b4b11accommit-bot@chromium.org SkTArray<GrTexture*, true> fHWBoundTextures; 4696b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org 4700a6fe71f1bc0e601b41b7ae6d28b8c96a2c41116commit-bot@chromium.org struct PathTexGenData { 4716b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org GrGLenum fMode; 4726b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org GrGLint fNumComponents; 4736b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org GrGLfloat fCoefficients[3 * 3]; 4746b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org }; 4750a6fe71f1bc0e601b41b7ae6d28b8c96a2c41116commit-bot@chromium.org int fHWActivePathTexGenSets; 4760a6fe71f1bc0e601b41b7ae6d28b8c96a2c41116commit-bot@chromium.org SkTArray<PathTexGenData, true> fHWPathTexGenSettings; 477492093951ae2a7d7c14aa22f48faa8942f045cafbsalomon@google.com ///@} 478978c8c61ba1e792567e9d8e6629c2c4ee59727b7bsalomon@google.com 479fe6765293f9f16707a8f246f44c006c6e9abd33ebsalomon@google.com // we record what stencil format worked last time to hopefully exit early 480fe6765293f9f16707a8f246f44c006c6e9abd33ebsalomon@google.com // from our loop that tries stencil formats and calls check fb status. 481fe6765293f9f16707a8f246f44c006c6e9abd33ebsalomon@google.com int fLastSuccessfulStencilFmtIdx; 482fe6765293f9f16707a8f246f44c006c6e9abd33ebsalomon@google.com 483511923443facc611b3735b4688342c12071feaa0cdalton SkAutoTDelete<GrGLNameAllocator> fPathNameAllocator; 484511923443facc611b3735b4688342c12071feaa0cdalton 485ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com typedef GrGpu INHERITED; 486ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com}; 487ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 488a7f84e150cb9e821267a8ca9e59c1ae9a3cfa300bsalomon@google.com#endif 489