Flutter Engine
The Flutter Engine
Macros | Typedefs | Functions
GrDirectContextPriv.cpp File Reference
#include "src/gpu/ganesh/GrDirectContextPriv.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkTypes.h"
#include "include/gpu/GrContextThreadSafeProxy.h"
#include "include/gpu/GrDirectContext.h"
#include "include/private/chromium/GrDeferredDisplayList.h"
#include "src/core/SkRuntimeEffectPriv.h"
#include "src/gpu/ganesh/GrContextThreadSafeProxyPriv.h"
#include "src/gpu/ganesh/GrDrawingManager.h"
#include "src/gpu/ganesh/GrGpu.h"
#include "src/gpu/ganesh/GrMemoryPool.h"
#include "src/gpu/ganesh/GrRecordingContextPriv.h"
#include "src/gpu/ganesh/GrTexture.h"
#include "src/gpu/ganesh/GrThreadSafePipelineBuilder.h"
#include "src/gpu/ganesh/GrTracing.h"
#include "src/gpu/ganesh/SkGr.h"
#include "src/gpu/ganesh/SurfaceContext.h"
#include "src/gpu/ganesh/SurfaceFillContext.h"
#include "src/gpu/ganesh/effects/GrSkSLFP.h"
#include "src/gpu/ganesh/effects/GrTextureEffect.h"
#include "src/gpu/ganesh/image/SkImage_Ganesh.h"
#include "src/gpu/ganesh/text/GrAtlasManager.h"
#include "src/image/SkImage_Base.h"
#include "src/text/gpu/TextBlobRedrawCoordinator.h"

Go to the source code of this file.

Macros

#define ASSERT_OWNED_PROXY(P)    SkASSERT(!(P) || !((P)->peekTexture()) || (P)->peekTexture()->getContext() == this->context())
 
#define ASSERT_SINGLE_OWNER   SKGPU_ASSERT_SINGLE_OWNER(this->context()->singleOwner())
 
#define RETURN_VALUE_IF_ABANDONED(value)   if (this->context()->abandoned()) { return (value); }
 

Typedefs

using MaskFormat = skgpu::MaskFormat
 

Functions

static std::unique_ptr< GrFragmentProcessormake_premul_effect (std::unique_ptr< GrFragmentProcessor > fp)
 
static std::unique_ptr< GrFragmentProcessormake_unpremul_effect (std::unique_ptr< GrFragmentProcessor > fp)
 
static bool test_for_preserving_PM_conversions (GrDirectContext *dContext)
 

Macro Definition Documentation

◆ ASSERT_OWNED_PROXY

#define ASSERT_OWNED_PROXY (   P)     SkASSERT(!(P) || !((P)->peekTexture()) || (P)->peekTexture()->getContext() == this->context())

Definition at line 38 of file GrDirectContextPriv.cpp.

◆ ASSERT_SINGLE_OWNER

#define ASSERT_SINGLE_OWNER   SKGPU_ASSERT_SINGLE_OWNER(this->context()->singleOwner())

Definition at line 40 of file GrDirectContextPriv.cpp.

◆ RETURN_VALUE_IF_ABANDONED

#define RETURN_VALUE_IF_ABANDONED (   value)    if (this->context()->abandoned()) { return (value); }

Definition at line 41 of file GrDirectContextPriv.cpp.

Typedef Documentation

◆ MaskFormat

Definition at line 36 of file GrDirectContextPriv.cpp.

Function Documentation

◆ make_premul_effect()

static std::unique_ptr< GrFragmentProcessor > make_premul_effect ( std::unique_ptr< GrFragmentProcessor fp)
static

Definition at line 196 of file GrDirectContextPriv.cpp.

