blob: 9327a538b61e974736b60a053e42ccb935178342 [file] [log] [blame]
Robert Phillipsad8a43f2017-08-30 12:06:35 -04001/*
2 * Copyright 2017 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 SkSurfaceCharacterization_DEFINED
9#define SkSurfaceCharacterization_DEFINED
10
11#include "GrTypes.h"
12
Robert Phillips62000362018-02-01 09:10:04 -050013#include "SkColorSpace.h"
14#include "SkRefCnt.h"
Robert Phillips61e51012017-11-30 11:22:14 -050015#include "SkSurfaceProps.h"
Robert Phillipsad8a43f2017-08-30 12:06:35 -040016
Robert Phillips61e51012017-11-30 11:22:14 -050017class SkColorSpace;
Robert Phillips8def8bf2017-11-30 08:46:03 -050018
Robert Phillips62000362018-02-01 09:10:04 -050019// This define can be used to swap between the default (raster) DDL implementation and the
20// gpu implementation.
21#define SK_RASTER_RECORDER_IMPLEMENTATION 1
Robert Phillipse42edcc2017-12-13 11:50:22 -050022
Robert Phillips62000362018-02-01 09:10:04 -050023#if SK_SUPPORT_GPU
24#include "GrContext.h"
Robert Phillipse42edcc2017-12-13 11:50:22 -050025
Robert Phillips8def8bf2017-11-30 08:46:03 -050026/** \class SkSurfaceCharacterization
27 A surface characterization contains all the information Ganesh requires to makes its internal
28 rendering decisions. When passed into a SkDeferredDisplayListRecorder it will copy the
29 data and pass it on to the SkDeferredDisplayList if/when it is created. Note that both of
30 those objects (the Recorder and the DisplayList) will take a ref on the
Robert Phillips7ffbcf92017-12-04 12:52:46 -050031 GrContextThreadSafeProxy and SkColorSpace objects.
Robert Phillips8def8bf2017-11-30 08:46:03 -050032*/
Robert Phillipsad8a43f2017-08-30 12:06:35 -040033class SkSurfaceCharacterization {
34public:
Robert Phillipse8fabb22018-02-04 14:33:21 -050035 enum class Textureable : bool { kNo = false, kYes = true };
36 enum class MipMapped : bool { kNo = false, kYes = true };
37
Robert Phillipsad8a43f2017-08-30 12:06:35 -040038 SkSurfaceCharacterization()
Robert Phillipsfc711a22018-02-13 17:03:00 -050039 : fCacheMaxResourceBytes(0)
Robert Phillips8d1e67e2017-12-04 13:48:14 -050040 , fOrigin(kBottomLeft_GrSurfaceOrigin)
Robert Phillipsad8a43f2017-08-30 12:06:35 -040041 , fWidth(0)
42 , fHeight(0)
Robert Phillips61e51012017-11-30 11:22:14 -050043 , fConfig(kUnknown_GrPixelConfig)
Robert Phillips7ffbcf92017-12-04 12:52:46 -050044 , fFSAAType(GrFSAAType::kNone)
45 , fStencilCnt(0)
Robert Phillipse8fabb22018-02-04 14:33:21 -050046 , fIsTextureable(Textureable::kYes)
47 , fIsMipMapped(MipMapped::kYes)
Robert Phillips61e51012017-11-30 11:22:14 -050048 , fSurfaceProps(0, kUnknown_SkPixelGeometry) {
Robert Phillipsad8a43f2017-08-30 12:06:35 -040049 }
50
Robert Phillips8def8bf2017-11-30 08:46:03 -050051 SkSurfaceCharacterization(SkSurfaceCharacterization&&) = default;
52 SkSurfaceCharacterization& operator=(SkSurfaceCharacterization&&) = default;
53
54 SkSurfaceCharacterization(const SkSurfaceCharacterization&) = default;
55 SkSurfaceCharacterization& operator=(const SkSurfaceCharacterization& other) = default;
Robert Phillipsad8a43f2017-08-30 12:06:35 -040056
Robert Phillips61e51012017-11-30 11:22:14 -050057 GrContextThreadSafeProxy* contextInfo() const { return fContextInfo.get(); }
Robert Phillipsfde6fa02018-03-02 08:53:14 -050058 sk_sp<GrContextThreadSafeProxy> refContextInfo() const { return fContextInfo; }
Robert Phillips8d1e67e2017-12-04 13:48:14 -050059 size_t cacheMaxResourceBytes() const { return fCacheMaxResourceBytes; }
60
Robert Phillipsfc711a22018-02-13 17:03:00 -050061 bool isValid() const { return kUnknown_GrPixelConfig != fConfig; }
62
Robert Phillipsad8a43f2017-08-30 12:06:35 -040063 GrSurfaceOrigin origin() const { return fOrigin; }
64 int width() const { return fWidth; }
65 int height() const { return fHeight; }
66 GrPixelConfig config() const { return fConfig; }
Robert Phillips7ffbcf92017-12-04 12:52:46 -050067 GrFSAAType fsaaType() const { return fFSAAType; }
68 int stencilCount() const { return fStencilCnt; }
Robert Phillipse8fabb22018-02-04 14:33:21 -050069 bool isTextureable() const { return Textureable::kYes == fIsTextureable; }
70 bool isMipMapped() const { return MipMapped::kYes == fIsMipMapped; }
Robert Phillips61e51012017-11-30 11:22:14 -050071 SkColorSpace* colorSpace() const { return fColorSpace.get(); }
72 sk_sp<SkColorSpace> refColorSpace() const { return fColorSpace; }
73 const SkSurfaceProps& surfaceProps()const { return fSurfaceProps; }
Robert Phillipsad8a43f2017-08-30 12:06:35 -040074
75private:
Robert Phillips8def8bf2017-11-30 08:46:03 -050076 friend class SkSurface_Gpu; // for 'set'
Robert Phillipsfc711a22018-02-13 17:03:00 -050077 friend class GrContextThreadSafeProxy; // for private ctor
78
79 SkSurfaceCharacterization(sk_sp<GrContextThreadSafeProxy> contextInfo,
80 size_t cacheMaxResourceBytes,
81 GrSurfaceOrigin origin, int width, int height,
82 GrPixelConfig config, GrFSAAType FSAAType, int stencilCnt,
83 Textureable isTextureable, MipMapped isMipMapped,
84 sk_sp<SkColorSpace> colorSpace,
85 const SkSurfaceProps& surfaceProps)
86 : fContextInfo(std::move(contextInfo))
87 , fCacheMaxResourceBytes(cacheMaxResourceBytes)
88 , fOrigin(origin)
89 , fWidth(width)
90 , fHeight(height)
91 , fConfig(config)
92 , fFSAAType(FSAAType)
93 , fStencilCnt(stencilCnt)
94 , fIsTextureable(isTextureable)
95 , fIsMipMapped(isMipMapped)
96 , fColorSpace(std::move(colorSpace))
97 , fSurfaceProps(surfaceProps) {
98 }
Robert Phillips8def8bf2017-11-30 08:46:03 -050099
Robert Phillips61e51012017-11-30 11:22:14 -0500100 void set(sk_sp<GrContextThreadSafeProxy> contextInfo,
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500101 size_t cacheMaxResourceBytes,
Robert Phillips61e51012017-11-30 11:22:14 -0500102 GrSurfaceOrigin origin,
Robert Phillips8def8bf2017-11-30 08:46:03 -0500103 int width, int height,
104 GrPixelConfig config,
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500105 GrFSAAType fsaaType,
106 int stencilCnt,
Robert Phillipse8fabb22018-02-04 14:33:21 -0500107 Textureable isTextureable,
108 MipMapped isMipMapped,
Robert Phillips61e51012017-11-30 11:22:14 -0500109 sk_sp<SkColorSpace> colorSpace,
110 const SkSurfaceProps& surfaceProps) {
Robert Phillipse8fabb22018-02-04 14:33:21 -0500111 SkASSERT(MipMapped::kNo == isMipMapped || Textureable::kYes == isTextureable);
112
Robert Phillips61e51012017-11-30 11:22:14 -0500113 fContextInfo = contextInfo;
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500114 fCacheMaxResourceBytes = cacheMaxResourceBytes;
115
Robert Phillips8def8bf2017-11-30 08:46:03 -0500116 fOrigin = origin;
117 fWidth = width;
118 fHeight = height;
119 fConfig = config;
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500120 fFSAAType = fsaaType;
121 fStencilCnt = stencilCnt;
Robert Phillipse8fabb22018-02-04 14:33:21 -0500122 fIsTextureable = isTextureable;
123 fIsMipMapped = isMipMapped;
Robert Phillips61e51012017-11-30 11:22:14 -0500124 fColorSpace = std::move(colorSpace);
125 fSurfaceProps = surfaceProps;
Robert Phillips8def8bf2017-11-30 08:46:03 -0500126 }
127
Robert Phillips61e51012017-11-30 11:22:14 -0500128 sk_sp<GrContextThreadSafeProxy> fContextInfo;
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500129 size_t fCacheMaxResourceBytes;
130
Robert Phillips8def8bf2017-11-30 08:46:03 -0500131 GrSurfaceOrigin fOrigin;
132 int fWidth;
133 int fHeight;
134 GrPixelConfig fConfig;
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500135 GrFSAAType fFSAAType;
136 int fStencilCnt;
Robert Phillipse8fabb22018-02-04 14:33:21 -0500137 Textureable fIsTextureable;
138 MipMapped fIsMipMapped;
Robert Phillips61e51012017-11-30 11:22:14 -0500139 sk_sp<SkColorSpace> fColorSpace;
140 SkSurfaceProps fSurfaceProps;
Robert Phillipsad8a43f2017-08-30 12:06:35 -0400141};
142
Robert Phillips8def8bf2017-11-30 08:46:03 -0500143#else// !SK_SUPPORT_GPU
144
145class SkSurfaceCharacterization {
146public:
Robert Phillipse42edcc2017-12-13 11:50:22 -0500147 SkSurfaceCharacterization()
148 : fWidth(0)
149 , fHeight(0)
150 , fSurfaceProps(0, kUnknown_SkPixelGeometry) {
151 }
Robert Phillips8def8bf2017-11-30 08:46:03 -0500152
Robert Phillipsfc711a22018-02-13 17:03:00 -0500153 bool isValid() const { return false; }
154
Robert Phillips8def8bf2017-11-30 08:46:03 -0500155 int width() const { return fWidth; }
156 int height() const { return fHeight; }
Robert Phillipse42edcc2017-12-13 11:50:22 -0500157 SkColorSpace* colorSpace() const { return fColorSpace.get(); }
158 sk_sp<SkColorSpace> refColorSpace() const { return fColorSpace; }
159 const SkSurfaceProps& surfaceProps()const { return fSurfaceProps; }
Robert Phillips8def8bf2017-11-30 08:46:03 -0500160
161private:
162 int fWidth;
163 int fHeight;
Robert Phillipse42edcc2017-12-13 11:50:22 -0500164 sk_sp<SkColorSpace> fColorSpace;
165 SkSurfaceProps fSurfaceProps;
Robert Phillips8def8bf2017-11-30 08:46:03 -0500166};
167
168#endif
169
Robert Phillipsad8a43f2017-08-30 12:06:35 -0400170#endif