GrContext.h revision 56ce48ade325f6f49acb0da31d6252806e4ed7ef
1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com/* 2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2010 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. 627847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com */ 727847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com 827847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com#ifndef GrContext_DEFINED 927847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com#define GrContext_DEFINED 1027847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com 11a2d71482db8b6d752a51c96da74768d7dfc27932robertphillips@google.com#include "GrClipData.h" 12a0b40280a49a8a43af7929ead3b3489951c58501commit-bot@chromium.org#include "GrColor.h" 13288d9549b42a4eb934e814790f2b7a81f017a9c5bsalomon@google.com#include "GrPaint.h" 1445a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com#include "GrPathRendererChain.h" 15fd03d4a829efe2d77a712fd991927c55f59a2ffecommit-bot@chromium.org#include "GrPoint.h" 16fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com#include "GrRenderTarget.h" 17288d9549b42a4eb934e814790f2b7a81f017a9c5bsalomon@google.com#include "GrTexture.h" 18a0b40280a49a8a43af7929ead3b3489951c58501commit-bot@chromium.org#include "SkMatrix.h" 19a0b40280a49a8a43af7929ead3b3489951c58501commit-bot@chromium.org#include "SkTypes.h" 2027847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com 21bfe2b9d3a290d0153b82617cd6b65a4814fe89e3jvanverth@google.comclass GrAARectRenderer; 223b4dd90282932c9cd695d13f3876f98c9c6d6d5esenorblanco@chromium.orgclass GrAutoScratchTexture; 2310e04bf1c5025389d999f22467405782e9f9ffccbsalomon@google.comclass GrDrawState; 24583a1e38503ebd57ba9bd39a3fabe89bead8e76cbsalomon@google.comclass GrDrawTarget; 25a469c28c3c16214733a25201a286970f57b3d944bsalomon@google.comclass GrEffect; 2627847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.comclass GrFontCache; 2705ef510389950e1ae8dcba40e41e001db771b12dbsalomon@google.comclass GrGpu; 28583a1e38503ebd57ba9bd39a3fabe89bead8e76cbsalomon@google.comclass GrIndexBuffer; 2927847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.comclass GrIndexBufferAllocPool; 3027847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.comclass GrInOrderDrawBuffer; 3181312830ef73420efdc4821feb7c2d6fd9152af8commit-bot@chromium.orgclass GrOvalRenderer; 32583a1e38503ebd57ba9bd39a3fabe89bead8e76cbsalomon@google.comclass GrPathRenderer; 3350398bf7f1953e640e5529616e710cf540799731bsalomon@google.comclass GrResourceEntry; 3450398bf7f1953e640e5529616e710cf540799731bsalomon@google.comclass GrResourceCache; 35558a75bcb323c03dd7482555c7214062a363276fbsalomon@google.comclass GrStencilBuffer; 3678a1078f17f4f0ae63415298517262a64f706af6commit-bot@chromium.orgclass GrTestTarget; 37288d9549b42a4eb934e814790f2b7a81f017a9c5bsalomon@google.comclass GrTextureParams; 38583a1e38503ebd57ba9bd39a3fabe89bead8e76cbsalomon@google.comclass GrVertexBuffer; 3950398bf7f1953e640e5529616e710cf540799731bsalomon@google.comclass GrVertexBufferAllocPool; 4072176b2d38db005863a54e3dd6657bbabd068bb6robertphillips@google.comclass GrSoftwarePathRenderer; 415f74cf8c49701f514b69dc6f1a8b5c0ffd78af0asugoi@google.comclass SkStrokeRec; 4250398bf7f1953e640e5529616e710cf540799731bsalomon@google.com 43a4de8c257ea0be8ff7081f645249b6afe5c48e7ecommit-bot@chromium.orgclass SK_API GrContext : public SkRefCnt { 4427847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.compublic: 45fa35e3ddcc9d130ce87c927218bdf27879c38711reed@google.com SK_DECLARE_INST_COUNT(GrContext) 46fa35e3ddcc9d130ce87c927218bdf27879c38711reed@google.com 4727847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com /** 4816e3ddea6a80972aced04b21b1d66377fa95e7c7bsalomon@google.com * Creates a GrContext for a backend context. 4927847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com */ 5016e3ddea6a80972aced04b21b1d66377fa95e7c7bsalomon@google.com static GrContext* Create(GrBackend, GrBackendContext); 5127847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com 52c0af3173314e227611d8c5541ef2deee0052d412bsalomon@google.com /** 53c0af3173314e227611d8c5541ef2deee0052d412bsalomon@google.com * Returns the number of GrContext instances for the current thread. 54c0af3173314e227611d8c5541ef2deee0052d412bsalomon@google.com */ 55c0af3173314e227611d8c5541ef2deee0052d412bsalomon@google.com static int GetThreadInstanceCount(); 56c0af3173314e227611d8c5541ef2deee0052d412bsalomon@google.com 5727847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com virtual ~GrContext(); 5827847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com 5927847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com /** 6027847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * The GrContext normally assumes that no outsider is setting state 6127847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * within the underlying 3D API's context/device/whatever. This call informs 6227847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * the context that the state was modified and it should resend. Shouldn't 6327847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * be called frequently for good performance. 640a208a117b2d7f2c2231aa357f1db4864dbdcba3bsalomon@google.com * The flag bits, state, is dpendent on which backend is used by the 650a208a117b2d7f2c2231aa357f1db4864dbdcba3bsalomon@google.com * context, either GL or D3D (possible in future). 6627847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com */ 670a208a117b2d7f2c2231aa357f1db4864dbdcba3bsalomon@google.com void resetContext(uint32_t state = kAll_GrBackendState); 6827847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com 698fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com /** 70cdb426d55a4bc4dae4f6d4f23e6994762950fdc3robertphillips@google.com * Callback function to allow classes to cleanup on GrContext destruction. 71cdb426d55a4bc4dae4f6d4f23e6994762950fdc3robertphillips@google.com * The 'info' field is filled in with the 'info' passed to addCleanUp. 72cdb426d55a4bc4dae4f6d4f23e6994762950fdc3robertphillips@google.com */ 73cdb426d55a4bc4dae4f6d4f23e6994762950fdc3robertphillips@google.com typedef void (*PFCleanUpFunc)(const GrContext* context, void* info); 74cdb426d55a4bc4dae4f6d4f23e6994762950fdc3robertphillips@google.com 75cdb426d55a4bc4dae4f6d4f23e6994762950fdc3robertphillips@google.com /** 76cdb426d55a4bc4dae4f6d4f23e6994762950fdc3robertphillips@google.com * Add a function to be called from within GrContext's destructor. 77cdb426d55a4bc4dae4f6d4f23e6994762950fdc3robertphillips@google.com * This gives classes a chance to free resources held on a per context basis. 78cdb426d55a4bc4dae4f6d4f23e6994762950fdc3robertphillips@google.com * The 'info' parameter will be stored and passed to the callback function. 79cdb426d55a4bc4dae4f6d4f23e6994762950fdc3robertphillips@google.com */ 80cdb426d55a4bc4dae4f6d4f23e6994762950fdc3robertphillips@google.com void addCleanUp(PFCleanUpFunc cleanUp, void* info) { 81cdb426d55a4bc4dae4f6d4f23e6994762950fdc3robertphillips@google.com CleanUpData* entry = fCleanUpData.push(); 82cdb426d55a4bc4dae4f6d4f23e6994762950fdc3robertphillips@google.com 83cdb426d55a4bc4dae4f6d4f23e6994762950fdc3robertphillips@google.com entry->fFunc = cleanUp; 84cdb426d55a4bc4dae4f6d4f23e6994762950fdc3robertphillips@google.com entry->fInfo = info; 85cdb426d55a4bc4dae4f6d4f23e6994762950fdc3robertphillips@google.com } 86cdb426d55a4bc4dae4f6d4f23e6994762950fdc3robertphillips@google.com 87cdb426d55a4bc4dae4f6d4f23e6994762950fdc3robertphillips@google.com /** 881e269b5a08610da13c3aee23809bb45b17e7b663bsalomon@google.com * Abandons all GPU resources, assumes 3D API state is unknown. Call this 898fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com * if you have lost the associated GPU context, and thus internal texture, 908fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com * buffer, etc. references/IDs are now invalid. Should be called even when 918fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com * GrContext is no longer going to be used for two reasons: 928fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com * 1) ~GrContext will not try to free the objects in the 3D API. 938fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com * 2) If you've created GrResources that outlive the GrContext they will 948fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com * be marked as invalid (GrResource::isValid()) and won't attempt to 958fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com * free their underlying resource in the 3D API. 968fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com * Content drawn since the last GrContext::flush() may be lost. 978fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com */ 988fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com void contextLost(); 9927847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com 10027847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com /** 10153a5584bb0094e19c39a66cec7f346aad04ecac4junov@google.com * Similar to contextLost, but makes no attempt to reset state. 10253a5584bb0094e19c39a66cec7f346aad04ecac4junov@google.com * Use this method when GrContext destruction is pending, but 10353a5584bb0094e19c39a66cec7f346aad04ecac4junov@google.com * the graphics context is destroyed first. 10453a5584bb0094e19c39a66cec7f346aad04ecac4junov@google.com */ 10553a5584bb0094e19c39a66cec7f346aad04ecac4junov@google.com void contextDestroyed(); 10653a5584bb0094e19c39a66cec7f346aad04ecac4junov@google.com 10753a5584bb0094e19c39a66cec7f346aad04ecac4junov@google.com /** 1081e269b5a08610da13c3aee23809bb45b17e7b663bsalomon@google.com * Frees GPU created by the context. Can be called to reduce GPU memory 1098fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com * pressure. 11027847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com */ 1118fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com void freeGpuResources(); 1128fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com 11307fc0d178e20f74a88dd78384f817b53204e625fbsalomon@google.com /** 11407fc0d178e20f74a88dd78384f817b53204e625fbsalomon@google.com * Returns the number of bytes of GPU memory hosted by the texture cache. 11507fc0d178e20f74a88dd78384f817b53204e625fbsalomon@google.com */ 11607fc0d178e20f74a88dd78384f817b53204e625fbsalomon@google.com size_t getGpuTextureCacheBytes() const; 11707fc0d178e20f74a88dd78384f817b53204e625fbsalomon@google.com 1188fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com /////////////////////////////////////////////////////////////////////////// 1198fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com // Textures 12027847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com 12127847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com /** 12295ed55adc6b8f0cee063c2cf2e14782773b0087fbsalomon@google.com * Creates a new entry, based on the specified key and texture and returns it. The caller owns a 12395ed55adc6b8f0cee063c2cf2e14782773b0087fbsalomon@google.com * ref on the returned texture which must be balanced by a call to unref. 1241fadb20c50c2302565f73ae12057a6f5d22192c7bsalomon@google.com * 1251e269b5a08610da13c3aee23809bb45b17e7b663bsalomon@google.com * @param params The texture params used to draw a texture may help determine 126b8670998a59d305cd22a3c0cbdc6e075b0a37a6ebsalomon@google.com * the cache entry used. (e.g. different versions may exist 127b8670998a59d305cd22a3c0cbdc6e075b0a37a6ebsalomon@google.com * for different wrap modes on GPUs with limited NPOT 128b8670998a59d305cd22a3c0cbdc6e075b0a37a6ebsalomon@google.com * texture support). NULL implies clamp wrap modes. 1291fadb20c50c2302565f73ae12057a6f5d22192c7bsalomon@google.com * @param desc Description of the texture properties. 1300797c2cceadd7dfc2e7f9efa30b611d18efcdcddbsalomon@google.com * @param cacheID Cache-specific properties (e.g., texture gen ID) 1311fadb20c50c2302565f73ae12057a6f5d22192c7bsalomon@google.com * @param srcData Pointer to the pixel values. 1321fadb20c50c2302565f73ae12057a6f5d22192c7bsalomon@google.com * @param rowBytes The number of bytes between rows of the texture. Zero 1331fadb20c50c2302565f73ae12057a6f5d22192c7bsalomon@google.com * implies tightly packed rows. 13450a3043194cf278a74ff51c33c6cdb52cbe1f8f9commit-bot@chromium.org * @param cacheKey (optional) If non-NULL, we'll write the cache key we used to cacheKey. 1351fadb20c50c2302565f73ae12057a6f5d22192c7bsalomon@google.com */ 1369fbcad0f00d7098574cf3394a812c9d845c9cc5brobertphillips@google.com GrTexture* createTexture(const GrTextureParams* params, 1379fbcad0f00d7098574cf3394a812c9d845c9cc5brobertphillips@google.com const GrTextureDesc& desc, 1380797c2cceadd7dfc2e7f9efa30b611d18efcdcddbsalomon@google.com const GrCacheID& cacheID, 13950a3043194cf278a74ff51c33c6cdb52cbe1f8f9commit-bot@chromium.org void* srcData, 14050a3043194cf278a74ff51c33c6cdb52cbe1f8f9commit-bot@chromium.org size_t rowBytes, 14150a3043194cf278a74ff51c33c6cdb52cbe1f8f9commit-bot@chromium.org GrResourceKey* cacheKey = NULL); 1421fadb20c50c2302565f73ae12057a6f5d22192c7bsalomon@google.com 1431fadb20c50c2302565f73ae12057a6f5d22192c7bsalomon@google.com /** 14495ed55adc6b8f0cee063c2cf2e14782773b0087fbsalomon@google.com * Search for an entry based on key and dimensions. If found, ref it and return it. The return 14595ed55adc6b8f0cee063c2cf2e14782773b0087fbsalomon@google.com * value will be NULL if not found. The caller must balance with a call to unref. 1461fadb20c50c2302565f73ae12057a6f5d22192c7bsalomon@google.com * 147b8670998a59d305cd22a3c0cbdc6e075b0a37a6ebsalomon@google.com * @param desc Description of the texture properties. 1480797c2cceadd7dfc2e7f9efa30b611d18efcdcddbsalomon@google.com * @param cacheID Cache-specific properties (e.g., texture gen ID) 1491e269b5a08610da13c3aee23809bb45b17e7b663bsalomon@google.com * @param params The texture params used to draw a texture may help determine 150b8670998a59d305cd22a3c0cbdc6e075b0a37a6ebsalomon@google.com * the cache entry used. (e.g. different versions may exist 151b8670998a59d305cd22a3c0cbdc6e075b0a37a6ebsalomon@google.com * for different wrap modes on GPUs with limited NPOT 152b8670998a59d305cd22a3c0cbdc6e075b0a37a6ebsalomon@google.com * texture support). NULL implies clamp wrap modes. 15350398bf7f1953e640e5529616e710cf540799731bsalomon@google.com */ 15495ed55adc6b8f0cee063c2cf2e14782773b0087fbsalomon@google.com GrTexture* findAndRefTexture(const GrTextureDesc& desc, 15595ed55adc6b8f0cee063c2cf2e14782773b0087fbsalomon@google.com const GrCacheID& cacheID, 15695ed55adc6b8f0cee063c2cf2e14782773b0087fbsalomon@google.com const GrTextureParams* params); 157fb30951cd9346a7a2d36e7d5f81f9e7ee792b669bsalomon@google.com /** 158fb30951cd9346a7a2d36e7d5f81f9e7ee792b669bsalomon@google.com * Determines whether a texture is in the cache. If the texture is found it 159fb30951cd9346a7a2d36e7d5f81f9e7ee792b669bsalomon@google.com * will not be locked or returned. This call does not affect the priority of 160fb30951cd9346a7a2d36e7d5f81f9e7ee792b669bsalomon@google.com * the texture for deletion. 161fb30951cd9346a7a2d36e7d5f81f9e7ee792b669bsalomon@google.com */ 16275b3c9633cb9a594dab0ccf51dab1e694c149a18robertphillips@google.com bool isTextureInCache(const GrTextureDesc& desc, 1630797c2cceadd7dfc2e7f9efa30b611d18efcdcddbsalomon@google.com const GrCacheID& cacheID, 164b8670998a59d305cd22a3c0cbdc6e075b0a37a6ebsalomon@google.com const GrTextureParams* params) const; 16550398bf7f1953e640e5529616e710cf540799731bsalomon@google.com 16650398bf7f1953e640e5529616e710cf540799731bsalomon@google.com /** 16750398bf7f1953e640e5529616e710cf540799731bsalomon@google.com * Enum that determines how closely a returned scratch texture must match 16850398bf7f1953e640e5529616e710cf540799731bsalomon@google.com * a provided GrTextureDesc. 16950398bf7f1953e640e5529616e710cf540799731bsalomon@google.com */ 17050398bf7f1953e640e5529616e710cf540799731bsalomon@google.com enum ScratchTexMatch { 17150398bf7f1953e640e5529616e710cf540799731bsalomon@google.com /** 17250398bf7f1953e640e5529616e710cf540799731bsalomon@google.com * Finds a texture that exactly matches the descriptor. 17350398bf7f1953e640e5529616e710cf540799731bsalomon@google.com */ 17450398bf7f1953e640e5529616e710cf540799731bsalomon@google.com kExact_ScratchTexMatch, 17550398bf7f1953e640e5529616e710cf540799731bsalomon@google.com /** 17650398bf7f1953e640e5529616e710cf540799731bsalomon@google.com * Finds a texture that approximately matches the descriptor. Will be 17750398bf7f1953e640e5529616e710cf540799731bsalomon@google.com * at least as large in width and height as desc specifies. If desc 17850398bf7f1953e640e5529616e710cf540799731bsalomon@google.com * specifies that texture is a render target then result will be a 17950398bf7f1953e640e5529616e710cf540799731bsalomon@google.com * render target. If desc specifies a render target and doesn't set the 18050398bf7f1953e640e5529616e710cf540799731bsalomon@google.com * no stencil flag then result will have a stencil. Format and aa level 18150398bf7f1953e640e5529616e710cf540799731bsalomon@google.com * will always match. 18250398bf7f1953e640e5529616e710cf540799731bsalomon@google.com */ 18350398bf7f1953e640e5529616e710cf540799731bsalomon@google.com kApprox_ScratchTexMatch 18450398bf7f1953e640e5529616e710cf540799731bsalomon@google.com }; 18527847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com 18627847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com /** 187fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com * Returns a texture matching the desc. It's contents are unknown. Subsequent 188fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com * requests with the same descriptor are not guaranteed to return the same 189fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com * texture. The same texture is guaranteed not be returned again until it is 19095ed55adc6b8f0cee063c2cf2e14782773b0087fbsalomon@google.com * unlocked. Call must be balanced with an unlockTexture() call. The caller 19195ed55adc6b8f0cee063c2cf2e14782773b0087fbsalomon@google.com * owns a ref on the returned texture and must balance with a call to unref. 192a39f404c87e9957947e3341e46056e4f589c91adbsalomon@google.com * 193a39f404c87e9957947e3341e46056e4f589c91adbsalomon@google.com * Textures created by createAndLockTexture() hide the complications of 194fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com * tiling non-power-of-two textures on APIs that don't support this (e.g. 1951e269b5a08610da13c3aee23809bb45b17e7b663bsalomon@google.com * unextended GLES2). Tiling a NPOT texture created by lockScratchTexture on 196a39f404c87e9957947e3341e46056e4f589c91adbsalomon@google.com * such an API will create gaps in the tiling pattern. This includes clamp 197a39f404c87e9957947e3341e46056e4f589c91adbsalomon@google.com * mode. (This may be addressed in a future update.) 19827847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com */ 19995ed55adc6b8f0cee063c2cf2e14782773b0087fbsalomon@google.com GrTexture* lockAndRefScratchTexture(const GrTextureDesc&, ScratchTexMatch match); 200b5b3168a645802f66233234a06dd5a3764f18018bsalomon@google.com 201b5b3168a645802f66233234a06dd5a3764f18018bsalomon@google.com /** 2020797c2cceadd7dfc2e7f9efa30b611d18efcdcddbsalomon@google.com * When done with an entry, call unlockScratchTexture(entry) on it, which returns 20395ed55adc6b8f0cee063c2cf2e14782773b0087fbsalomon@google.com * it to the cache, where it may be purged. This does not unref the texture. 20427847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com */ 2059fbcad0f00d7098574cf3394a812c9d845c9cc5brobertphillips@google.com void unlockScratchTexture(GrTexture* texture); 20627847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com 20727847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com /** 20850a035ddbb068446645b0978f4c092dec87a1a02robertphillips@google.com * This method should be called whenever a GrTexture is unreffed or 20950a035ddbb068446645b0978f4c092dec87a1a02robertphillips@google.com * switched from exclusive to non-exclusive. This 21050a035ddbb068446645b0978f4c092dec87a1a02robertphillips@google.com * gives the resource cache a chance to discard unneeded textures. 2119fbcad0f00d7098574cf3394a812c9d845c9cc5brobertphillips@google.com * Note: this entry point will be removed once totally ref-driven 2129fbcad0f00d7098574cf3394a812c9d845c9cc5brobertphillips@google.com * cache maintenance is implemented 21350a035ddbb068446645b0978f4c092dec87a1a02robertphillips@google.com */ 21450a035ddbb068446645b0978f4c092dec87a1a02robertphillips@google.com void purgeCache(); 21550a035ddbb068446645b0978f4c092dec87a1a02robertphillips@google.com 21650a035ddbb068446645b0978f4c092dec87a1a02robertphillips@google.com /** 21727847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * Creates a texture that is outside the cache. Does not count against 21827847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * cache's budget. 21927847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com */ 22075b3c9633cb9a594dab0ccf51dab1e694c149a18robertphillips@google.com GrTexture* createUncachedTexture(const GrTextureDesc& desc, 22127847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com void* srcData, 22227847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com size_t rowBytes); 22327847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com 22427847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com /** 225b8670998a59d305cd22a3c0cbdc6e075b0a37a6ebsalomon@google.com * Returns true if the specified use of an indexed texture is supported. 226b8670998a59d305cd22a3c0cbdc6e075b0a37a6ebsalomon@google.com * Support may depend upon whether the texture params indicate that the 227b8670998a59d305cd22a3c0cbdc6e075b0a37a6ebsalomon@google.com * texture will be tiled. Passing NULL for the texture params indicates 228b8670998a59d305cd22a3c0cbdc6e075b0a37a6ebsalomon@google.com * clamp mode. 22927847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com */ 230b8670998a59d305cd22a3c0cbdc6e075b0a37a6ebsalomon@google.com bool supportsIndex8PixelConfig(const GrTextureParams*, 2311f221a70214fa1ab87b8a32dd66facf485f318eebsalomon@google.com int width, 2321f221a70214fa1ab87b8a32dd66facf485f318eebsalomon@google.com int height) const; 23327847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com 23427847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com /** 23507fc0d178e20f74a88dd78384f817b53204e625fbsalomon@google.com * Return the current texture cache limits. 23607fc0d178e20f74a88dd78384f817b53204e625fbsalomon@google.com * 23707fc0d178e20f74a88dd78384f817b53204e625fbsalomon@google.com * @param maxTextures If non-null, returns maximum number of textures that 23807fc0d178e20f74a88dd78384f817b53204e625fbsalomon@google.com * can be held in the cache. 23907fc0d178e20f74a88dd78384f817b53204e625fbsalomon@google.com * @param maxTextureBytes If non-null, returns maximum number of bytes of 24007fc0d178e20f74a88dd78384f817b53204e625fbsalomon@google.com * texture memory that can be held in the cache. 24127847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com */ 24207fc0d178e20f74a88dd78384f817b53204e625fbsalomon@google.com void getTextureCacheLimits(int* maxTextures, size_t* maxTextureBytes) const; 24327847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com 24427847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com /** 24507fc0d178e20f74a88dd78384f817b53204e625fbsalomon@google.com * Specify the texture cache limits. If the current cache exceeds either 24607fc0d178e20f74a88dd78384f817b53204e625fbsalomon@google.com * of these, it will be purged (LRU) to keep the cache within these limits. 24727847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * 24807fc0d178e20f74a88dd78384f817b53204e625fbsalomon@google.com * @param maxTextures The maximum number of textures that can be held in 24907fc0d178e20f74a88dd78384f817b53204e625fbsalomon@google.com * the cache. 25027847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * @param maxTextureBytes The maximum number of bytes of texture memory 25127847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * that can be held in the cache. 25227847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com */ 25307fc0d178e20f74a88dd78384f817b53204e625fbsalomon@google.com void setTextureCacheLimits(int maxTextures, size_t maxTextureBytes); 25427847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com 25527847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com /** 2561e269b5a08610da13c3aee23809bb45b17e7b663bsalomon@google.com * Return the max width or height of a texture supported by the current GPU. 25727847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com */ 258919583674bd5daeb60327c0bc1ce8aaa80d54e13bsalomon@google.com int getMaxTextureSize() const; 259919583674bd5daeb60327c0bc1ce8aaa80d54e13bsalomon@google.com 26044a91dcf2542c2aa93f159ebbb5bf813ae7362c0robertphillips@google.com /** 261956b310f13c7412c035406c658ff16ca85eac656skia.committer@gmail.com * Temporarily override the true max texture size. Note: an override 26244a91dcf2542c2aa93f159ebbb5bf813ae7362c0robertphillips@google.com * larger then the true max texture size will have no effect. 26344a91dcf2542c2aa93f159ebbb5bf813ae7362c0robertphillips@google.com * This entry point is mainly meant for testing texture size dependent 26444a91dcf2542c2aa93f159ebbb5bf813ae7362c0robertphillips@google.com * features and is only available if defined outside of Skia (see 26544a91dcf2542c2aa93f159ebbb5bf813ae7362c0robertphillips@google.com * bleed GM. 26644a91dcf2542c2aa93f159ebbb5bf813ae7362c0robertphillips@google.com */ 26744a91dcf2542c2aa93f159ebbb5bf813ae7362c0robertphillips@google.com void setMaxTextureSizeOverride(int maxTextureSizeOverride); 26844a91dcf2542c2aa93f159ebbb5bf813ae7362c0robertphillips@google.com 26927847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com /////////////////////////////////////////////////////////////////////////// 27027847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com // Render targets 27127847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com 27227847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com /** 2735877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * Sets the render target. 274bb6a3178c3e79c8549b332e4ce84c64b59964f1ecommit-bot@chromium.org * @param target the render target to set. 2755877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com */ 276bb6a3178c3e79c8549b332e4ce84c64b59964f1ecommit-bot@chromium.org void setRenderTarget(GrRenderTarget* target) { 277bb6a3178c3e79c8549b332e4ce84c64b59964f1ecommit-bot@chromium.org fRenderTarget.reset(SkSafeRef(target)); 278bb6a3178c3e79c8549b332e4ce84c64b59964f1ecommit-bot@chromium.org } 2795877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com 2805877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com /** 2815877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * Gets the current render target. 282bb6a3178c3e79c8549b332e4ce84c64b59964f1ecommit-bot@chromium.org * @return the currently bound render target. 2835877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com */ 284bb6a3178c3e79c8549b332e4ce84c64b59964f1ecommit-bot@chromium.org const GrRenderTarget* getRenderTarget() const { return fRenderTarget.get(); } 285bb6a3178c3e79c8549b332e4ce84c64b59964f1ecommit-bot@chromium.org GrRenderTarget* getRenderTarget() { return fRenderTarget.get(); } 2865877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com 287f69a11b5c5dc5ae02489dfe7ca6432d641b9f121robertphillips@google.com GrAARectRenderer* getAARectRenderer() { return fAARectRenderer; } 288f69a11b5c5dc5ae02489dfe7ca6432d641b9f121robertphillips@google.com 28999a5ac0b67a14048a1db3f429878775854d29397robertphillips@google.com /** 29099a5ac0b67a14048a1db3f429878775854d29397robertphillips@google.com * Can the provided configuration act as a color render target? 29199a5ac0b67a14048a1db3f429878775854d29397robertphillips@google.com */ 2926b7938f9cb250086a7c6325cf31576f894ca4a1bcommit-bot@chromium.org bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const; 29399a5ac0b67a14048a1db3f429878775854d29397robertphillips@google.com 2948a70eef71cf369803e97ffea786f43f944de758ebsalomon@google.com /** 2958a70eef71cf369803e97ffea786f43f944de758ebsalomon@google.com * Return the max width or height of a render target supported by the 2968a70eef71cf369803e97ffea786f43f944de758ebsalomon@google.com * current GPU. 2978a70eef71cf369803e97ffea786f43f944de758ebsalomon@google.com */ 2988a70eef71cf369803e97ffea786f43f944de758ebsalomon@google.com int getMaxRenderTargetSize() const; 2998a70eef71cf369803e97ffea786f43f944de758ebsalomon@google.com 3008a70eef71cf369803e97ffea786f43f944de758ebsalomon@google.com /** 3018a70eef71cf369803e97ffea786f43f944de758ebsalomon@google.com * Returns the max sample count for a render target. It will be 0 if MSAA 3028a70eef71cf369803e97ffea786f43f944de758ebsalomon@google.com * is not supported. 3038a70eef71cf369803e97ffea786f43f944de758ebsalomon@google.com */ 3048a70eef71cf369803e97ffea786f43f944de758ebsalomon@google.com int getMaxSampleCount() const; 3058a70eef71cf369803e97ffea786f43f944de758ebsalomon@google.com 3065877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com /////////////////////////////////////////////////////////////////////////// 30716e3ddea6a80972aced04b21b1d66377fa95e7c7bsalomon@google.com // Backend Surfaces 3085877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com 3095877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com /** 310e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * Wraps an existing texture with a GrTexture object. 311e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * 312e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * OpenGL: if the object is a texture Gr may change its GL texture params 313e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * when it is drawn. 314e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * 315e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * @param desc description of the object to create. 316e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * 317e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * @return GrTexture object or NULL on failure. 318e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com */ 31916e3ddea6a80972aced04b21b1d66377fa95e7c7bsalomon@google.com GrTexture* wrapBackendTexture(const GrBackendTextureDesc& desc); 320e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com 321e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com /** 322e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * Wraps an existing render target with a GrRenderTarget object. It is 32316e3ddea6a80972aced04b21b1d66377fa95e7c7bsalomon@google.com * similar to wrapBackendTexture but can be used to draw into surfaces 324e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * that are not also textures (e.g. FBO 0 in OpenGL, or an MSAA buffer that 325e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * the client will resolve to a texture). 326e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * 327e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * @param desc description of the object to create. 328e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * 329e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * @return GrTexture object or NULL on failure. 330e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com */ 33116e3ddea6a80972aced04b21b1d66377fa95e7c7bsalomon@google.com GrRenderTarget* wrapBackendRenderTarget(const GrBackendRenderTargetDesc& desc); 332e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com 33327847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com /////////////////////////////////////////////////////////////////////////// 33427847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com // Matrix state 33527847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com 33627847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com /** 33727847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * Gets the current transformation matrix. 33827847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * @return the current matrix. 33927847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com */ 340bb6a3178c3e79c8549b332e4ce84c64b59964f1ecommit-bot@chromium.org const SkMatrix& getMatrix() const { return fViewMatrix; } 34127847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com 34227847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com /** 34327847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * Sets the transformation matrix. 34427847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * @param m the matrix to set. 34527847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com */ 346bb6a3178c3e79c8549b332e4ce84c64b59964f1ecommit-bot@chromium.org void setMatrix(const SkMatrix& m) { fViewMatrix = m; } 34727847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com 34827847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com /** 3490f11e1ab5b6e53f6176dde2dbb25a8e3ae34858fbsalomon@google.com * Sets the current transformation matrix to identity. 3500f11e1ab5b6e53f6176dde2dbb25a8e3ae34858fbsalomon@google.com */ 351bb6a3178c3e79c8549b332e4ce84c64b59964f1ecommit-bot@chromium.org void setIdentityMatrix() { fViewMatrix.reset(); } 3520f11e1ab5b6e53f6176dde2dbb25a8e3ae34858fbsalomon@google.com 3530f11e1ab5b6e53f6176dde2dbb25a8e3ae34858fbsalomon@google.com /** 35427847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * Concats the current matrix. The passed matrix is applied before the 35527847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * current matrix. 35627847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * @param m the matrix to concat. 35727847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com */ 358bb6a3178c3e79c8549b332e4ce84c64b59964f1ecommit-bot@chromium.org void concatMatrix(const SkMatrix& m) { fViewMatrix.preConcat(m); } 35927847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com 36027847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com 36127847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com /////////////////////////////////////////////////////////////////////////// 36227847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com // Clip state 36327847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com /** 36427847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * Gets the current clip. 36527847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * @return the current clip. 36627847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com */ 367bb6a3178c3e79c8549b332e4ce84c64b59964f1ecommit-bot@chromium.org const GrClipData* getClip() const { return fClip; } 36827847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com 36927847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com /** 37027847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * Sets the clip. 371beb1af78d016d2700c350487a383c6bcfa7e2e20robertphillips@google.com * @param clipData the clip to set. 37227847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com */ 373bb6a3178c3e79c8549b332e4ce84c64b59964f1ecommit-bot@chromium.org void setClip(const GrClipData* clipData) { fClip = clipData; } 37427847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com 37527847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com /////////////////////////////////////////////////////////////////////////// 37627847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com // Draws 37727847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com 37827847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com /** 3796aa25c3f555dc2a6711365d14279db3ec909e064bsalomon@google.com * Clear the entire or rect of the render target, ignoring any clips. 3806aa25c3f555dc2a6711365d14279db3ec909e064bsalomon@google.com * @param rect the rect to clear or the whole thing if rect is NULL. 3816aa25c3f555dc2a6711365d14279db3ec909e064bsalomon@google.com * @param color the color to clear to. 38256ce48ade325f6f49acb0da31d6252806e4ed7efrobertphillips@google.com * @param canIgnoreRect allows partial clears to be converted to whole 38356ce48ade325f6f49acb0da31d6252806e4ed7efrobertphillips@google.com * clears on platforms for which that is cheap 384c82a8b7aa4ec19fba508c394920a9e88d3e5bd12robertphillips@google.com * @param target if non-NULL, the render target to clear otherwise clear 385c82a8b7aa4ec19fba508c394920a9e88d3e5bd12robertphillips@google.com * the current render target 38627847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com */ 38756ce48ade325f6f49acb0da31d6252806e4ed7efrobertphillips@google.com void clear(const SkIRect* rect, GrColor color, bool canIgnoreRect, 388c82a8b7aa4ec19fba508c394920a9e88d3e5bd12robertphillips@google.com GrRenderTarget* target = NULL); 38927847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com 39027847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com /** 39127847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * Draw everywhere (respecting the clip) with the paint. 39227847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com */ 39327847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com void drawPaint(const GrPaint& paint); 39427847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com 39527847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com /** 39627847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * Draw the rect using a paint. 39727847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * @param paint describes how to color pixels. 39827847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * @param strokeWidth If strokeWidth < 0, then the rect is filled, else 39927847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * the rect is mitered stroked based on strokeWidth. If 40027847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * strokeWidth == 0, then the stroke is always a single 40127847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * pixel thick. 40227847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * @param matrix Optional matrix applied to the rect. Applied before 40327847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * context's matrix or the paint's matrix. 40427847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * The rects coords are used to access the paint (through texture matrix) 40527847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com */ 40627847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com void drawRect(const GrPaint& paint, 407fd03d4a829efe2d77a712fd991927c55f59a2ffecommit-bot@chromium.org const SkRect&, 40881712883419f76e25d2ffec38a9438284a45a48dbsalomon@google.com SkScalar strokeWidth = -1, 409b9086a026844e4cfd08b219e49ce3f12294cba98bsalomon@google.com const SkMatrix* matrix = NULL); 41027847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com 41127847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com /** 412c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com * Maps a rect of local coordinates onto the a rect of destination 413c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com * coordinates. Each rect can optionally be transformed. The localRect 41427847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * is stretched over the dstRect. The dstRect is transformed by the 415c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com * context's matrix. Additional optional matrices for both rects can be 416c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com * provided by parameters. 41727847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * 418c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com * @param paint describes how to color pixels. 419c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com * @param dstRect the destination rect to draw. 420c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com * @param localRect rect of local coordinates to be mapped onto dstRect 421c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com * @param dstMatrix Optional matrix to transform dstRect. Applied before context's matrix. 422c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com * @param localMatrix Optional matrix to transform localRect. 42327847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com */ 42427847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com void drawRectToRect(const GrPaint& paint, 425fd03d4a829efe2d77a712fd991927c55f59a2ffecommit-bot@chromium.org const SkRect& dstRect, 426fd03d4a829efe2d77a712fd991927c55f59a2ffecommit-bot@chromium.org const SkRect& localRect, 427b9086a026844e4cfd08b219e49ce3f12294cba98bsalomon@google.com const SkMatrix* dstMatrix = NULL, 428c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com const SkMatrix* localMatrix = NULL); 42927847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com 43027847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com /** 431f2bfd54de32ffbcf90ddcd0e249aaebb1559d9c2commit-bot@chromium.org * Draw a roundrect using a paint. 432f2bfd54de32ffbcf90ddcd0e249aaebb1559d9c2commit-bot@chromium.org * 433f2bfd54de32ffbcf90ddcd0e249aaebb1559d9c2commit-bot@chromium.org * @param paint describes how to color pixels. 434f2bfd54de32ffbcf90ddcd0e249aaebb1559d9c2commit-bot@chromium.org * @param rrect the roundrect to draw 435f2bfd54de32ffbcf90ddcd0e249aaebb1559d9c2commit-bot@chromium.org * @param stroke the stroke information (width, join, cap) 436f2bfd54de32ffbcf90ddcd0e249aaebb1559d9c2commit-bot@chromium.org */ 437f2bfd54de32ffbcf90ddcd0e249aaebb1559d9c2commit-bot@chromium.org void drawRRect(const GrPaint& paint, 438f2bfd54de32ffbcf90ddcd0e249aaebb1559d9c2commit-bot@chromium.org const SkRRect& rrect, 439f2bfd54de32ffbcf90ddcd0e249aaebb1559d9c2commit-bot@chromium.org const SkStrokeRec& stroke); 440f2bfd54de32ffbcf90ddcd0e249aaebb1559d9c2commit-bot@chromium.org 441f2bfd54de32ffbcf90ddcd0e249aaebb1559d9c2commit-bot@chromium.org /** 442d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com * Draws a path. 44327847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * 44427847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * @param paint describes how to color pixels. 44507f3ee10d34f09342abb93d758b5e151ff78f7a5reed@google.com * @param path the path to draw 4465f74cf8c49701f514b69dc6f1a8b5c0ffd78af0asugoi@google.com * @param stroke the stroke information (width, join, cap) 44727847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com */ 4485f74cf8c49701f514b69dc6f1a8b5c0ffd78af0asugoi@google.com void drawPath(const GrPaint& paint, const SkPath& path, const SkStrokeRec& stroke); 44907f3ee10d34f09342abb93d758b5e151ff78f7a5reed@google.com 45027847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com /** 45127847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * Draws vertices with a paint. 45227847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * 45327847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * @param paint describes how to color pixels. 45427847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * @param primitiveType primitives type to draw. 45527847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * @param vertexCount number of vertices. 45627847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * @param positions array of vertex positions, required. 45727847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * @param texCoords optional array of texture coordinates used 45827847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * to access the paint. 45927847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * @param colors optional array of per-vertex colors, supercedes 46027847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * the paint's color field. 46127847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * @param indices optional array of indices. If NULL vertices 46227847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * are drawn non-indexed. 46327847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * @param indexCount if indices is non-null then this is the 46427847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * number of indices. 46527847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com */ 46627847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com void drawVertices(const GrPaint& paint, 46727847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com GrPrimitiveType primitiveType, 46827847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com int vertexCount, 46927847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com const GrPoint positions[], 47027847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com const GrPoint texs[], 47127847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com const GrColor colors[], 47227847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com const uint16_t indices[], 47327847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com int indexCount); 47427847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com 47593c9660cd158c5d0cab0ba4223e4257f699d5bb8bsalomon@google.com /** 47693c9660cd158c5d0cab0ba4223e4257f699d5bb8bsalomon@google.com * Draws an oval. 47793c9660cd158c5d0cab0ba4223e4257f699d5bb8bsalomon@google.com * 47893c9660cd158c5d0cab0ba4223e4257f699d5bb8bsalomon@google.com * @param paint describes how to color pixels. 47946d3d39e65e0b3ea2ad7c91c176ccafb4df0fa24jvanverth@google.com * @param oval the bounding rect of the oval. 48046d3d39e65e0b3ea2ad7c91c176ccafb4df0fa24jvanverth@google.com * @param stroke the stroke information (width, style) 48193c9660cd158c5d0cab0ba4223e4257f699d5bb8bsalomon@google.com */ 48293c9660cd158c5d0cab0ba4223e4257f699d5bb8bsalomon@google.com void drawOval(const GrPaint& paint, 483fd03d4a829efe2d77a712fd991927c55f59a2ffecommit-bot@chromium.org const SkRect& oval, 48446d3d39e65e0b3ea2ad7c91c176ccafb4df0fa24jvanverth@google.com const SkStrokeRec& stroke); 48593c9660cd158c5d0cab0ba4223e4257f699d5bb8bsalomon@google.com 48627847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com /////////////////////////////////////////////////////////////////////////// 48727847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com // Misc. 48827847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com 48927847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com /** 490a7f84e150cb9e821267a8ca9e59c1ae9a3cfa300bsalomon@google.com * Flags that affect flush() behavior. 491a7f84e150cb9e821267a8ca9e59c1ae9a3cfa300bsalomon@google.com */ 492a7f84e150cb9e821267a8ca9e59c1ae9a3cfa300bsalomon@google.com enum FlushBits { 493a7f84e150cb9e821267a8ca9e59c1ae9a3cfa300bsalomon@google.com /** 494a7f84e150cb9e821267a8ca9e59c1ae9a3cfa300bsalomon@google.com * A client may reach a point where it has partially rendered a frame 495a7f84e150cb9e821267a8ca9e59c1ae9a3cfa300bsalomon@google.com * through a GrContext that it knows the user will never see. This flag 496a7f84e150cb9e821267a8ca9e59c1ae9a3cfa300bsalomon@google.com * causes the flush to skip submission of deferred content to the 3D API 497a7f84e150cb9e821267a8ca9e59c1ae9a3cfa300bsalomon@google.com * during the flush. 498a7f84e150cb9e821267a8ca9e59c1ae9a3cfa300bsalomon@google.com */ 499a7f84e150cb9e821267a8ca9e59c1ae9a3cfa300bsalomon@google.com kDiscard_FlushBit = 0x2, 500a7f84e150cb9e821267a8ca9e59c1ae9a3cfa300bsalomon@google.com }; 501a7f84e150cb9e821267a8ca9e59c1ae9a3cfa300bsalomon@google.com 502a7f84e150cb9e821267a8ca9e59c1ae9a3cfa300bsalomon@google.com /** 50327847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * Call to ensure all drawing to the context has been issued to the 50427847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * underlying 3D API. 505a7f84e150cb9e821267a8ca9e59c1ae9a3cfa300bsalomon@google.com * @param flagsBitfield flags that control the flushing behavior. See 506a7f84e150cb9e821267a8ca9e59c1ae9a3cfa300bsalomon@google.com * FlushBits. 50727847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com */ 5088fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com void flush(int flagsBitfield = 0); 5096f3795105b2b458079e53a721c1735c9518f6bb5bsalomon@google.com 5100342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com /** 5110342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com * These flags can be used with the read/write pixels functions below. 5120342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com */ 5130342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com enum PixelOpsFlags { 5140342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com /** The GrContext will not be flushed. This means that the read or write may occur before 5150342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com previous draws have executed. */ 5160342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com kDontFlush_PixelOpsFlag = 0x1, 5170342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com /** The src for write or dst read is unpremultiplied. This is only respected if both the 5180342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com config src and dst configs are an RGBA/BGRA 8888 format. */ 5190342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com kUnpremul_PixelOpsFlag = 0x2, 5200342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com }; 5210342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com 522669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com /** 523669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com * Reads a rectangle of pixels from a render target. 5240342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com * @param target the render target to read from. NULL means the current render target. 525669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com * @param left left edge of the rectangle to read (inclusive) 526669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com * @param top top edge of the rectangle to read (inclusive) 527669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com * @param width width of rectangle to read in pixels. 528669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com * @param height height of rectangle to read in pixels. 529669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com * @param config the pixel config of the destination buffer 530669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com * @param buffer memory to read the rectangle into. 5310342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com * @param rowBytes number of bytes bewtween consecutive rows. Zero means rows are tightly 5320342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com * packed. 5330342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com * @param pixelOpsFlags see PixelOpsFlags enum above. 534669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com * 5350342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com * @return true if the read succeeded, false if not. The read can fail because of an unsupported 5360342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com * pixel config or because no render target is currently set and NULL was passed for 5370342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com * target. 538669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com */ 539669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com bool readRenderTargetPixels(GrRenderTarget* target, 540669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com int left, int top, int width, int height, 5410342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com GrPixelConfig config, void* buffer, 5420342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com size_t rowBytes = 0, 5430342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com uint32_t pixelOpsFlags = 0); 5446f3795105b2b458079e53a721c1735c9518f6bb5bsalomon@google.com 5456f3795105b2b458079e53a721c1735c9518f6bb5bsalomon@google.com /** 5461e269b5a08610da13c3aee23809bb45b17e7b663bsalomon@google.com * Copy the src pixels [buffer, row bytes, pixel config] into a render target at the specified 5470342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com * rectangle. 5480342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com * @param target the render target to write into. NULL means the current render target. 5496f3795105b2b458079e53a721c1735c9518f6bb5bsalomon@google.com * @param left left edge of the rectangle to write (inclusive) 5506f3795105b2b458079e53a721c1735c9518f6bb5bsalomon@google.com * @param top top edge of the rectangle to write (inclusive) 5516f3795105b2b458079e53a721c1735c9518f6bb5bsalomon@google.com * @param width width of rectangle to write in pixels. 5526f3795105b2b458079e53a721c1735c9518f6bb5bsalomon@google.com * @param height height of rectangle to write in pixels. 5536f3795105b2b458079e53a721c1735c9518f6bb5bsalomon@google.com * @param config the pixel config of the source buffer 5546f3795105b2b458079e53a721c1735c9518f6bb5bsalomon@google.com * @param buffer memory to read the rectangle from. 5553cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com * @param rowBytes number of bytes between consecutive rows. Zero means rows are tightly 5560342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com * packed. 5570342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com * @param pixelOpsFlags see PixelOpsFlags enum above. 5589c68058b679aee81e6e0158e7fcbfb5d8479c91absalomon@google.com * 5599c68058b679aee81e6e0158e7fcbfb5d8479c91absalomon@google.com * @return true if the write succeeded, false if not. The write can fail because of an 5609c68058b679aee81e6e0158e7fcbfb5d8479c91absalomon@google.com * unsupported combination of target and pixel configs. 5616f3795105b2b458079e53a721c1735c9518f6bb5bsalomon@google.com */ 5629c68058b679aee81e6e0158e7fcbfb5d8479c91absalomon@google.com bool writeRenderTargetPixels(GrRenderTarget* target, 5636f3795105b2b458079e53a721c1735c9518f6bb5bsalomon@google.com int left, int top, int width, int height, 5646f3795105b2b458079e53a721c1735c9518f6bb5bsalomon@google.com GrPixelConfig config, const void* buffer, 5650342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com size_t rowBytes = 0, 5660342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com uint32_t pixelOpsFlags = 0); 567669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com 568669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com /** 569669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com * Reads a rectangle of pixels from a texture. 5706f3795105b2b458079e53a721c1735c9518f6bb5bsalomon@google.com * @param texture the texture to read from. 571669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com * @param left left edge of the rectangle to read (inclusive) 572669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com * @param top top edge of the rectangle to read (inclusive) 573669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com * @param width width of rectangle to read in pixels. 574669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com * @param height height of rectangle to read in pixels. 575669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com * @param config the pixel config of the destination buffer 576669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com * @param buffer memory to read the rectangle into. 5773cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com * @param rowBytes number of bytes between consecutive rows. Zero means rows are tightly 5780342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com * packed. 5790342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com * @param pixelOpsFlags see PixelOpsFlags enum above. 580669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com * 5810342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com * @return true if the read succeeded, false if not. The read can fail because of an unsupported 5820342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com * pixel config. 58327847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com */ 5846f3795105b2b458079e53a721c1735c9518f6bb5bsalomon@google.com bool readTexturePixels(GrTexture* texture, 585669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com int left, int top, int width, int height, 5866f3795105b2b458079e53a721c1735c9518f6bb5bsalomon@google.com GrPixelConfig config, void* buffer, 5870342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com size_t rowBytes = 0, 5880342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com uint32_t pixelOpsFlags = 0); 58927847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com 59027847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com /** 5916f3795105b2b458079e53a721c1735c9518f6bb5bsalomon@google.com * Writes a rectangle of pixels to a texture. 5926f3795105b2b458079e53a721c1735c9518f6bb5bsalomon@google.com * @param texture the render target to read from. 5936f3795105b2b458079e53a721c1735c9518f6bb5bsalomon@google.com * @param left left edge of the rectangle to write (inclusive) 5946f3795105b2b458079e53a721c1735c9518f6bb5bsalomon@google.com * @param top top edge of the rectangle to write (inclusive) 5956f3795105b2b458079e53a721c1735c9518f6bb5bsalomon@google.com * @param width width of rectangle to write in pixels. 5966f3795105b2b458079e53a721c1735c9518f6bb5bsalomon@google.com * @param height height of rectangle to write in pixels. 5976f3795105b2b458079e53a721c1735c9518f6bb5bsalomon@google.com * @param config the pixel config of the source buffer 5986f3795105b2b458079e53a721c1735c9518f6bb5bsalomon@google.com * @param buffer memory to read pixels from 5993cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com * @param rowBytes number of bytes between consecutive rows. Zero 6006f3795105b2b458079e53a721c1735c9518f6bb5bsalomon@google.com * means rows are tightly packed. 6010342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com * @param pixelOpsFlags see PixelOpsFlags enum above. 6029c68058b679aee81e6e0158e7fcbfb5d8479c91absalomon@google.com * @return true if the write succeeded, false if not. The write can fail because of an 6039c68058b679aee81e6e0158e7fcbfb5d8479c91absalomon@google.com * unsupported combination of texture and pixel configs. 60427847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com */ 6059c68058b679aee81e6e0158e7fcbfb5d8479c91absalomon@google.com bool writeTexturePixels(GrTexture* texture, 6066f3795105b2b458079e53a721c1735c9518f6bb5bsalomon@google.com int left, int top, int width, int height, 6076f3795105b2b458079e53a721c1735c9518f6bb5bsalomon@google.com GrPixelConfig config, const void* buffer, 6080342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com size_t rowBytes, 6090342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com uint32_t pixelOpsFlags = 0); 6100342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com 6110342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com 612027de5f922e8ad1acc5402829f716b8c513fdd8dsenorblanco@chromium.org /** 613a2a31928470dfb642880f6ab2e4d34b1c7f5d476scroggo@google.com * Copies a rectangle of texels from src to dst. The size of dst is the size of the rectangle 614a2a31928470dfb642880f6ab2e4d34b1c7f5d476scroggo@google.com * copied and topLeft is the position of the rect in src. The rectangle is clipped to src's 615a2a31928470dfb642880f6ab2e4d34b1c7f5d476scroggo@google.com * bounds. 616ef843cdcd1be858fe55cc99ff134ffbd080c9a51senorblanco@chromium.org * @param src the texture to copy from. 617ef843cdcd1be858fe55cc99ff134ffbd080c9a51senorblanco@chromium.org * @param dst the render target to copy to. 618a2a31928470dfb642880f6ab2e4d34b1c7f5d476scroggo@google.com * @param topLeft the point in src that will be copied to the top-left of dst. If NULL, 619a2a31928470dfb642880f6ab2e4d34b1c7f5d476scroggo@google.com * (0, 0) will be used. 620ef843cdcd1be858fe55cc99ff134ffbd080c9a51senorblanco@chromium.org */ 621a2a31928470dfb642880f6ab2e4d34b1c7f5d476scroggo@google.com void copyTexture(GrTexture* src, GrRenderTarget* dst, const SkIPoint* topLeft = NULL); 62275f9f25d8bf2adc0494f9afbbd5965809ee13acabsalomon@google.com 62375f9f25d8bf2adc0494f9afbbd5965809ee13acabsalomon@google.com /** 62475f9f25d8bf2adc0494f9afbbd5965809ee13acabsalomon@google.com * Resolves a render target that has MSAA. The intermediate MSAA buffer is 6251e269b5a08610da13c3aee23809bb45b17e7b663bsalomon@google.com * down-sampled to the associated GrTexture (accessible via 62675f9f25d8bf2adc0494f9afbbd5965809ee13acabsalomon@google.com * GrRenderTarget::asTexture()). Any pending draws to the render target will 62775f9f25d8bf2adc0494f9afbbd5965809ee13acabsalomon@google.com * be executed before the resolve. 62875f9f25d8bf2adc0494f9afbbd5965809ee13acabsalomon@google.com * 62975f9f25d8bf2adc0494f9afbbd5965809ee13acabsalomon@google.com * This is only necessary when a client wants to access the object directly 63016e3ddea6a80972aced04b21b1d66377fa95e7c7bsalomon@google.com * using the backend API directly. GrContext will detect when it must 63175f9f25d8bf2adc0494f9afbbd5965809ee13acabsalomon@google.com * perform a resolve to a GrTexture used as the source of a draw or before 63275f9f25d8bf2adc0494f9afbbd5965809ee13acabsalomon@google.com * reading pixels back from a GrTexture or GrRenderTarget. 63375f9f25d8bf2adc0494f9afbbd5965809ee13acabsalomon@google.com */ 63475f9f25d8bf2adc0494f9afbbd5965809ee13acabsalomon@google.com void resolveRenderTarget(GrRenderTarget* target); 63575f9f25d8bf2adc0494f9afbbd5965809ee13acabsalomon@google.com 63603e3e89641c93df603dfb705d518848dfe81427ecommit-bot@chromium.org#ifdef SK_DEVELOPER 63703e3e89641c93df603dfb705d518848dfe81427ecommit-bot@chromium.org void dumpFontCache() const; 63803e3e89641c93df603dfb705d518848dfe81427ecommit-bot@chromium.org#endif 63903e3e89641c93df603dfb705d518848dfe81427ecommit-bot@chromium.org 64027847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com /////////////////////////////////////////////////////////////////////////// 64127847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com // Helpers 64227847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com 643a0b40280a49a8a43af7929ead3b3489951c58501commit-bot@chromium.org class AutoRenderTarget : public ::SkNoncopyable { 64427847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com public: 64527847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com AutoRenderTarget(GrContext* context, GrRenderTarget* target) { 64627847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com fPrevTarget = context->getRenderTarget(); 647a4de8c257ea0be8ff7081f645249b6afe5c48e7ecommit-bot@chromium.org SkSafeRef(fPrevTarget); 648a04e8e842450e606dd938ddae17857849bd504d4bsalomon@google.com context->setRenderTarget(target); 649a04e8e842450e606dd938ddae17857849bd504d4bsalomon@google.com fContext = context; 650a04e8e842450e606dd938ddae17857849bd504d4bsalomon@google.com } 651a04e8e842450e606dd938ddae17857849bd504d4bsalomon@google.com AutoRenderTarget(GrContext* context) { 652a04e8e842450e606dd938ddae17857849bd504d4bsalomon@google.com fPrevTarget = context->getRenderTarget(); 653a4de8c257ea0be8ff7081f645249b6afe5c48e7ecommit-bot@chromium.org SkSafeRef(fPrevTarget); 654a04e8e842450e606dd938ddae17857849bd504d4bsalomon@google.com fContext = context; 65527847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com } 65627847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com ~AutoRenderTarget() { 657ccb39504096db647dafdb254cae59ae172969b8erobertphillips@google.com if (NULL != fContext) { 65827847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com fContext->setRenderTarget(fPrevTarget); 65927847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com } 660a4de8c257ea0be8ff7081f645249b6afe5c48e7ecommit-bot@chromium.org SkSafeUnref(fPrevTarget); 66127847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com } 66227847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com private: 66327847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com GrContext* fContext; 66427847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com GrRenderTarget* fPrevTarget; 66527847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com }; 66627847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com 667fea85ac3e31842f80493e2df8a93a28f21cd815frobertphillips@google.com /** 6683cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com * Save/restore the view-matrix in the context. It can optionally adjust a paint to account 6693cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com * for a coordinate system change. Here is an example of how the paint param can be used: 6703cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com * 6716f261bed0252e3f3caa595798364e0bf12a2573absalomon@google.com * A GrPaint is setup with GrEffects. The stages will have access to the pre-matrix source 6723cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com * geometry positions when the draw is executed. Later on a decision is made to transform the 6736f261bed0252e3f3caa595798364e0bf12a2573absalomon@google.com * geometry to device space on the CPU. The effects now need to know that the space in which 6746f261bed0252e3f3caa595798364e0bf12a2573absalomon@google.com * the geometry will be specified has changed. 6753cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com * 6763cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com * Note that when restore is called (or in the destructor) the context's matrix will be 6773cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com * restored. However, the paint will not be restored. The caller must make a copy of the 6783cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com * paint if necessary. Hint: use SkTCopyOnFirstWrite if the AutoMatrix is conditionally 6793cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com * initialized. 680fea85ac3e31842f80493e2df8a93a28f21cd815frobertphillips@google.com */ 681a0b40280a49a8a43af7929ead3b3489951c58501commit-bot@chromium.org class AutoMatrix : public ::SkNoncopyable { 682fea85ac3e31842f80493e2df8a93a28f21cd815frobertphillips@google.com public: 683fea85ac3e31842f80493e2df8a93a28f21cd815frobertphillips@google.com AutoMatrix() : fContext(NULL) {} 684a04e8e842450e606dd938ddae17857849bd504d4bsalomon@google.com 6853cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com ~AutoMatrix() { this->restore(); } 6863cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com 6873cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com /** 6883cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com * Initializes by pre-concat'ing the context's current matrix with the preConcat param. 6893cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com */ 690b9086a026844e4cfd08b219e49ce3f12294cba98bsalomon@google.com void setPreConcat(GrContext* context, const SkMatrix& preConcat, GrPaint* paint = NULL) { 691f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org SkASSERT(NULL != context); 6923cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com 6933cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com this->restore(); 694f57c01bdcfdf1c923b9a473974bfe6f8c66eca3eskia.committer@gmail.com 6953cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com fContext = context; 6963cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com fMatrix = context->getMatrix(); 6973cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com this->preConcat(preConcat, paint); 698fea85ac3e31842f80493e2df8a93a28f21cd815frobertphillips@google.com } 699a04e8e842450e606dd938ddae17857849bd504d4bsalomon@google.com 7003cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com /** 7013cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com * Sets the context's matrix to identity. Returns false if the inverse matrix is required to 7023cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com * update a paint but the matrix cannot be inverted. 7033cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com */ 7043cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com bool setIdentity(GrContext* context, GrPaint* paint = NULL) { 705f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org SkASSERT(NULL != context); 7063cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com 7073cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com this->restore(); 708f57c01bdcfdf1c923b9a473974bfe6f8c66eca3eskia.committer@gmail.com 7093cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com if (NULL != paint) { 710c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com if (!paint->localCoordChangeInverse(context->getMatrix())) { 7113cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com return false; 7123cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com } 7133cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com } 7143cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com fMatrix = context->getMatrix(); 7153cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com fContext = context; 7163cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com context->setIdentityMatrix(); 7173cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com return true; 718fea85ac3e31842f80493e2df8a93a28f21cd815frobertphillips@google.com } 719a04e8e842450e606dd938ddae17857849bd504d4bsalomon@google.com 7203cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com /** 7213cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com * Replaces the context's matrix with a new matrix. Returns false if the inverse matrix is 7223cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com * required to update a paint but the matrix cannot be inverted. 7233cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com */ 724b9086a026844e4cfd08b219e49ce3f12294cba98bsalomon@google.com bool set(GrContext* context, const SkMatrix& newMatrix, GrPaint* paint = NULL) { 7253cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com if (NULL != paint) { 7263cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com if (!this->setIdentity(context, paint)) { 7273cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com return false; 7283cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com } 7293cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com this->preConcat(newMatrix, paint); 7303cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com } else { 7313cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com this->restore(); 7323cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com fContext = context; 7333cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com fMatrix = context->getMatrix(); 7343cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com context->setMatrix(newMatrix); 735fea85ac3e31842f80493e2df8a93a28f21cd815frobertphillips@google.com } 7363cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com return true; 737fea85ac3e31842f80493e2df8a93a28f21cd815frobertphillips@google.com } 738a04e8e842450e606dd938ddae17857849bd504d4bsalomon@google.com 7393cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com /** 7403cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com * If this has been initialized then the context's matrix will be further updated by 7413cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com * pre-concat'ing the preConcat param. The matrix that will be restored remains unchanged. 7423cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com * The paint is assumed to be relative to the context's matrix at the time this call is 7433cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com * made, not the matrix at the time AutoMatrix was first initialized. In other words, this 7443cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com * performs an incremental update of the paint. 7453cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com */ 746b9086a026844e4cfd08b219e49ce3f12294cba98bsalomon@google.com void preConcat(const SkMatrix& preConcat, GrPaint* paint = NULL) { 7473cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com if (NULL != paint) { 748c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com paint->localCoordChange(preConcat); 749fea85ac3e31842f80493e2df8a93a28f21cd815frobertphillips@google.com } 7503cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com fContext->concatMatrix(preConcat); 751fea85ac3e31842f80493e2df8a93a28f21cd815frobertphillips@google.com } 752a04e8e842450e606dd938ddae17857849bd504d4bsalomon@google.com 7533cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com /** 7543cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com * Returns false if never initialized or the inverse matrix was required to update a paint 7553cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com * but the matrix could not be inverted. 7563cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com */ 7573cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com bool succeeded() const { return NULL != fContext; } 7583cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com 7593cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com /** 7603cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com * If this has been initialized then the context's original matrix is restored. 7613cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com */ 7623cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com void restore() { 763fea85ac3e31842f80493e2df8a93a28f21cd815frobertphillips@google.com if (NULL != fContext) { 764fea85ac3e31842f80493e2df8a93a28f21cd815frobertphillips@google.com fContext->setMatrix(fMatrix); 7653cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com fContext = NULL; 766fea85ac3e31842f80493e2df8a93a28f21cd815frobertphillips@google.com } 767fea85ac3e31842f80493e2df8a93a28f21cd815frobertphillips@google.com } 768fea85ac3e31842f80493e2df8a93a28f21cd815frobertphillips@google.com 769fea85ac3e31842f80493e2df8a93a28f21cd815frobertphillips@google.com private: 770fea85ac3e31842f80493e2df8a93a28f21cd815frobertphillips@google.com GrContext* fContext; 771b9086a026844e4cfd08b219e49ce3f12294cba98bsalomon@google.com SkMatrix fMatrix; 772fea85ac3e31842f80493e2df8a93a28f21cd815frobertphillips@google.com }; 77327847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com 774a0b40280a49a8a43af7929ead3b3489951c58501commit-bot@chromium.org class AutoClip : public ::SkNoncopyable { 77556c79b10377e358b8092d9c6ab3e1aacf2cd60e5robertphillips@google.com public: 776a04e8e842450e606dd938ddae17857849bd504d4bsalomon@google.com // This enum exists to require a caller of the constructor to acknowledge that the clip will 777a04e8e842450e606dd938ddae17857849bd504d4bsalomon@google.com // initially be wide open. It also could be extended if there are other desirable initial 778a04e8e842450e606dd938ddae17857849bd504d4bsalomon@google.com // clip states. 779a04e8e842450e606dd938ddae17857849bd504d4bsalomon@google.com enum InitialClip { 780a04e8e842450e606dd938ddae17857849bd504d4bsalomon@google.com kWideOpen_InitialClip, 781a04e8e842450e606dd938ddae17857849bd504d4bsalomon@google.com }; 782a04e8e842450e606dd938ddae17857849bd504d4bsalomon@google.com 783dc3a4e5fa8c42bd0313af547bc15db2e6554a217skia.committer@gmail.com AutoClip(GrContext* context, InitialClip initialState) 784ccb39504096db647dafdb254cae59ae172969b8erobertphillips@google.com : fContext(context) { 785f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org SkASSERT(kWideOpen_InitialClip == initialState); 786a04e8e842450e606dd938ddae17857849bd504d4bsalomon@google.com fNewClipData.fClipStack = &fNewClipStack; 787ccb39504096db647dafdb254cae59ae172969b8erobertphillips@google.com 788ccb39504096db647dafdb254cae59ae172969b8erobertphillips@google.com fOldClip = context->getClip(); 789a04e8e842450e606dd938ddae17857849bd504d4bsalomon@google.com context->setClip(&fNewClipData); 790a04e8e842450e606dd938ddae17857849bd504d4bsalomon@google.com } 791a04e8e842450e606dd938ddae17857849bd504d4bsalomon@google.com 792fd03d4a829efe2d77a712fd991927c55f59a2ffecommit-bot@chromium.org AutoClip(GrContext* context, const SkRect& newClipRect) 79356c79b10377e358b8092d9c6ab3e1aacf2cd60e5robertphillips@google.com : fContext(context) 794beb1af78d016d2700c350487a383c6bcfa7e2e20robertphillips@google.com , fNewClipStack(newClipRect) { 795beb1af78d016d2700c350487a383c6bcfa7e2e20robertphillips@google.com fNewClipData.fClipStack = &fNewClipStack; 796beb1af78d016d2700c350487a383c6bcfa7e2e20robertphillips@google.com 79756c79b10377e358b8092d9c6ab3e1aacf2cd60e5robertphillips@google.com fOldClip = fContext->getClip(); 798beb1af78d016d2700c350487a383c6bcfa7e2e20robertphillips@google.com fContext->setClip(&fNewClipData); 79956c79b10377e358b8092d9c6ab3e1aacf2cd60e5robertphillips@google.com } 80056c79b10377e358b8092d9c6ab3e1aacf2cd60e5robertphillips@google.com 80156c79b10377e358b8092d9c6ab3e1aacf2cd60e5robertphillips@google.com ~AutoClip() { 80256c79b10377e358b8092d9c6ab3e1aacf2cd60e5robertphillips@google.com if (NULL != fContext) { 80356c79b10377e358b8092d9c6ab3e1aacf2cd60e5robertphillips@google.com fContext->setClip(fOldClip); 80456c79b10377e358b8092d9c6ab3e1aacf2cd60e5robertphillips@google.com } 80556c79b10377e358b8092d9c6ab3e1aacf2cd60e5robertphillips@google.com } 80656c79b10377e358b8092d9c6ab3e1aacf2cd60e5robertphillips@google.com private: 807beb1af78d016d2700c350487a383c6bcfa7e2e20robertphillips@google.com GrContext* fContext; 808beb1af78d016d2700c350487a383c6bcfa7e2e20robertphillips@google.com const GrClipData* fOldClip; 809beb1af78d016d2700c350487a383c6bcfa7e2e20robertphillips@google.com 810641f8b19a6799b6d73ac17b9c2d2f8a5e6f5ad4drobertphillips@google.com SkClipStack fNewClipStack; 811beb1af78d016d2700c350487a383c6bcfa7e2e20robertphillips@google.com GrClipData fNewClipData; 81256c79b10377e358b8092d9c6ab3e1aacf2cd60e5robertphillips@google.com }; 81356c79b10377e358b8092d9c6ab3e1aacf2cd60e5robertphillips@google.com 814a04e8e842450e606dd938ddae17857849bd504d4bsalomon@google.com class AutoWideOpenIdentityDraw { 815a04e8e842450e606dd938ddae17857849bd504d4bsalomon@google.com public: 816a04e8e842450e606dd938ddae17857849bd504d4bsalomon@google.com AutoWideOpenIdentityDraw(GrContext* ctx, GrRenderTarget* rt) 817a04e8e842450e606dd938ddae17857849bd504d4bsalomon@google.com : fAutoClip(ctx, AutoClip::kWideOpen_InitialClip) 8183cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com , fAutoRT(ctx, rt) { 8193cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com fAutoMatrix.setIdentity(ctx); 8203cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com // should never fail with no paint param. 821f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org SkASSERT(fAutoMatrix.succeeded()); 822a04e8e842450e606dd938ddae17857849bd504d4bsalomon@google.com } 8233cbaa2d4da8bc39a99bf3afaaab43cc6dc481723bsalomon@google.com 824a04e8e842450e606dd938ddae17857849bd504d4bsalomon@google.com private: 825a04e8e842450e606dd938ddae17857849bd504d4bsalomon@google.com AutoClip fAutoClip; 826a04e8e842450e606dd938ddae17857849bd504d4bsalomon@google.com AutoRenderTarget fAutoRT; 827a04e8e842450e606dd938ddae17857849bd504d4bsalomon@google.com AutoMatrix fAutoMatrix; 828a04e8e842450e606dd938ddae17857849bd504d4bsalomon@google.com }; 829a04e8e842450e606dd938ddae17857849bd504d4bsalomon@google.com 83027847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com /////////////////////////////////////////////////////////////////////////// 83127847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com // Functions intended for internal use only. 83227847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com GrGpu* getGpu() { return fGpu; } 8331f221a70214fa1ab87b8a32dd66facf485f318eebsalomon@google.com const GrGpu* getGpu() const { return fGpu; } 83427847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com GrFontCache* getFontCache() { return fFontCache; } 83521c10c5ff50cb8f2fd995fc9396d435d3396258bbsalomon@google.com GrDrawTarget* getTextTarget(); 83627847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com const GrIndexBuffer* getQuadIndexBuffer() const; 8379923c2b29aafc7ebc81c929c68c6b32443c9f22bbsalomon@google.com 83878a1078f17f4f0ae63415298517262a64f706af6commit-bot@chromium.org // Called by tests that draw directly to the context via GrDrawTarget 83978a1078f17f4f0ae63415298517262a64f706af6commit-bot@chromium.org void getTestTarget(GrTestTarget*); 84078a1078f17f4f0ae63415298517262a64f706af6commit-bot@chromium.org 841558a75bcb323c03dd7482555c7214062a363276fbsalomon@google.com /** 8421e269b5a08610da13c3aee23809bb45b17e7b663bsalomon@google.com * Stencil buffers add themselves to the cache using addStencilBuffer. findStencilBuffer is 8431e269b5a08610da13c3aee23809bb45b17e7b663bsalomon@google.com * called to check the cache for a SB that matches an RT's criteria. 844558a75bcb323c03dd7482555c7214062a363276fbsalomon@google.com */ 8459fbcad0f00d7098574cf3394a812c9d845c9cc5brobertphillips@google.com void addStencilBuffer(GrStencilBuffer* sb); 8469fbcad0f00d7098574cf3394a812c9d845c9cc5brobertphillips@google.com GrStencilBuffer* findStencilBuffer(int width, int height, int sampleCnt); 84727847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com 84845a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com GrPathRenderer* getPathRenderer( 84945a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com const SkPath& path, 8505f74cf8c49701f514b69dc6f1a8b5c0ffd78af0asugoi@google.com const SkStrokeRec& stroke, 85145a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com const GrDrawTarget* target, 85245a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com bool allowSW, 85345a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com GrPathRendererChain::DrawType drawType = GrPathRendererChain::kColor_DrawType, 85445a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com GrPathRendererChain::StencilSupport* stencilSupport = NULL); 8552c75681e36b33fcafc5665d7012bbd4fc6647d83robertphillips@google.com 8567475811143e190e172bf83d13c4bdba85704b604skia.committer@gmail.com 8575955202c805c7ef1448103cbf666972ea9d1ded1robertphillips@google.com#if GR_CACHE_STATS 8585f9f2f574fe9b195f5f3e40edeb2e28b673511fdrobertphillips@google.com void printCacheStats() const; 8595f9f2f574fe9b195f5f3e40edeb2e28b673511fdrobertphillips@google.com#endif 8605f9f2f574fe9b195f5f3e40edeb2e28b673511fdrobertphillips@google.com 86127847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.comprivate: 8621d4edd38f6b62d1cc54cb7bc6f3c6ce10ccb1471bsalomon@google.com // Used to indicate whether a draw should be performed immediately or queued in fDrawBuffer. 8631d4edd38f6b62d1cc54cb7bc6f3c6ce10ccb1471bsalomon@google.com enum BufferedDraw { 8641d4edd38f6b62d1cc54cb7bc6f3c6ce10ccb1471bsalomon@google.com kYes_BufferedDraw, 8651d4edd38f6b62d1cc54cb7bc6f3c6ce10ccb1471bsalomon@google.com kNo_BufferedDraw, 86627847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com }; 8671d4edd38f6b62d1cc54cb7bc6f3c6ce10ccb1471bsalomon@google.com BufferedDraw fLastDrawWasBuffered; 86827847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com 869bb6a3178c3e79c8549b332e4ce84c64b59964f1ecommit-bot@chromium.org GrGpu* fGpu; 870bb6a3178c3e79c8549b332e4ce84c64b59964f1ecommit-bot@chromium.org SkMatrix fViewMatrix; 871bb6a3178c3e79c8549b332e4ce84c64b59964f1ecommit-bot@chromium.org SkAutoTUnref<GrRenderTarget> fRenderTarget; 872bb6a3178c3e79c8549b332e4ce84c64b59964f1ecommit-bot@chromium.org const GrClipData* fClip; // TODO: make this ref counted 873bb6a3178c3e79c8549b332e4ce84c64b59964f1ecommit-bot@chromium.org GrDrawState* fDrawState; 87410e04bf1c5025389d999f22467405782e9f9ffccbsalomon@google.com 875bb6a3178c3e79c8549b332e4ce84c64b59964f1ecommit-bot@chromium.org GrResourceCache* fTextureCache; 876bb6a3178c3e79c8549b332e4ce84c64b59964f1ecommit-bot@chromium.org GrFontCache* fFontCache; 877dfe75bcf98b0c04535efbf7fe36492a7fb53c90dbsalomon@google.com 878bb6a3178c3e79c8549b332e4ce84c64b59964f1ecommit-bot@chromium.org GrPathRendererChain* fPathRendererChain; 879bb6a3178c3e79c8549b332e4ce84c64b59964f1ecommit-bot@chromium.org GrSoftwarePathRenderer* fSoftwarePathRenderer; 88027847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com 881bb6a3178c3e79c8549b332e4ce84c64b59964f1ecommit-bot@chromium.org GrVertexBufferAllocPool* fDrawBufferVBAllocPool; 882bb6a3178c3e79c8549b332e4ce84c64b59964f1ecommit-bot@chromium.org GrIndexBufferAllocPool* fDrawBufferIBAllocPool; 883bb6a3178c3e79c8549b332e4ce84c64b59964f1ecommit-bot@chromium.org GrInOrderDrawBuffer* fDrawBuffer; 88427847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com 8855dbb149fda134941e5d168790127caf294d322e2commit-bot@chromium.org // Set by OverbudgetCB() to request that GrContext flush before exiting a draw. 8865dbb149fda134941e5d168790127caf294d322e2commit-bot@chromium.org bool fFlushToReduceCacheSize; 8875dbb149fda134941e5d168790127caf294d322e2commit-bot@chromium.org 888bb6a3178c3e79c8549b332e4ce84c64b59964f1ecommit-bot@chromium.org GrAARectRenderer* fAARectRenderer; 889bb6a3178c3e79c8549b332e4ce84c64b59964f1ecommit-bot@chromium.org GrOvalRenderer* fOvalRenderer; 890dfe75bcf98b0c04535efbf7fe36492a7fb53c90dbsalomon@google.com 891bb6a3178c3e79c8549b332e4ce84c64b59964f1ecommit-bot@chromium.org bool fDidTestPMConversions; 892bb6a3178c3e79c8549b332e4ce84c64b59964f1ecommit-bot@chromium.org int fPMToUPMConversion; 893bb6a3178c3e79c8549b332e4ce84c64b59964f1ecommit-bot@chromium.org int fUPMToPMConversion; 894a04e8e842450e606dd938ddae17857849bd504d4bsalomon@google.com 895cdb426d55a4bc4dae4f6d4f23e6994762950fdc3robertphillips@google.com struct CleanUpData { 896cdb426d55a4bc4dae4f6d4f23e6994762950fdc3robertphillips@google.com PFCleanUpFunc fFunc; 897cdb426d55a4bc4dae4f6d4f23e6994762950fdc3robertphillips@google.com void* fInfo; 898cdb426d55a4bc4dae4f6d4f23e6994762950fdc3robertphillips@google.com }; 899cdb426d55a4bc4dae4f6d4f23e6994762950fdc3robertphillips@google.com 90044a91dcf2542c2aa93f159ebbb5bf813ae7362c0robertphillips@google.com SkTDArray<CleanUpData> fCleanUpData; 90144a91dcf2542c2aa93f159ebbb5bf813ae7362c0robertphillips@google.com 902956b310f13c7412c035406c658ff16ca85eac656skia.committer@gmail.com int fMaxTextureSizeOverride; 903cdb426d55a4bc4dae4f6d4f23e6994762950fdc3robertphillips@google.com 9046e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com GrContext(); // init must be called after the constructor. 9056e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com bool init(GrBackend, GrBackendContext); 906205d46067ace24bd4b111cf44efc96caff6c4d30bsalomon@google.com 9078fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com void setupDrawBuffer(); 9088fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com 909eb6879f50a5564eeb981ec5616b55bf685eb76fcbsalomon@google.com class AutoRestoreEffects; 9105dbb149fda134941e5d168790127caf294d322e2commit-bot@chromium.org class AutoCheckFlush; 91107ea2db0260d8e6cd2bf605571b68b1c574b5a77bsalomon@google.com /// Sets the paint and returns the target to draw into. The paint can be NULL in which case the 91207ea2db0260d8e6cd2bf605571b68b1c574b5a77bsalomon@google.com /// draw state is left unmodified. 9135dbb149fda134941e5d168790127caf294d322e2commit-bot@chromium.org GrDrawTarget* prepareToDraw(const GrPaint*, BufferedDraw, AutoRestoreEffects*, AutoCheckFlush*); 91427847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com 91537d883d9d3c5945e9d121830bdcd1935160fd53bcommit-bot@chromium.org void internalDrawPath(GrDrawTarget* target, bool useAA, const SkPath& path, 91681312830ef73420efdc4821feb7c2d6fd9152af8commit-bot@chromium.org const SkStrokeRec& stroke); 91746d3d39e65e0b3ea2ad7c91c176ccafb4df0fa24jvanverth@google.com 9183319f33470abc50a6f3da3a565d917050f9b2f53robertphillips@google.com GrTexture* createResizedTexture(const GrTextureDesc& desc, 9190797c2cceadd7dfc2e7f9efa30b611d18efcdcddbsalomon@google.com const GrCacheID& cacheID, 9203319f33470abc50a6f3da3a565d917050f9b2f53robertphillips@google.com void* srcData, 9213319f33470abc50a6f3da3a565d917050f9b2f53robertphillips@google.com size_t rowBytes, 922b86add1ad37776818e1f730359ec587c9fdbff5fhumper@google.com bool filter); 9233319f33470abc50a6f3da3a565d917050f9b2f53robertphillips@google.com 92415c0fea699b25343fe6f49668a5632866e1a0306robertphillips@google.com // Needed so GrTexture's returnToCache helper function can call 92515c0fea699b25343fe6f49668a5632866e1a0306robertphillips@google.com // addExistingTextureToCache 92615c0fea699b25343fe6f49668a5632866e1a0306robertphillips@google.com friend class GrTexture; 92715c0fea699b25343fe6f49668a5632866e1a0306robertphillips@google.com 92815c0fea699b25343fe6f49668a5632866e1a0306robertphillips@google.com // Add an existing texture to the texture cache. This is intended solely 92915c0fea699b25343fe6f49668a5632866e1a0306robertphillips@google.com // for use with textures released from an GrAutoScratchTexture. 93015c0fea699b25343fe6f49668a5632866e1a0306robertphillips@google.com void addExistingTextureToCache(GrTexture* texture); 931fa35e3ddcc9d130ce87c927218bdf27879c38711reed@google.com 932cdcb2ce2744c7e5c47453328dbf292edee79ab37skia.committer@gmail.com /** 933adc6536fe5baff2216fb76ecda6cc81c61109d5cbsalomon@google.com * These functions create premul <-> unpremul effects if it is possible to generate a pair 934adc6536fe5baff2216fb76ecda6cc81c61109d5cbsalomon@google.com * of effects that make a readToUPM->writeToPM->readToUPM cycle invariant. Otherwise, they 935adc6536fe5baff2216fb76ecda6cc81c61109d5cbsalomon@google.com * return NULL. 936adc6536fe5baff2216fb76ecda6cc81c61109d5cbsalomon@google.com */ 937adc6536fe5baff2216fb76ecda6cc81c61109d5cbsalomon@google.com const GrEffectRef* createPMToUPMEffect(GrTexture* texture, 938adc6536fe5baff2216fb76ecda6cc81c61109d5cbsalomon@google.com bool swapRAndB, 939adc6536fe5baff2216fb76ecda6cc81c61109d5cbsalomon@google.com const SkMatrix& matrix); 940adc6536fe5baff2216fb76ecda6cc81c61109d5cbsalomon@google.com const GrEffectRef* createUPMToPMEffect(GrTexture* texture, 941adc6536fe5baff2216fb76ecda6cc81c61109d5cbsalomon@google.com bool swapRAndB, 942adc6536fe5baff2216fb76ecda6cc81c61109d5cbsalomon@google.com const SkMatrix& matrix); 943a04e8e842450e606dd938ddae17857849bd504d4bsalomon@google.com 944cae27fed5e45e8899e56ece22b27e8958ffc0162commit-bot@chromium.org /** 945cae27fed5e45e8899e56ece22b27e8958ffc0162commit-bot@chromium.org * This callback allows the resource cache to callback into the GrContext 946cae27fed5e45e8899e56ece22b27e8958ffc0162commit-bot@chromium.org * when the cache is still overbudget after a purge. 947cae27fed5e45e8899e56ece22b27e8958ffc0162commit-bot@chromium.org */ 948cae27fed5e45e8899e56ece22b27e8958ffc0162commit-bot@chromium.org static bool OverbudgetCB(void* data); 949cae27fed5e45e8899e56ece22b27e8958ffc0162commit-bot@chromium.org 950a4de8c257ea0be8ff7081f645249b6afe5c48e7ecommit-bot@chromium.org typedef SkRefCnt INHERITED; 95127847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com}; 95227847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com 95327847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com/** 9541e269b5a08610da13c3aee23809bb45b17e7b663bsalomon@google.com * Gets and locks a scratch texture from a descriptor using either exact or approximate criteria. 9551e269b5a08610da13c3aee23809bb45b17e7b663bsalomon@google.com * Unlocks texture in the destructor. 956aadd9f8b193aa70e3dc30cbe5c4e1bc5c1d047basenorblanco@chromium.org */ 957a0b40280a49a8a43af7929ead3b3489951c58501commit-bot@chromium.orgclass GrAutoScratchTexture : public ::SkNoncopyable { 958aadd9f8b193aa70e3dc30cbe5c4e1bc5c1d047basenorblanco@chromium.orgpublic: 95950398bf7f1953e640e5529616e710cf540799731bsalomon@google.com GrAutoScratchTexture() 9601f47f4f7325971dd53991e2bb02da94fa7c6d962robertphillips@google.com : fContext(NULL) 9611f47f4f7325971dd53991e2bb02da94fa7c6d962robertphillips@google.com , fTexture(NULL) { 962aadd9f8b193aa70e3dc30cbe5c4e1bc5c1d047basenorblanco@chromium.org } 96350398bf7f1953e640e5529616e710cf540799731bsalomon@google.com 96450398bf7f1953e640e5529616e710cf540799731bsalomon@google.com GrAutoScratchTexture(GrContext* context, 96550398bf7f1953e640e5529616e710cf540799731bsalomon@google.com const GrTextureDesc& desc, 9660797c2cceadd7dfc2e7f9efa30b611d18efcdcddbsalomon@google.com GrContext::ScratchTexMatch match = GrContext::kApprox_ScratchTexMatch) 9671f47f4f7325971dd53991e2bb02da94fa7c6d962robertphillips@google.com : fContext(NULL) 9681f47f4f7325971dd53991e2bb02da94fa7c6d962robertphillips@google.com , fTexture(NULL) { 96950398bf7f1953e640e5529616e710cf540799731bsalomon@google.com this->set(context, desc, match); 97050398bf7f1953e640e5529616e710cf540799731bsalomon@google.com } 971fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 97250398bf7f1953e640e5529616e710cf540799731bsalomon@google.com ~GrAutoScratchTexture() { 9739ec075366ed94802a142fc5e948d19a774f85b43robertphillips@google.com this->reset(); 9749ec075366ed94802a142fc5e948d19a774f85b43robertphillips@google.com } 9759ec075366ed94802a142fc5e948d19a774f85b43robertphillips@google.com 9769ec075366ed94802a142fc5e948d19a774f85b43robertphillips@google.com void reset() { 9771f47f4f7325971dd53991e2bb02da94fa7c6d962robertphillips@google.com if (NULL != fContext && NULL != fTexture) { 9789fbcad0f00d7098574cf3394a812c9d845c9cc5brobertphillips@google.com fContext->unlockScratchTexture(fTexture); 97995ed55adc6b8f0cee063c2cf2e14782773b0087fbsalomon@google.com fTexture->unref(); 9801f47f4f7325971dd53991e2bb02da94fa7c6d962robertphillips@google.com fTexture = NULL; 981aadd9f8b193aa70e3dc30cbe5c4e1bc5c1d047basenorblanco@chromium.org } 982aadd9f8b193aa70e3dc30cbe5c4e1bc5c1d047basenorblanco@chromium.org } 98384223118f7073a28f42c11ad08595e07c0ceb933bsalomon@google.com 98415c0fea699b25343fe6f49668a5632866e1a0306robertphillips@google.com /* 98515c0fea699b25343fe6f49668a5632866e1a0306robertphillips@google.com * When detaching a texture we do not unlock it in the texture cache but 986fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com * we do set the returnToCache flag. In this way the texture remains 987fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com * "locked" in the texture cache until it is freed and recycled in 988fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com * GrTexture::internal_dispose. In reality, the texture has been removed 989fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com * from the cache (because this is in AutoScratchTexture) and by not 99095ed55adc6b8f0cee063c2cf2e14782773b0087fbsalomon@google.com * calling unlockScratchTexture we simply don't re-add it. It will be 99195ed55adc6b8f0cee063c2cf2e14782773b0087fbsalomon@google.com * reattached in GrTexture::internal_dispose. 99215c0fea699b25343fe6f49668a5632866e1a0306robertphillips@google.com * 99315c0fea699b25343fe6f49668a5632866e1a0306robertphillips@google.com * Note that the caller is assumed to accept and manage the ref to the 99415c0fea699b25343fe6f49668a5632866e1a0306robertphillips@google.com * returned texture. 99515c0fea699b25343fe6f49668a5632866e1a0306robertphillips@google.com */ 99615c0fea699b25343fe6f49668a5632866e1a0306robertphillips@google.com GrTexture* detach() { 9973f4ea26ff5794547c4c7ff40b265700fff551521commit-bot@chromium.org if (NULL == fTexture) { 9983f4ea26ff5794547c4c7ff40b265700fff551521commit-bot@chromium.org return NULL; 9993f4ea26ff5794547c4c7ff40b265700fff551521commit-bot@chromium.org } 100095ed55adc6b8f0cee063c2cf2e14782773b0087fbsalomon@google.com GrTexture* texture = fTexture; 10011f47f4f7325971dd53991e2bb02da94fa7c6d962robertphillips@google.com fTexture = NULL; 100215c0fea699b25343fe6f49668a5632866e1a0306robertphillips@google.com 100395ed55adc6b8f0cee063c2cf2e14782773b0087fbsalomon@google.com // This GrAutoScratchTexture has a ref from lockAndRefScratchTexture, which we give up now. 100495ed55adc6b8f0cee063c2cf2e14782773b0087fbsalomon@google.com // The cache also has a ref which we are lending to the caller of detach(). When the caller 100595ed55adc6b8f0cee063c2cf2e14782773b0087fbsalomon@google.com // lets go of the ref and the ref count goes to 0 internal_dispose will see this flag is 100695ed55adc6b8f0cee063c2cf2e14782773b0087fbsalomon@google.com // set and re-ref the texture, thereby restoring the cache's ref. 1007f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org SkASSERT(texture->getRefCnt() > 1); 100895ed55adc6b8f0cee063c2cf2e14782773b0087fbsalomon@google.com texture->setFlag((GrTextureFlags) GrTexture::kReturnToCache_FlagBit); 100995ed55adc6b8f0cee063c2cf2e14782773b0087fbsalomon@google.com texture->unref(); 1010f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org SkASSERT(NULL != texture->getCacheEntry()); 101195ed55adc6b8f0cee063c2cf2e14782773b0087fbsalomon@google.com 101295ed55adc6b8f0cee063c2cf2e14782773b0087fbsalomon@google.com return texture; 101315c0fea699b25343fe6f49668a5632866e1a0306robertphillips@google.com } 101415c0fea699b25343fe6f49668a5632866e1a0306robertphillips@google.com 101550398bf7f1953e640e5529616e710cf540799731bsalomon@google.com GrTexture* set(GrContext* context, 101650398bf7f1953e640e5529616e710cf540799731bsalomon@google.com const GrTextureDesc& desc, 10170797c2cceadd7dfc2e7f9efa30b611d18efcdcddbsalomon@google.com GrContext::ScratchTexMatch match = GrContext::kApprox_ScratchTexMatch) { 10189ec075366ed94802a142fc5e948d19a774f85b43robertphillips@google.com this->reset(); 10199ec075366ed94802a142fc5e948d19a774f85b43robertphillips@google.com 102050398bf7f1953e640e5529616e710cf540799731bsalomon@google.com fContext = context; 102150398bf7f1953e640e5529616e710cf540799731bsalomon@google.com if (NULL != fContext) { 102295ed55adc6b8f0cee063c2cf2e14782773b0087fbsalomon@google.com fTexture = fContext->lockAndRefScratchTexture(desc, match); 10231f47f4f7325971dd53991e2bb02da94fa7c6d962robertphillips@google.com if (NULL == fTexture) { 102450398bf7f1953e640e5529616e710cf540799731bsalomon@google.com fContext = NULL; 102550398bf7f1953e640e5529616e710cf540799731bsalomon@google.com } 10261f47f4f7325971dd53991e2bb02da94fa7c6d962robertphillips@google.com return fTexture; 102750398bf7f1953e640e5529616e710cf540799731bsalomon@google.com } else { 102850398bf7f1953e640e5529616e710cf540799731bsalomon@google.com return NULL; 102950398bf7f1953e640e5529616e710cf540799731bsalomon@google.com } 103050398bf7f1953e640e5529616e710cf540799731bsalomon@google.com } 103150398bf7f1953e640e5529616e710cf540799731bsalomon@google.com 10321f47f4f7325971dd53991e2bb02da94fa7c6d962robertphillips@google.com GrTexture* texture() { return fTexture; } 10331f47f4f7325971dd53991e2bb02da94fa7c6d962robertphillips@google.com 1034aadd9f8b193aa70e3dc30cbe5c4e1bc5c1d047basenorblanco@chromium.orgprivate: 103550398bf7f1953e640e5529616e710cf540799731bsalomon@google.com GrContext* fContext; 10361f47f4f7325971dd53991e2bb02da94fa7c6d962robertphillips@google.com GrTexture* fTexture; 1037aadd9f8b193aa70e3dc30cbe5c4e1bc5c1d047basenorblanco@chromium.org}; 1038aadd9f8b193aa70e3dc30cbe5c4e1bc5c1d047basenorblanco@chromium.org 103927847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com#endif 1040