Flutter Engine
The Flutter Engine
DeviceTest.cpp
Go to the documentation of this file.
1/*
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
11#include "include/core/SkRect.h"
17#include "include/gpu/GrTypes.h"
19#include "src/core/SkDevice.h"
25#include "tests/Test.h"
26
27struct GrContextOptions;
28
30public:
32 return dev->makeSpecial(bm);
33 }
34
36 return dev->makeSpecial(img);
37 }
38
40 return dev->snapSpecial();
41 }
42};
43
44// TODO: re-enable this when Raster methods are implemented
45#if 0
46DEF_TEST(SpecialImage_BitmapDevice, reporter) {
47 static const int kWidth = 100;
48 static const int kHeight = 90;
49
51
53
54 SkBitmap bm;
56
57 // Create a raster-backed special image from a raster-backed SkBitmap
59 SkASSERT(!special->isTextureBacked());
60 SkASSERT(kWidth == special->width());
61 SkASSERT(kHeight == special->height());
62 SkASSERT(bm.getGenerationID() == special->uniqueID());
64
65 // Create a raster-backed special image from a raster-backed SkImage
67 special = DeviceTestingAccess::MakeSpecial(bmDev.get(), image.get());
68 SkASSERT(!special->isTextureBacked());
69 SkASSERT(kWidth == special->width());
70 SkASSERT(kHeight == special->height());
71 SkASSERT(bm.getGenerationID() == special->uniqueID());
73
74 // Snap the device as a raster-backed special image
75 special = DeviceTestingAccess::SnapSpecial(bmDev.get());
76 SkASSERT(!special->isTextureBacked());
77 SkASSERT(2*kWidth == special->width());
78 SkASSERT(2*kHeight == special->height());
79 SkASSERT(SkIRect::MakeWH(2*kWidth, 2*kHeight) == special->subset());
80}
81#endif
82
85 ctxInfo,
87 auto dContext = ctxInfo.directContext();
88
89 static const int kWidth = 100;
90 static const int kHeight = 90;
91
93
94 auto device = dContext->priv().createDevice(skgpu::Budgeted::kNo,
95 ii,
97 1,
103
104 SkBitmap bm;
106
107 // Create a gpu-backed special image from a raster-backed SkBitmap
109 SkASSERT(special->isGaneshBacked());
110 SkASSERT(kWidth == special->width());
111 SkASSERT(kHeight == special->height());
112 SkASSERT(bm.getGenerationID() == special->uniqueID());
114
115 // Create a gpu-backed special image from a raster-backed SkImage
118 SkASSERT(special->isGaneshBacked());
119 SkASSERT(kWidth == special->width());
120 SkASSERT(kHeight == special->height());
121 // TODO: Hmmm, this is a bit unexpected
122 SkASSERT(image->uniqueID() != special->uniqueID());
124
125 // Create a gpu-backed special image from a gpu-backed SkImage
128 SkASSERT(special->isGaneshBacked());
129 SkASSERT(kWidth == special->width());
130 SkASSERT(kHeight == special->height());
131 SkASSERT(image->uniqueID() == special->uniqueID());
133
134 // Snap the device as a gpu-backed special image
136 SkASSERT(special->isGaneshBacked());
137 SkASSERT(2*kWidth == special->width());
138 SkASSERT(2*kHeight == special->height());
139 SkASSERT(SkIRect::MakeWH(2*kWidth, 2*kHeight) == special->subset());
140}
DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS(SpecialImage_GPUDevice, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
Definition: DeviceTest.cpp:83
reporter
Definition: FontMgrTest.cpp:39
SkAssertResult(font.textToGlyphs("Hello", 5, SkTextEncoding::kUTF8, glyphs, std::size(glyphs))==count)
@ kBottomLeft_GrSurfaceOrigin
Definition: GrTypes.h:149
#define SkASSERT(cond)
Definition: SkAssert.h:116
#define DEF_TEST(name, reporter)
Definition: Test.h:312
static sk_sp< SkSpecialImage > MakeSpecial(SkDevice *dev, SkImage *img)
Definition: DeviceTest.cpp:35
static sk_sp< SkSpecialImage > SnapSpecial(SkDevice *dev)
Definition: DeviceTest.cpp:39
static sk_sp< SkSpecialImage > MakeSpecial(SkDevice *dev, const SkBitmap &bm)
Definition: DeviceTest.cpp:31
static sk_sp< SkBitmapDevice > Create(const SkImageInfo &, const SkSurfaceProps &, SkRasterHandleAllocator *=nullptr)
sk_sp< SkImage > asImage() const
Definition: SkBitmap.cpp:645
uint32_t getGenerationID() const
Definition: SkBitmap.cpp:361
bool tryAllocN32Pixels(int width, int height, bool isOpaque=false)
Definition: SkBitmap.cpp:226
virtual sk_sp< SkSpecialImage > snapSpecial(const SkIRect &subset, bool forceCopy=false)
Definition: SkDevice.cpp:315
virtual sk_sp< SkSpecialImage > makeSpecial(const SkBitmap &)
Definition: SkDevice.cpp:313
uint32_t uniqueID() const
Definition: SkImage.h:311
int width() const
int height() const
virtual bool isGaneshBacked() const
uint32_t uniqueID() const
const SkIRect & subset() const
T * get() const
Definition: SkRefCnt.h:303
VkDevice device
Definition: main.cc:53
SK_API sk_sp< SkImage > TextureFromImage(GrDirectContext *, const SkImage *, skgpu::Mipmapped=skgpu::Mipmapped::kNo, skgpu::Budgeted=skgpu::Budgeted::kYes)
SK_API sk_sp< SkImage > RasterFromBitmap(const SkBitmap &bitmap)
sk_sp< const SkImage > image
Definition: SkRecords.h:269
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
Definition: SkRect.h:56
static SkImageInfo MakeN32Premul(int width, int height)
constexpr size_t kHeight
constexpr size_t kWidth