Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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());
63 SkASSERT(SkIRect::MakeWH(kWidth, kHeight) == special->subset());
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());
72 SkASSERT(SkIRect::MakeWH(kWidth, kHeight) == special->subset());
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,
98 skgpu::Mipmapped::kNo,
99 GrProtected::kNo,
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());
113 SkASSERT(SkIRect::MakeWH(kWidth, kHeight) == special->subset());
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());
123 SkASSERT(SkIRect::MakeWH(kWidth, kHeight) == special->subset());
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());
132 SkASSERT(SkIRect::MakeWH(kWidth, kHeight) == special->subset());
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}
reporter
@ kBottomLeft_GrSurfaceOrigin
Definition GrTypes.h:149
#define SkAssertResult(cond)
Definition SkAssert.h:123
#define SkASSERT(cond)
Definition SkAssert.h:116
#define DEF_TEST(name, reporter)
Definition Test.h:312
#define DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS(name, reporter, context_info, ctsEnforcement)
Definition Test.h:434
static sk_sp< SkSpecialImage > MakeSpecial(SkDevice *dev, SkImage *img)
static sk_sp< SkSpecialImage > SnapSpecial(SkDevice *dev)
static sk_sp< SkSpecialImage > MakeSpecial(SkDevice *dev, const SkBitmap &bm)
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:316
virtual sk_sp< SkSpecialImage > makeSpecial(const SkBitmap &)
Definition SkDevice.cpp:314
uint32_t uniqueID() const
Definition SkImage.h:311
T * get() const
Definition SkRefCnt.h:303
VkDevice device
Definition main.cc:53
sk_sp< SkImage > image
Definition examples.cpp:29
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)
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