1aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com/* 2aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com * Copyright 2011 Google Inc. 3aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com * 4aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com * Use of this source code is governed by a BSD-style license that can be 5aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com * found in the LICENSE file. 6aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com */ 7aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com 8aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com 9aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com#ifndef GrGLRenderTarget_DEFINED 10aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com#define GrGLRenderTarget_DEFINED 11aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com 12aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com#include "GrGLIRect.h" 13aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com#include "GrRenderTarget.h" 1481712883419f76e25d2ffec38a9438284a45a48dbsalomon@google.com#include "SkScalar.h" 15aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com 16aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.comclass GrGpuGL; 17aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.comclass GrGLTexture; 18aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.comclass GrGLTexID; 19aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com 20aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.comclass GrGLRenderTarget : public GrRenderTarget { 21aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com 22aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.compublic: 23aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com // set fTexFBOID to this value to indicate that it is multisampled but 24aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com // Gr doesn't know how to resolve it. 25aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com enum { kUnresolvableFBOID = 0 }; 26aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com 275bfc21761e0ce41206acac4c5008fc0f24debd44bsalomon@google.com struct Desc { 283cb406bb88f5aa09cf9f5a9554b4b1314cf1a2eesenorblanco@chromium.org GrGLuint fRTFBOID; 293cb406bb88f5aa09cf9f5a9554b4b1314cf1a2eesenorblanco@chromium.org GrGLuint fTexFBOID; 303cb406bb88f5aa09cf9f5a9554b4b1314cf1a2eesenorblanco@chromium.org GrGLuint fMSColorRenderbufferID; 313cb406bb88f5aa09cf9f5a9554b4b1314cf1a2eesenorblanco@chromium.org bool fIsWrapped; 323cb406bb88f5aa09cf9f5a9554b4b1314cf1a2eesenorblanco@chromium.org GrPixelConfig fConfig; 333cb406bb88f5aa09cf9f5a9554b4b1314cf1a2eesenorblanco@chromium.org int fSampleCnt; 343cb406bb88f5aa09cf9f5a9554b4b1314cf1a2eesenorblanco@chromium.org GrSurfaceOrigin fOrigin; 35d0925240efb3732475e62966896716c28e9902b2senorblanco@chromium.org bool fCheckAllocation; 36aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com }; 37aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com 385bfc21761e0ce41206acac4c5008fc0f24debd44bsalomon@google.com // creates a GrGLRenderTarget associated with a texture 395bfc21761e0ce41206acac4c5008fc0f24debd44bsalomon@google.com GrGLRenderTarget(GrGpuGL* gpu, 405bfc21761e0ce41206acac4c5008fc0f24debd44bsalomon@google.com const Desc& desc, 415bfc21761e0ce41206acac4c5008fc0f24debd44bsalomon@google.com const GrGLIRect& viewport, 425bfc21761e0ce41206acac4c5008fc0f24debd44bsalomon@google.com GrGLTexID* texID, 435bfc21761e0ce41206acac4c5008fc0f24debd44bsalomon@google.com GrGLTexture* texture); 445bfc21761e0ce41206acac4c5008fc0f24debd44bsalomon@google.com 455bfc21761e0ce41206acac4c5008fc0f24debd44bsalomon@google.com // creates an independent GrGLRenderTarget 465bfc21761e0ce41206acac4c5008fc0f24debd44bsalomon@google.com GrGLRenderTarget(GrGpuGL* gpu, 475bfc21761e0ce41206acac4c5008fc0f24debd44bsalomon@google.com const Desc& desc, 485bfc21761e0ce41206acac4c5008fc0f24debd44bsalomon@google.com const GrGLIRect& viewport); 49aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com 50aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com virtual ~GrGLRenderTarget() { this->release(); } 51aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com 52aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com void setViewport(const GrGLIRect& rect) { fViewport = rect; } 53aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com const GrGLIRect& getViewport() const { return fViewport; } 54aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com 55fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com // The following two functions return the same ID when a 562d0baded0f45dfde9dc8c25313ff14ea18c0c915bsalomon@google.com // texture/render target is multisampled, and different IDs when 57aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com // it is. 58aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com // FBO ID used to render into 59aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com GrGLuint renderFBOID() const { return fRTFBOID; } 60aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com // FBO ID that has texture ID attached. 61aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com GrGLuint textureFBOID() const { return fTexFBOID; } 62aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com 63fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com // override of GrRenderTarget 6408afc843c074429a9848d8d165e6b898e3e7d371bsalomon@google.com virtual GrBackendObject getRenderTargetHandle() const { 65fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com return this->renderFBOID(); 66aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com } 6708afc843c074429a9848d8d165e6b898e3e7d371bsalomon@google.com virtual GrBackendObject getRenderTargetResolvedHandle() const { 68aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com return this->textureFBOID(); 69aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com } 70aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com virtual ResolveType getResolveType() const { 71e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com 72e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com if (!this->isMultisampled() || 73e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com fRTFBOID == fTexFBOID) { 74aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com // catches FBO 0 and non MSAA case 75aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com return kAutoResolves_ResolveType; 76aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com } else if (kUnresolvableFBOID == fTexFBOID) { 77aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com return kCantResolve_ResolveType; 78aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com } else { 79aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com return kCanResolve_ResolveType; 80aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com } 81aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com } 82aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com 83aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.comprotected: 84aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com // override of GrResource 85d6bbbf8a831cc982cda9b91e84c5600c631af5b2robertphillips@google.com virtual void onAbandon() SK_OVERRIDE; 86d6bbbf8a831cc982cda9b91e84c5600c631af5b2robertphillips@google.com virtual void onRelease() SK_OVERRIDE; 87aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com 88aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.comprivate: 89aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com GrGLuint fRTFBOID; 90aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com GrGLuint fTexFBOID; 9181c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com 92aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com GrGLuint fMSColorRenderbufferID; 93aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com 942d0baded0f45dfde9dc8c25313ff14ea18c0c915bsalomon@google.com // when we switch to this render target we want to set the viewport to 95aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com // only render to to content area (as opposed to the whole allocation) and 96aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com // we want the rendering to be at top left (GL has origin in bottom left) 97aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com GrGLIRect fViewport; 98aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com 99aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com // non-NULL if this RT was created by Gr with an associated GrGLTexture. 10059e16e4e1d30eee3ce564e0b513d952579065cb3commit-bot@chromium.org SkAutoTUnref<GrGLTexID> fTexIDObj; 101aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com 1025bfc21761e0ce41206acac4c5008fc0f24debd44bsalomon@google.com void init(const Desc& desc, const GrGLIRect& viewport, GrGLTexID* texID); 1035bfc21761e0ce41206acac4c5008fc0f24debd44bsalomon@google.com 104aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com typedef GrRenderTarget INHERITED; 105aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com}; 106aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com 107aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com#endif 108