Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / skia / src / gpu / gl / GrGLRenderTarget.h
1 /*
2  * Copyright 2011 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7
8
9 #ifndef GrGLRenderTarget_DEFINED
10 #define GrGLRenderTarget_DEFINED
11
12 #include "GrGLIRect.h"
13 #include "GrRenderTarget.h"
14 #include "SkScalar.h"
15
16 class GrGpuGL;
17
18 class GrGLRenderTarget : public GrRenderTarget {
19 public:
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 };
23
24     struct IDDesc {
25         GrGLuint         fRTFBOID;
26         GrGLuint         fTexFBOID;
27         GrGLuint         fMSColorRenderbufferID;
28         bool             fIsWrapped;
29     };
30
31     GrGLRenderTarget(GrGpuGL*, const GrSurfaceDesc&, const IDDesc&);
32
33     virtual ~GrGLRenderTarget() { this->release(); }
34
35     void setViewport(const GrGLIRect& rect) { fViewport = rect; }
36     const GrGLIRect& getViewport() const { return fViewport; }
37
38     // The following two functions return the same ID when a
39     // texture/render target is multisampled, and different IDs when
40     // it is.
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; }
45
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;
56         } else {
57             return kCanResolve_ResolveType;
58         }
59     }
60
61     virtual size_t gpuMemorySize() const SK_OVERRIDE;
62
63 protected:
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);
69
70     void init(const GrSurfaceDesc&, const IDDesc&);
71
72     virtual void onAbandon() SK_OVERRIDE;
73     virtual void onRelease() SK_OVERRIDE;
74
75 private:
76     GrGLuint      fRTFBOID;
77     GrGLuint      fTexFBOID;
78     GrGLuint      fMSColorRenderbufferID;
79
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)
83     GrGLIRect fViewport;
84
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
87     // actions.
88     uint8_t fColorValuesPerPixel;
89
90     typedef GrRenderTarget INHERITED;
91 };
92
93 #endif