blob: 7ff8d490e038abdc8e9e9e4c2c0774434a68d09d [file] [log] [blame]
bsalomon37dd3312014-11-03 08:47:23 -08001/*
2 * Copyright 2014 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 GrGLTextureRenderTarget_DEFINED
10#define GrGLTextureRenderTarget_DEFINED
11
ericrk0a5fa482015-09-15 14:16:10 -070012#include "GrGLGpu.h"
bsalomon37dd3312014-11-03 08:47:23 -080013#include "GrGLTexture.h"
14#include "GrGLRenderTarget.h"
Robert Phillipsd6214d42016-11-07 08:23:48 -050015#include "GrTexturePriv.h"
bsalomon37dd3312014-11-03 08:47:23 -080016
bsalomon861e1032014-12-16 07:33:49 -080017class GrGLGpu;
bsalomon37dd3312014-11-03 08:47:23 -080018
19#ifdef SK_BUILD_FOR_WIN
20// Windows gives bogus warnings about inheriting asTexture/asRenderTarget via dominance.
21#pragma warning(push)
22#pragma warning(disable: 4250)
23#endif
24
25class GrGLTextureRenderTarget : public GrGLTexture, public GrGLRenderTarget {
26public:
27 // We're virtually derived from GrSurface (via both GrGLTexture and GrGLRenderTarget) so its
28 // constructor must be explicitly called.
bsalomon861e1032014-12-16 07:33:49 -080029 GrGLTextureRenderTarget(GrGLGpu* gpu,
kkinnunen2e6055b2016-04-22 01:48:29 -070030 SkBudgeted budgeted,
bsalomon37dd3312014-11-03 08:47:23 -080031 const GrSurfaceDesc& desc,
32 const GrGLTexture::IDDesc& texIDDesc,
Robert Phillipsd6214d42016-11-07 08:23:48 -050033 const GrGLRenderTarget::IDDesc& rtIDDesc,
34 bool wasMipMapDataProvided)
kkinnunen2e6055b2016-04-22 01:48:29 -070035 : GrSurface(gpu, desc)
Robert Phillipsd6214d42016-11-07 08:23:48 -050036 , GrGLTexture(gpu, desc, texIDDesc, wasMipMapDataProvided)
kkinnunen2e6055b2016-04-22 01:48:29 -070037 , GrGLRenderTarget(gpu, desc, rtIDDesc) {
38 this->registerWithCache(budgeted);
bsalomon37dd3312014-11-03 08:47:23 -080039 }
40
kkinnunen2e6055b2016-04-22 01:48:29 -070041 bool canAttemptStencilAttachment() const override;
42
ericrk0a5fa482015-09-15 14:16:10 -070043 void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const override;
44
bungeman6bd52842016-10-27 09:30:08 -070045 static sk_sp<GrGLTextureRenderTarget> MakeWrapped(GrGLGpu* gpu, const GrSurfaceDesc& desc,
46 const GrGLTexture::IDDesc& texIDDesc,
47 const GrGLRenderTarget::IDDesc& rtIDDesc);
bsalomon37dd3312014-11-03 08:47:23 -080048protected:
mtklein36352bf2015-03-25 18:17:31 -070049 void onAbandon() override {
bsalomon37dd3312014-11-03 08:47:23 -080050 GrGLRenderTarget::onAbandon();
51 GrGLTexture::onAbandon();
52 }
53
mtklein36352bf2015-03-25 18:17:31 -070054 void onRelease() override {
bsalomon37dd3312014-11-03 08:47:23 -080055 GrGLRenderTarget::onRelease();
56 GrGLTexture::onRelease();
57 }
bsalomon69ed47f2014-11-12 11:13:39 -080058
59private:
kkinnunen2e6055b2016-04-22 01:48:29 -070060 // Constructor for instances wrapping backend objects.
61 GrGLTextureRenderTarget(GrGLGpu* gpu,
62 const GrSurfaceDesc& desc,
63 const GrGLTexture::IDDesc& texIDDesc,
Robert Phillipsd6214d42016-11-07 08:23:48 -050064 const GrGLRenderTarget::IDDesc& rtIDDesc,
65 bool wasMipMapDataProvided)
kkinnunen2e6055b2016-04-22 01:48:29 -070066 : GrSurface(gpu, desc)
Robert Phillipsd6214d42016-11-07 08:23:48 -050067 , GrGLTexture(gpu, desc, texIDDesc, wasMipMapDataProvided)
kkinnunen2e6055b2016-04-22 01:48:29 -070068 , GrGLRenderTarget(gpu, desc, rtIDDesc) {
69 this->registerWithCacheWrapped();
70 }
71
mtklein36352bf2015-03-25 18:17:31 -070072 size_t onGpuMemorySize() const override {
Robert Phillipsd6214d42016-11-07 08:23:48 -050073 return GrSurface::ComputeSize(fDesc,
74 this->numSamplesOwnedPerPixel(),
75 this->texturePriv().hasMipMaps());
bsalomon69ed47f2014-11-12 11:13:39 -080076 }
77
bsalomon37dd3312014-11-03 08:47:23 -080078};
79
80#ifdef SK_BUILD_FOR_WIN
81#pragma warning(pop)
82#endif
83
84#endif