1ad8a43f7698071f00ce024a935b0bc04a4b19a41Robert Phillips/*
2ad8a43f7698071f00ce024a935b0bc04a4b19a41Robert Phillips * Copyright 2017 Google Inc.
3ad8a43f7698071f00ce024a935b0bc04a4b19a41Robert Phillips *
4ad8a43f7698071f00ce024a935b0bc04a4b19a41Robert Phillips * Use of this source code is governed by a BSD-style license that can be
5ad8a43f7698071f00ce024a935b0bc04a4b19a41Robert Phillips * found in the LICENSE file.
6ad8a43f7698071f00ce024a935b0bc04a4b19a41Robert Phillips */
7ad8a43f7698071f00ce024a935b0bc04a4b19a41Robert Phillips
8ad8a43f7698071f00ce024a935b0bc04a4b19a41Robert Phillips#ifndef SkSurfaceCharacterization_DEFINED
9ad8a43f7698071f00ce024a935b0bc04a4b19a41Robert Phillips#define SkSurfaceCharacterization_DEFINED
10ad8a43f7698071f00ce024a935b0bc04a4b19a41Robert Phillips
11ad8a43f7698071f00ce024a935b0bc04a4b19a41Robert Phillips#include "GrTypes.h"
12ad8a43f7698071f00ce024a935b0bc04a4b19a41Robert Phillips
13620003692923dc6c6df5a1b66288988b6783a69fRobert Phillips#include "SkColorSpace.h"
14620003692923dc6c6df5a1b66288988b6783a69fRobert Phillips#include "SkRefCnt.h"
15e42edcc8ef257d4c430344d6d208e994f20f9320Robert Phillips#include "SkSurfaceProps.h"
16e42edcc8ef257d4c430344d6d208e994f20f9320Robert Phillips
17e42edcc8ef257d4c430344d6d208e994f20f9320Robert Phillipsclass SkColorSpace;
18e42edcc8ef257d4c430344d6d208e994f20f9320Robert Phillips
19620003692923dc6c6df5a1b66288988b6783a69fRobert Phillips// This define can be used to swap between the default (raster) DDL implementation and the
20620003692923dc6c6df5a1b66288988b6783a69fRobert Phillips// gpu implementation.
21620003692923dc6c6df5a1b66288988b6783a69fRobert Phillips#define SK_RASTER_RECORDER_IMPLEMENTATION 1
22ad8a43f7698071f00ce024a935b0bc04a4b19a41Robert Phillips
23620003692923dc6c6df5a1b66288988b6783a69fRobert Phillips#if SK_SUPPORT_GPU
24620003692923dc6c6df5a1b66288988b6783a69fRobert Phillips#include "GrContext.h"
258def8bffe98ee58af6c088f3ab6e4a41f32b732fRobert Phillips
268def8bffe98ee58af6c088f3ab6e4a41f32b732fRobert Phillips/** \class SkSurfaceCharacterization
278def8bffe98ee58af6c088f3ab6e4a41f32b732fRobert Phillips    A surface characterization contains all the information Ganesh requires to makes its internal
288def8bffe98ee58af6c088f3ab6e4a41f32b732fRobert Phillips    rendering decisions. When passed into a SkDeferredDisplayListRecorder it will copy the
298def8bffe98ee58af6c088f3ab6e4a41f32b732fRobert Phillips    data and pass it on to the SkDeferredDisplayList if/when it is created. Note that both of
308def8bffe98ee58af6c088f3ab6e4a41f32b732fRobert Phillips    those objects (the Recorder and the DisplayList) will take a ref on the
317ffbcf909d365eb22c5e22b776aeac7b7472fbf3Robert Phillips    GrContextThreadSafeProxy and SkColorSpace objects.
328def8bffe98ee58af6c088f3ab6e4a41f32b732fRobert Phillips*/
33ad8a43f7698071f00ce024a935b0bc04a4b19a41Robert Phillipsclass SkSurfaceCharacterization {
34ad8a43f7698071f00ce024a935b0bc04a4b19a41Robert Phillipspublic:
35e8fabb2665d12ee289bc3af5b7e93c5b12396e2dRobert Phillips    enum class Textureable : bool { kNo = false, kYes = true };
36e8fabb2665d12ee289bc3af5b7e93c5b12396e2dRobert Phillips    enum class MipMapped : bool { kNo = false, kYes = true };
37e8fabb2665d12ee289bc3af5b7e93c5b12396e2dRobert Phillips
38ad8a43f7698071f00ce024a935b0bc04a4b19a41Robert Phillips    SkSurfaceCharacterization()
39fc711a2b0143aa4f559ef041068af1c04d7dab85Robert Phillips            : fCacheMaxResourceBytes(0)
408d1e67ed6b75909ac20211ae3aec130587920cecRobert Phillips            , fOrigin(kBottomLeft_GrSurfaceOrigin)
41ad8a43f7698071f00ce024a935b0bc04a4b19a41Robert Phillips            , fWidth(0)
42ad8a43f7698071f00ce024a935b0bc04a4b19a41Robert Phillips            , fHeight(0)
4361e51012ee150e12f953bc4225fbdbdc1564007dRobert Phillips            , fConfig(kUnknown_GrPixelConfig)
447ffbcf909d365eb22c5e22b776aeac7b7472fbf3Robert Phillips            , fFSAAType(GrFSAAType::kNone)
457ffbcf909d365eb22c5e22b776aeac7b7472fbf3Robert Phillips            , fStencilCnt(0)
46e8fabb2665d12ee289bc3af5b7e93c5b12396e2dRobert Phillips            , fIsTextureable(Textureable::kYes)
47e8fabb2665d12ee289bc3af5b7e93c5b12396e2dRobert Phillips            , fIsMipMapped(MipMapped::kYes)
4861e51012ee150e12f953bc4225fbdbdc1564007dRobert Phillips            , fSurfaceProps(0, kUnknown_SkPixelGeometry) {
49ad8a43f7698071f00ce024a935b0bc04a4b19a41Robert Phillips    }
50ad8a43f7698071f00ce024a935b0bc04a4b19a41Robert Phillips
518def8bffe98ee58af6c088f3ab6e4a41f32b732fRobert Phillips    SkSurfaceCharacterization(SkSurfaceCharacterization&&) = default;
528def8bffe98ee58af6c088f3ab6e4a41f32b732fRobert Phillips    SkSurfaceCharacterization& operator=(SkSurfaceCharacterization&&) = default;
538def8bffe98ee58af6c088f3ab6e4a41f32b732fRobert Phillips
548def8bffe98ee58af6c088f3ab6e4a41f32b732fRobert Phillips    SkSurfaceCharacterization(const SkSurfaceCharacterization&) = default;
558def8bffe98ee58af6c088f3ab6e4a41f32b732fRobert Phillips    SkSurfaceCharacterization& operator=(const SkSurfaceCharacterization& other) = default;
568def8bffe98ee58af6c088f3ab6e4a41f32b732fRobert Phillips
5761e51012ee150e12f953bc4225fbdbdc1564007dRobert Phillips    GrContextThreadSafeProxy* contextInfo() const { return fContextInfo.get(); }
58fde6fa0903b3cedc463c1a753268ffcf30ad7a38Robert Phillips    sk_sp<GrContextThreadSafeProxy> refContextInfo() const { return fContextInfo; }
598d1e67ed6b75909ac20211ae3aec130587920cecRobert Phillips    size_t cacheMaxResourceBytes() const { return fCacheMaxResourceBytes; }
608d1e67ed6b75909ac20211ae3aec130587920cecRobert Phillips
61fc711a2b0143aa4f559ef041068af1c04d7dab85Robert Phillips    bool isValid() const { return kUnknown_GrPixelConfig != fConfig; }
62fc711a2b0143aa4f559ef041068af1c04d7dab85Robert Phillips
638def8bffe98ee58af6c088f3ab6e4a41f32b732fRobert Phillips    GrSurfaceOrigin origin() const { return fOrigin; }
648def8bffe98ee58af6c088f3ab6e4a41f32b732fRobert Phillips    int width() const { return fWidth; }
658def8bffe98ee58af6c088f3ab6e4a41f32b732fRobert Phillips    int height() const { return fHeight; }
668def8bffe98ee58af6c088f3ab6e4a41f32b732fRobert Phillips    GrPixelConfig config() const { return fConfig; }
677ffbcf909d365eb22c5e22b776aeac7b7472fbf3Robert Phillips    GrFSAAType fsaaType() const { return fFSAAType; }
687ffbcf909d365eb22c5e22b776aeac7b7472fbf3Robert Phillips    int stencilCount() const { return fStencilCnt; }
69e8fabb2665d12ee289bc3af5b7e93c5b12396e2dRobert Phillips    bool isTextureable() const { return Textureable::kYes == fIsTextureable; }
70e8fabb2665d12ee289bc3af5b7e93c5b12396e2dRobert Phillips    bool isMipMapped() const { return MipMapped::kYes == fIsMipMapped; }
7161e51012ee150e12f953bc4225fbdbdc1564007dRobert Phillips    SkColorSpace* colorSpace() const { return fColorSpace.get(); }
7261e51012ee150e12f953bc4225fbdbdc1564007dRobert Phillips    sk_sp<SkColorSpace> refColorSpace() const { return fColorSpace; }
7361e51012ee150e12f953bc4225fbdbdc1564007dRobert Phillips    const SkSurfaceProps& surfaceProps()const { return fSurfaceProps; }
748def8bffe98ee58af6c088f3ab6e4a41f32b732fRobert Phillips
758def8bffe98ee58af6c088f3ab6e4a41f32b732fRobert Phillipsprivate:
768def8bffe98ee58af6c088f3ab6e4a41f32b732fRobert Phillips    friend class SkSurface_Gpu; // for 'set'
77fc711a2b0143aa4f559ef041068af1c04d7dab85Robert Phillips    friend class GrContextThreadSafeProxy; // for private ctor
78fc711a2b0143aa4f559ef041068af1c04d7dab85Robert Phillips
79fc711a2b0143aa4f559ef041068af1c04d7dab85Robert Phillips    SkSurfaceCharacterization(sk_sp<GrContextThreadSafeProxy> contextInfo,
80fc711a2b0143aa4f559ef041068af1c04d7dab85Robert Phillips                              size_t cacheMaxResourceBytes,
81fc711a2b0143aa4f559ef041068af1c04d7dab85Robert Phillips                              GrSurfaceOrigin origin, int width, int height,
82fc711a2b0143aa4f559ef041068af1c04d7dab85Robert Phillips                              GrPixelConfig config, GrFSAAType FSAAType, int stencilCnt,
83fc711a2b0143aa4f559ef041068af1c04d7dab85Robert Phillips                              Textureable isTextureable, MipMapped isMipMapped,
84fc711a2b0143aa4f559ef041068af1c04d7dab85Robert Phillips                              sk_sp<SkColorSpace> colorSpace,
85fc711a2b0143aa4f559ef041068af1c04d7dab85Robert Phillips                              const SkSurfaceProps& surfaceProps)
86fc711a2b0143aa4f559ef041068af1c04d7dab85Robert Phillips            : fContextInfo(std::move(contextInfo))
87fc711a2b0143aa4f559ef041068af1c04d7dab85Robert Phillips            , fCacheMaxResourceBytes(cacheMaxResourceBytes)
88fc711a2b0143aa4f559ef041068af1c04d7dab85Robert Phillips            , fOrigin(origin)
89fc711a2b0143aa4f559ef041068af1c04d7dab85Robert Phillips            , fWidth(width)
90fc711a2b0143aa4f559ef041068af1c04d7dab85Robert Phillips            , fHeight(height)
91fc711a2b0143aa4f559ef041068af1c04d7dab85Robert Phillips            , fConfig(config)
92fc711a2b0143aa4f559ef041068af1c04d7dab85Robert Phillips            , fFSAAType(FSAAType)
93fc711a2b0143aa4f559ef041068af1c04d7dab85Robert Phillips            , fStencilCnt(stencilCnt)
94fc711a2b0143aa4f559ef041068af1c04d7dab85Robert Phillips            , fIsTextureable(isTextureable)
95fc711a2b0143aa4f559ef041068af1c04d7dab85Robert Phillips            , fIsMipMapped(isMipMapped)
96fc711a2b0143aa4f559ef041068af1c04d7dab85Robert Phillips            , fColorSpace(std::move(colorSpace))
97fc711a2b0143aa4f559ef041068af1c04d7dab85Robert Phillips            , fSurfaceProps(surfaceProps) {
98fc711a2b0143aa4f559ef041068af1c04d7dab85Robert Phillips    }
998def8bffe98ee58af6c088f3ab6e4a41f32b732fRobert Phillips
10061e51012ee150e12f953bc4225fbdbdc1564007dRobert Phillips    void set(sk_sp<GrContextThreadSafeProxy> contextInfo,
1018d1e67ed6b75909ac20211ae3aec130587920cecRobert Phillips             size_t cacheMaxResourceBytes,
10261e51012ee150e12f953bc4225fbdbdc1564007dRobert Phillips             GrSurfaceOrigin origin,
103ad8a43f7698071f00ce024a935b0bc04a4b19a41Robert Phillips             int width, int height,
104ad8a43f7698071f00ce024a935b0bc04a4b19a41Robert Phillips             GrPixelConfig config,
1057ffbcf909d365eb22c5e22b776aeac7b7472fbf3Robert Phillips             GrFSAAType fsaaType,
1067ffbcf909d365eb22c5e22b776aeac7b7472fbf3Robert Phillips             int stencilCnt,
107e8fabb2665d12ee289bc3af5b7e93c5b12396e2dRobert Phillips             Textureable isTextureable,
108e8fabb2665d12ee289bc3af5b7e93c5b12396e2dRobert Phillips             MipMapped isMipMapped,
10961e51012ee150e12f953bc4225fbdbdc1564007dRobert Phillips             sk_sp<SkColorSpace> colorSpace,
11061e51012ee150e12f953bc4225fbdbdc1564007dRobert Phillips             const SkSurfaceProps& surfaceProps) {
111e8fabb2665d12ee289bc3af5b7e93c5b12396e2dRobert Phillips        SkASSERT(MipMapped::kNo == isMipMapped || Textureable::kYes == isTextureable);
112e8fabb2665d12ee289bc3af5b7e93c5b12396e2dRobert Phillips
11361e51012ee150e12f953bc4225fbdbdc1564007dRobert Phillips        fContextInfo = contextInfo;
1148d1e67ed6b75909ac20211ae3aec130587920cecRobert Phillips        fCacheMaxResourceBytes = cacheMaxResourceBytes;
1158d1e67ed6b75909ac20211ae3aec130587920cecRobert Phillips
116ad8a43f7698071f00ce024a935b0bc04a4b19a41Robert Phillips        fOrigin = origin;
117ad8a43f7698071f00ce024a935b0bc04a4b19a41Robert Phillips        fWidth = width;
118ad8a43f7698071f00ce024a935b0bc04a4b19a41Robert Phillips        fHeight = height;
119ad8a43f7698071f00ce024a935b0bc04a4b19a41Robert Phillips        fConfig = config;
1207ffbcf909d365eb22c5e22b776aeac7b7472fbf3Robert Phillips        fFSAAType = fsaaType;
1217ffbcf909d365eb22c5e22b776aeac7b7472fbf3Robert Phillips        fStencilCnt = stencilCnt;
122e8fabb2665d12ee289bc3af5b7e93c5b12396e2dRobert Phillips        fIsTextureable = isTextureable;
123e8fabb2665d12ee289bc3af5b7e93c5b12396e2dRobert Phillips        fIsMipMapped = isMipMapped;
12461e51012ee150e12f953bc4225fbdbdc1564007dRobert Phillips        fColorSpace = std::move(colorSpace);
12561e51012ee150e12f953bc4225fbdbdc1564007dRobert Phillips        fSurfaceProps = surfaceProps;
126ad8a43f7698071f00ce024a935b0bc04a4b19a41Robert Phillips    }
127ad8a43f7698071f00ce024a935b0bc04a4b19a41Robert Phillips
12861e51012ee150e12f953bc4225fbdbdc1564007dRobert Phillips    sk_sp<GrContextThreadSafeProxy> fContextInfo;
1298d1e67ed6b75909ac20211ae3aec130587920cecRobert Phillips    size_t                          fCacheMaxResourceBytes;
1308d1e67ed6b75909ac20211ae3aec130587920cecRobert Phillips
1318def8bffe98ee58af6c088f3ab6e4a41f32b732fRobert Phillips    GrSurfaceOrigin                 fOrigin;
1328def8bffe98ee58af6c088f3ab6e4a41f32b732fRobert Phillips    int                             fWidth;
1338def8bffe98ee58af6c088f3ab6e4a41f32b732fRobert Phillips    int                             fHeight;
1348def8bffe98ee58af6c088f3ab6e4a41f32b732fRobert Phillips    GrPixelConfig                   fConfig;
1357ffbcf909d365eb22c5e22b776aeac7b7472fbf3Robert Phillips    GrFSAAType                      fFSAAType;
1367ffbcf909d365eb22c5e22b776aeac7b7472fbf3Robert Phillips    int                             fStencilCnt;
137e8fabb2665d12ee289bc3af5b7e93c5b12396e2dRobert Phillips    Textureable                     fIsTextureable;
138e8fabb2665d12ee289bc3af5b7e93c5b12396e2dRobert Phillips    MipMapped                       fIsMipMapped;
13961e51012ee150e12f953bc4225fbdbdc1564007dRobert Phillips    sk_sp<SkColorSpace>             fColorSpace;
14061e51012ee150e12f953bc4225fbdbdc1564007dRobert Phillips    SkSurfaceProps                  fSurfaceProps;
1418def8bffe98ee58af6c088f3ab6e4a41f32b732fRobert Phillips};
1428def8bffe98ee58af6c088f3ab6e4a41f32b732fRobert Phillips
1438def8bffe98ee58af6c088f3ab6e4a41f32b732fRobert Phillips#else// !SK_SUPPORT_GPU
1448def8bffe98ee58af6c088f3ab6e4a41f32b732fRobert Phillips
1458def8bffe98ee58af6c088f3ab6e4a41f32b732fRobert Phillipsclass SkSurfaceCharacterization {
1468def8bffe98ee58af6c088f3ab6e4a41f32b732fRobert Phillipspublic:
147e42edcc8ef257d4c430344d6d208e994f20f9320Robert Phillips    SkSurfaceCharacterization()
148e42edcc8ef257d4c430344d6d208e994f20f9320Robert Phillips            : fWidth(0)
149e42edcc8ef257d4c430344d6d208e994f20f9320Robert Phillips            , fHeight(0)
150e42edcc8ef257d4c430344d6d208e994f20f9320Robert Phillips            , fSurfaceProps(0, kUnknown_SkPixelGeometry) {
151e42edcc8ef257d4c430344d6d208e994f20f9320Robert Phillips    }
1528def8bffe98ee58af6c088f3ab6e4a41f32b732fRobert Phillips
153fc711a2b0143aa4f559ef041068af1c04d7dab85Robert Phillips    bool isValid() const { return false; }
154fc711a2b0143aa4f559ef041068af1c04d7dab85Robert Phillips
155ad8a43f7698071f00ce024a935b0bc04a4b19a41Robert Phillips    int width() const { return fWidth; }
156ad8a43f7698071f00ce024a935b0bc04a4b19a41Robert Phillips    int height() const { return fHeight; }
157e42edcc8ef257d4c430344d6d208e994f20f9320Robert Phillips    SkColorSpace* colorSpace() const { return fColorSpace.get(); }
158e42edcc8ef257d4c430344d6d208e994f20f9320Robert Phillips    sk_sp<SkColorSpace> refColorSpace() const { return fColorSpace; }
159e42edcc8ef257d4c430344d6d208e994f20f9320Robert Phillips    const SkSurfaceProps& surfaceProps()const { return fSurfaceProps; }
160ad8a43f7698071f00ce024a935b0bc04a4b19a41Robert Phillips
161ad8a43f7698071f00ce024a935b0bc04a4b19a41Robert Phillipsprivate:
1628def8bffe98ee58af6c088f3ab6e4a41f32b732fRobert Phillips    int                             fWidth;
1638def8bffe98ee58af6c088f3ab6e4a41f32b732fRobert Phillips    int                             fHeight;
164e42edcc8ef257d4c430344d6d208e994f20f9320Robert Phillips    sk_sp<SkColorSpace>             fColorSpace;
165e42edcc8ef257d4c430344d6d208e994f20f9320Robert Phillips    SkSurfaceProps                  fSurfaceProps;
166ad8a43f7698071f00ce024a935b0bc04a4b19a41Robert Phillips};
167ad8a43f7698071f00ce024a935b0bc04a4b19a41Robert Phillips
168ad8a43f7698071f00ce024a935b0bc04a4b19a41Robert Phillips#endif
1698def8bffe98ee58af6c088f3ab6e4a41f32b732fRobert Phillips
1708def8bffe98ee58af6c088f3ab6e4a41f32b732fRobert Phillips#endif
171