197 {
198 if (!fp) {
199 return nullptr;
200 }
201
203 "half4 main(half4 halfColor) {"
204 "float4 color = float4(halfColor);"
205 "color = floor(color * 255 + 0.5) / 255;"
206 "color.rgb = floor(color.rgb * color.a * 255 + 0.5) / 255;"
207 "return color;"
208 "}"
209 );
210
211 fp = GrSkSLFP::Make(effect, "ToPremul", std::move(fp), GrSkSLFP::OptFlags::kNone);
212 return GrFragmentProcessor::HighPrecision(std::move(fp));
213}
SkRuntimeEffect * SkMakeRuntimeEffect(SkRuntimeEffect::Result(*make)(SkString, const SkRuntimeEffect::Options &), const char *sksl, SkRuntimeEffect::Options options=SkRuntimeEffect::Options{})
static std::unique_ptr< GrFragmentProcessor > HighPrecision(std::unique_ptr< GrFragmentProcessor >)
static std::unique_ptr< GrSkSLFP > Make(const SkRuntimeEffect *effect, const char *name, std::unique_ptr< GrFragmentProcessor > inputFP, OptFlags optFlags, Args &&... args)
Definition: GrSkSLFP.h:159
static Result MakeForColorFilter(SkString sksl, const Options &)
const uint32_t fp

◆ make_unpremul_effect()

static std::unique_ptr< GrFragmentProcessor > make_unpremul_effect ( std::unique_ptr< GrFragmentProcessor fp)
static

Definition at line 215 of file GrDirectContextPriv.cpp.

216 {
217 if (!fp) {
218 return nullptr;
219 }
220
222 "half4 main(half4 halfColor) {"
223 "float4 color = float4(halfColor);"
224 "color = floor(color * 255 + 0.5) / 255;"
225 "color.rgb = color.a <= 0 ? half3(0) : floor(color.rgb / color.a * 255 + 0.5) / 255;"
226 "return color;"
227 "}"
228 );
229
230 fp = GrSkSLFP::Make(effect, "ToUnpremul", std::move(fp), GrSkSLFP::OptFlags::kNone);
231 return GrFragmentProcessor::HighPrecision(std::move(fp));
232}

◆ test_for_preserving_PM_conversions()

static bool test_for_preserving_PM_conversions ( GrDirectContext dContext)
static

Definition at line 234 of file GrDirectContextPriv.cpp.

