blob: e68ef8896a85777d4880cef8a86babc7f8a78e5a [file] [log] [blame]
robertphillips76948d42016-05-04 12:47:41 -07001/*
2 * Copyright 2016 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#ifndef GrTextureProxy_DEFINED
9#define GrTextureProxy_DEFINED
10
11#include "GrSurfaceProxy.h"
12#include "GrTexture.h"
13
Robert Phillips84a81202016-11-04 11:59:10 -040014class GrCaps;
robertphillips76948d42016-05-04 12:47:41 -070015class GrTextureProvider;
16
17// This class delays the acquisition of textures until they are actually required
Robert Phillips84a81202016-11-04 11:59:10 -040018class GrTextureProxy : virtual public GrSurfaceProxy {
robertphillips76948d42016-05-04 12:47:41 -070019public:
20 // TODO: need to refine ownership semantics of 'srcData' if we're in completely
21 // deferred mode
Robert Phillips84a81202016-11-04 11:59:10 -040022 static sk_sp<GrTextureProxy> Make(const GrCaps&, GrTextureProvider*, const GrSurfaceDesc&,
Robert Phillips8bc06d02016-11-01 17:28:40 -040023 SkBackingFit, SkBudgeted,
robertphillips76948d42016-05-04 12:47:41 -070024 const void* srcData = nullptr, size_t rowBytes = 0);
25 static sk_sp<GrTextureProxy> Make(sk_sp<GrTexture>);
26
27 // TODO: add asRenderTargetProxy variants
28 GrTextureProxy* asTextureProxy() override { return this; }
29 const GrTextureProxy* asTextureProxy() const override { return this; }
30
31 // Actually instantiate the backing texture, if necessary
Robert Phillips8bc06d02016-11-01 17:28:40 -040032 GrTexture* instantiate(GrTextureProvider*);
robertphillips76948d42016-05-04 12:47:41 -070033
Robert Phillips84a81202016-11-04 11:59:10 -040034protected:
robertphillips8abb3702016-08-31 14:04:06 -070035 // Deferred version
36 GrTextureProxy(const GrSurfaceDesc& srcDesc, SkBackingFit, SkBudgeted,
37 const void* srcData, size_t srcRowBytes);
robertphillips76948d42016-05-04 12:47:41 -070038 // Wrapped version
39 GrTextureProxy(sk_sp<GrTexture> tex);
40
Robert Phillips84a81202016-11-04 11:59:10 -040041private:
Robert Phillips8bc06d02016-11-01 17:28:40 -040042 size_t onGpuMemorySize() const override;
43
Robert Phillipsc7635fa2016-10-28 13:25:24 -040044 // For wrapped proxies the GrTexture pointer is stored in GrIORefProxy.
45 // For deferred proxies that pointer will be filled n when we need to instantiate
46 // the deferred resource
robertphillips76948d42016-05-04 12:47:41 -070047
48 typedef GrSurfaceProxy INHERITED;
49};
50
51#endif