aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/image/SkImage_Gpu.h
blob: a36c8ebc135ca403db2e845864f9a375ad92cb54 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
 * Copyright 2015 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef SkImage_Gpu_DEFINED
#define SkImage_Gpu_DEFINED

#include "SkAtomics.h"
#include "GrTexture.h"
#include "GrGpuResourcePriv.h"
#include "SkBitmap.h"
#include "SkImage_Base.h"
#include "SkImagePriv.h"
#include "SkSurface.h"

class SkImage_Gpu : public SkImage_Base {
public:
    /**
     *  An "image" can be a subset/window into a larger texture, so we explicit take the
     *  width and height.
     */
    SkImage_Gpu(int w, int h, uint32_t uniqueID, SkAlphaType, GrTexture*, SkSurface::Budgeted);
    ~SkImage_Gpu() override;

    void applyBudgetDecision() const {
        GrTexture* tex = this->getTexture();
        SkASSERT(tex);
        if (fBudgeted) {
            tex->resourcePriv().makeBudgeted();
        } else {
            tex->resourcePriv().makeUnbudgeted();
        }
    }

    bool getROPixels(SkBitmap*, CachingHint) const override;
    GrTexture* asTextureRef(GrContext* ctx, const GrTextureParams& params) const override;
    SkImage* onNewSubset(const SkIRect&) const override;

    GrTexture* peekTexture() const override { return fTexture; }
    bool isOpaque() const override;
    bool onReadPixels(const SkImageInfo&, void* dstPixels, size_t dstRowBytes,
                      int srcX, int srcY, CachingHint) const override;

    SkSurface* onNewSurface(const SkImageInfo& info) const override {
        return SkSurface::NewRenderTarget(fTexture->getContext(), SkSurface::kNo_Budgeted, info);
    }

    bool asBitmapForImageFilters(SkBitmap* bitmap) const override;

private:
    SkAutoTUnref<GrTexture>     fTexture;
    const SkAlphaType           fAlphaType;
    const SkSurface::Budgeted   fBudgeted;
    mutable SkAtomic<bool>      fAddedRasterVersionToCache;


    typedef SkImage_Base INHERITED;
};

#endif