2 * Copyright 2011 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
9 #ifndef GrGLRenderTarget_DEFINED
10 #define GrGLRenderTarget_DEFINED
12 #include "GrGLIRect.h"
13 #include "GrRenderTarget.h"
18 class GrGLRenderTarget : public GrRenderTarget {
20 // set fTexFBOID to this value to indicate that it is multisampled but
21 // Gr doesn't know how to resolve it.
22 enum { kUnresolvableFBOID = 0 };
27 GrGLuint fMSColorRenderbufferID;
31 GrGLRenderTarget(GrGpuGL*, const GrSurfaceDesc&, const IDDesc&);
33 virtual ~GrGLRenderTarget() { this->release(); }
35 void setViewport(const GrGLIRect& rect) { fViewport = rect; }
36 const GrGLIRect& getViewport() const { return fViewport; }
38 // The following two functions return the same ID when a
39 // texture/render target is multisampled, and different IDs when
41 // FBO ID used to render into
42 GrGLuint renderFBOID() const { return fRTFBOID; }
43 // FBO ID that has texture ID attached.
44 GrGLuint textureFBOID() const { return fTexFBOID; }
46 // override of GrRenderTarget
47 virtual GrBackendObject getRenderTargetHandle() const { return this->renderFBOID(); }
48 virtual GrBackendObject getRenderTargetResolvedHandle() const { return this->textureFBOID(); }
49 virtual ResolveType getResolveType() const {
50 if (!this->isMultisampled() ||
51 fRTFBOID == fTexFBOID) {
52 // catches FBO 0 and non MSAA case
53 return kAutoResolves_ResolveType;
54 } else if (kUnresolvableFBOID == fTexFBOID) {
55 return kCantResolve_ResolveType;
57 return kCanResolve_ResolveType;
61 virtual size_t gpuMemorySize() const SK_OVERRIDE;
64 // The public constructor registers this object with the cache. However, only the most derived
65 // class should register with the cache. This constructor does not do the registration and
66 // rather moves that burden onto the derived class.
67 enum Derived { kDerived };
68 GrGLRenderTarget(GrGpuGL*, const GrSurfaceDesc&, const IDDesc&, Derived);
70 void init(const GrSurfaceDesc&, const IDDesc&);
72 virtual void onAbandon() SK_OVERRIDE;
73 virtual void onRelease() SK_OVERRIDE;
78 GrGLuint fMSColorRenderbufferID;
80 // when we switch to this render target we want to set the viewport to
81 // only render to content area (as opposed to the whole allocation) and
82 // we want the rendering to be at top left (GL has origin in bottom left)
85 // gpuMemorySize() needs to know what how many color values are owned per pixel. However,
86 // abandon and release zero out the IDs and the cache needs to know the size even after those
88 uint8_t fColorValuesPerPixel;
90 typedef GrRenderTarget INHERITED;