234 {
235 static constexpr int kSize = 256;
237 uint32_t* srcData = data.get();
238
239 // Fill with every possible premultiplied A, color channel value. There will be 256-y duplicate
240 // values in row y. We set r, g, and b to the same value since they are handled identically.
241 for (int y = 0; y < kSize; ++y) {
242 for (int x = 0; x < kSize; ++x) {
243 uint8_t* color = reinterpret_cast<uint8_t*>(&srcData[kSize*y + x]);
244 color[3] = y;
245 color[2] = std::min(x, y);
246 color[1] = std::min(x, y);
247 color[0] = std::min(x, y);
248 }
249 }
250
251 const SkImageInfo pmII =
254
255 auto readSFC =
256 dContext->priv().makeSFC(upmII, "ReadSfcForPMUPMConversion", SkBackingFit::kExact);
257 auto tempSFC =
258 dContext->priv().makeSFC(pmII, "TempSfcForPMUPMConversion", SkBackingFit::kExact);
259 if (!readSFC || !tempSFC) {
260 return false;
261 }
262
263 // This function is only ever called if we are in a GrDirectContext since we are calling read
264 // pixels here. Thus the pixel data will be uploaded immediately and we don't need to keep the
265 // pixel data alive in the proxy. Therefore the ReleaseProc is nullptr.
267 bitmap.installPixels(pmII, srcData, 4 * kSize);
268 bitmap.setImmutable();
269
270 auto dataView = std::get<0>(GrMakeUncachedBitmapProxyView(dContext, bitmap));
271 if (!dataView) {
272 return false;
273 }
274
275 uint32_t* firstRead = data.get() + kSize*kSize;
276 uint32_t* secondRead = data.get() + 2*kSize*kSize;
277 std::fill_n( firstRead, kSize*kSize, 0);
278 std::fill_n(secondRead, kSize*kSize, 0);
279
280 GrPixmap firstReadPM( upmII, firstRead, kSize*sizeof(uint32_t));
281 GrPixmap secondReadPM(upmII, secondRead, kSize*sizeof(uint32_t));
282
283 // We do a PM->UPM draw from dataTex to readTex and read the data. Then we do a UPM->PM draw
284 // from readTex to tempTex followed by a PM->UPM draw to readTex and finally read the data.
285 // We then verify that two reads produced the same values.
286
287 auto fp1 = make_unpremul_effect(GrTextureEffect::Make(std::move(dataView), bitmap.alphaType()));
288 readSFC->fillRectWithFP(SkIRect::MakeWH(kSize, kSize), std::move(fp1));
289 if (!readSFC->readPixels(dContext, firstReadPM, {0, 0})) {
290 return false;
291 }
292
293 auto fp2 = make_premul_effect(
294 GrTextureEffect::Make(readSFC->readSurfaceView(), readSFC->colorInfo().alphaType()));
295 tempSFC->fillRectWithFP(SkIRect::MakeWH(kSize, kSize), std::move(fp2));
296
297 auto fp3 = make_unpremul_effect(
298 GrTextureEffect::Make(tempSFC->readSurfaceView(), tempSFC->colorInfo().alphaType()));
299 readSFC->fillRectWithFP(SkIRect::MakeWH(kSize, kSize), std::move(fp3));
300
301 if (!readSFC->readPixels(dContext, secondReadPM, {0, 0})) {
302 return false;
303 }
304
305 for (int y = 0; y < kSize; ++y) {
306 for (int x = 0; x <= y; ++x) {
307 if (firstRead[kSize*y + x] != secondRead[kSize*y + x]) {
308 return false;
309 }
310 }
311 }
312
313 return true;
314}
static std::unique_ptr< GrFragmentProcessor > make_unpremul_effect(std::unique_ptr< GrFragmentProcessor > fp)
static std::unique_ptr< GrFragmentProcessor > make_premul_effect(std::unique_ptr< GrFragmentProcessor > fp)
kUnpremul_SkAlphaType
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition: SkColorType.h:24
std::tuple< GrSurfaceProxyView, GrColorType > GrMakeUncachedBitmapProxyView(GrRecordingContext *rContext, const SkBitmap &bitmap, skgpu::Mipmapped mipmapped, SkBackingFit fit, skgpu::Budgeted budgeted)
Definition: SkGr.cpp:253
GrDirectContextPriv priv()
std::unique_ptr< skgpu::ganesh::SurfaceFillContext > makeSFC(GrImageInfo, std::string_view label, SkBackingFit=SkBackingFit::kExact, int sampleCount=1, skgpu::Mipmapped=skgpu::Mipmapped::kNo, skgpu::Protected=skgpu::Protected::kNo, GrSurfaceOrigin=kTopLeft_GrSurfaceOrigin, skgpu::Budgeted=skgpu::Budgeted::kYes)
static std::unique_ptr< GrFragmentProcessor > Make(GrSurfaceProxyView, SkAlphaType, const SkMatrix &=SkMatrix::I(), GrSamplerState::Filter=GrSamplerState::Filter::kNearest, GrSamplerState::MipmapMode mipmapMode=GrSamplerState::MipmapMode::kNone)
DlColor color
static float min(float r, float g, float b)
Definition: hsl.cpp:48
constexpr int kSize
double y
double x
Definition: bitmap.py:1
const myers::Point & get< 0 >(const myers::Segment &s)
Definition: Myers.h:80
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
Definition: SkRect.h:56
SkImageInfo makeAlphaType(SkAlphaType newAlphaType) const
Definition: SkImageInfo.h:466
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63