1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com/* 2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2011 Google Inc. 3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * 4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be 5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file. 6ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 7ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 8ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com 9ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#ifndef GrGLTexture_DEFINED 10ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#define GrGLTexture_DEFINED 11ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 12d8f856c32b679d9f5a9926feac005e2c0186f83ftomhudson@google.com#include "GrGpu.h" 13aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com#include "GrGLRenderTarget.h" 14ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 151da0746fa155cdca982ae8deb68cc64f540c92dfbsalomon@google.com/** 161da0746fa155cdca982ae8deb68cc64f540c92dfbsalomon@google.com * A ref counted tex id that deletes the texture in its destructor. 171da0746fa155cdca982ae8deb68cc64f540c92dfbsalomon@google.com */ 18a4de8c257ea0be8ff7081f645249b6afe5c48e7ecommit-bot@chromium.orgclass GrGLTexID : public SkRefCnt { 191da0746fa155cdca982ae8deb68cc64f540c92dfbsalomon@google.compublic: 20fa35e3ddcc9d130ce87c927218bdf27879c38711reed@google.com SK_DECLARE_INST_COUNT(GrGLTexID) 21fa35e3ddcc9d130ce87c927218bdf27879c38711reed@google.com 22728302281920727b96e6cec0bfc7575900f34a8bbsalomon@google.com GrGLTexID(const GrGLInterface* gl, GrGLuint texID, bool isWrapped) 230b77d6892b067ad402c9678b0226bff70599fbe2bsalomon@google.com : fGL(gl) 240b77d6892b067ad402c9678b0226bff70599fbe2bsalomon@google.com , fTexID(texID) 25728302281920727b96e6cec0bfc7575900f34a8bbsalomon@google.com , fIsWrapped(isWrapped) { 260b77d6892b067ad402c9678b0226bff70599fbe2bsalomon@google.com } 271da0746fa155cdca982ae8deb68cc64f540c92dfbsalomon@google.com 281da0746fa155cdca982ae8deb68cc64f540c92dfbsalomon@google.com virtual ~GrGLTexID() { 29728302281920727b96e6cec0bfc7575900f34a8bbsalomon@google.com if (0 != fTexID && !fIsWrapped) { 300b77d6892b067ad402c9678b0226bff70599fbe2bsalomon@google.com GR_GL_CALL(fGL, DeleteTextures(1, &fTexID)); 311da0746fa155cdca982ae8deb68cc64f540c92dfbsalomon@google.com } 321da0746fa155cdca982ae8deb68cc64f540c92dfbsalomon@google.com } 331da0746fa155cdca982ae8deb68cc64f540c92dfbsalomon@google.com 341da0746fa155cdca982ae8deb68cc64f540c92dfbsalomon@google.com void abandon() { fTexID = 0; } 350f31ca79bde088e6caac219734c35c1ae3e9e8b9twiz@google.com GrGLuint id() const { return fTexID; } 361da0746fa155cdca982ae8deb68cc64f540c92dfbsalomon@google.com 371da0746fa155cdca982ae8deb68cc64f540c92dfbsalomon@google.comprivate: 380b77d6892b067ad402c9678b0226bff70599fbe2bsalomon@google.com const GrGLInterface* fGL; 390b77d6892b067ad402c9678b0226bff70599fbe2bsalomon@google.com GrGLuint fTexID; 40728302281920727b96e6cec0bfc7575900f34a8bbsalomon@google.com bool fIsWrapped; 41fa35e3ddcc9d130ce87c927218bdf27879c38711reed@google.com 42a4de8c257ea0be8ff7081f645249b6afe5c48e7ecommit-bot@chromium.org typedef SkRefCnt INHERITED; 431da0746fa155cdca982ae8deb68cc64f540c92dfbsalomon@google.com}; 441da0746fa155cdca982ae8deb68cc64f540c92dfbsalomon@google.com 455877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com//////////////////////////////////////////////////////////////////////////////// 465877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com 475877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com 48e49157f0838c615b10da0ef2b297c742da662e34commit-bot@chromium.orgclass GrGLTexture : public GrTextureImpl { 498fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com 50ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.compublic: 51da96ea01fe2a7f4237712c68fae2b96d3523b0f5bsalomon@google.com struct TexParams { 52149f4f5b4013f3d28017fd548e43b69133be83c3commit-bot@chromium.org GrGLenum fMinFilter; 53149f4f5b4013f3d28017fd548e43b69133be83c3commit-bot@chromium.org GrGLenum fMagFilter; 540f31ca79bde088e6caac219734c35c1ae3e9e8b9twiz@google.com GrGLenum fWrapS; 550f31ca79bde088e6caac219734c35c1ae3e9e8b9twiz@google.com GrGLenum fWrapT; 560a97be216df494291fe929b79d438809af7e9c83bsalomon@google.com GrGLenum fSwizzleRGBA[4]; 575877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com void invalidate() { memset(this, 0xff, sizeof(TexParams)); } 58da96ea01fe2a7f4237712c68fae2b96d3523b0f5bsalomon@google.com }; 59ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 6032716283420df90644c8b8114308f7967aa91d9frobertphillips@google.com struct Desc : public GrTextureDesc { 615877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com GrGLuint fTextureID; 62728302281920727b96e6cec0bfc7575900f34a8bbsalomon@google.com bool fIsWrapped; 635877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com }; 645877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com 655bfc21761e0ce41206acac4c5008fc0f24debd44bsalomon@google.com // creates a texture that is also an RT 665bfc21761e0ce41206acac4c5008fc0f24debd44bsalomon@google.com GrGLTexture(GrGpuGL* gpu, 675bfc21761e0ce41206acac4c5008fc0f24debd44bsalomon@google.com const Desc& textureDesc, 6880d09b9f7eb653103ca5fa10471e582c44f5b9debsalomon@google.com const GrGLRenderTarget::Desc& rtDesc); 695877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com 705bfc21761e0ce41206acac4c5008fc0f24debd44bsalomon@google.com // creates a non-RT texture 715877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com GrGLTexture(GrGpuGL* gpu, 7280d09b9f7eb653103ca5fa10471e582c44f5b9debsalomon@google.com const Desc& textureDesc); 735877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com 748fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com virtual ~GrGLTexture() { this->release(); } 75ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 7608afc843c074429a9848d8d165e6b898e3e7d371bsalomon@google.com virtual GrBackendObject getTextureHandle() const SK_OVERRIDE; 77957ebddce1764c30ec02f7e2e34d6c5cdc16007bjunov@chromium.org 78e49157f0838c615b10da0ef2b297c742da662e34commit-bot@chromium.org virtual void textureParamsModified() SK_OVERRIDE { fTexParams.invalidate(); } 79ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 8059e16e4e1d30eee3ce564e0b513d952579065cb3commit-bot@chromium.org // These functions are used to track the texture parameters associated with the texture. 8180d09b9f7eb653103ca5fa10471e582c44f5b9debsalomon@google.com const TexParams& getCachedTexParams(GrGpu::ResetTimestamp* timestamp) const { 8280d09b9f7eb653103ca5fa10471e582c44f5b9debsalomon@google.com *timestamp = fTexParamsTimestamp; 8380d09b9f7eb653103ca5fa10471e582c44f5b9debsalomon@google.com return fTexParams; 8480d09b9f7eb653103ca5fa10471e582c44f5b9debsalomon@google.com } 8559e16e4e1d30eee3ce564e0b513d952579065cb3commit-bot@chromium.org 8680d09b9f7eb653103ca5fa10471e582c44f5b9debsalomon@google.com void setCachedTexParams(const TexParams& texParams, 8780d09b9f7eb653103ca5fa10471e582c44f5b9debsalomon@google.com GrGpu::ResetTimestamp timestamp) { 8880d09b9f7eb653103ca5fa10471e582c44f5b9debsalomon@google.com fTexParams = texParams; 8980d09b9f7eb653103ca5fa10471e582c44f5b9debsalomon@google.com fTexParamsTimestamp = timestamp; 9080d09b9f7eb653103ca5fa10471e582c44f5b9debsalomon@google.com } 91ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 9259e16e4e1d30eee3ce564e0b513d952579065cb3commit-bot@chromium.org GrGLuint textureID() const { return (NULL != fTexIDObj.get()) ? fTexIDObj->id() : 0; } 938fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com 9459e16e4e1d30eee3ce564e0b513d952579065cb3commit-bot@chromium.orgprotected: 956dcf499d3578eff9ab5aead0d195fc0cb02c796bbsalomon@google.com // overrides of GrTexture 96957ebddce1764c30ec02f7e2e34d6c5cdc16007bjunov@chromium.org virtual void onAbandon() SK_OVERRIDE; 97957ebddce1764c30ec02f7e2e34d6c5cdc16007bjunov@chromium.org virtual void onRelease() SK_OVERRIDE; 988fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com 99ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.comprivate: 10080d09b9f7eb653103ca5fa10471e582c44f5b9debsalomon@google.com TexParams fTexParams; 10180d09b9f7eb653103ca5fa10471e582c44f5b9debsalomon@google.com GrGpu::ResetTimestamp fTexParamsTimestamp; 10259e16e4e1d30eee3ce564e0b513d952579065cb3commit-bot@chromium.org SkAutoTUnref<GrGLTexID> fTexIDObj; 103c6cf72381b212eb21e61d5c5e14247b483a77753bsalomon@google.com 1045bfc21761e0ce41206acac4c5008fc0f24debd44bsalomon@google.com void init(GrGpuGL* gpu, 1055bfc21761e0ce41206acac4c5008fc0f24debd44bsalomon@google.com const Desc& textureDesc, 10680d09b9f7eb653103ca5fa10471e582c44f5b9debsalomon@google.com const GrGLRenderTarget::Desc* rtDesc); 1075bfc21761e0ce41206acac4c5008fc0f24debd44bsalomon@google.com 108e49157f0838c615b10da0ef2b297c742da662e34commit-bot@chromium.org typedef GrTextureImpl INHERITED; 109ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com}; 110ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 111ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#endif 112