Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
crosscontextimage.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkData.h"
#include "include/core/SkImage.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPixmap.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkString.h"
#include "include/core/SkTypes.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/GrRecordingContext.h"
#include "include/gpu/ganesh/SkImageGanesh.h"
#include "tools/Resources.h"

Go to the source code of this file.

Functions

 DEF_SIMPLE_GPU_GM_CAN_FAIL (cross_context_image, rContext, canvas, errorMsg, 3 *256+40, 256+128+30)
 

Function Documentation

◆ DEF_SIMPLE_GPU_GM_CAN_FAIL()

DEF_SIMPLE_GPU_GM_CAN_FAIL ( cross_context_image  ,
rContext  ,
canvas  ,
errorMsg  ,
3 *256+  40,
256+128+  30 
)

Definition at line 24 of file crosscontextimage.cpp.

25 {
26 sk_sp<SkData> encodedData = GetResourceAsData("images/mandrill_256.png");
27 if (!encodedData) {
28 *errorMsg = "Could not load mandrill_256.png. Did you forget to set the resourcePath?";
30 }
31
32 auto dContext = rContext->asDirectContext();
33 if (!dContext) {
34 *errorMsg = "CrossContext image creation requires a direct context.";
36 }
37
40
41 SkBitmap bmp;
42 SkPixmap pixmap;
43 SkAssertResult(images[0]->asLegacyBitmap(&bmp) &&
44 bmp.peekPixels(&pixmap));
45
46 images[1] = SkImages::CrossContextTextureFromPixmap(dContext, pixmap, false);
47 images[2] = SkImages::CrossContextTextureFromPixmap(dContext, pixmap, true);
48
49 canvas->translate(10, 10);
50
51 for (size_t i = 0; i < std::size(images); ++i) {
52 canvas->save();
53
54 canvas->drawImage(images[i], 0, 0);
55 canvas->translate(0, 256 + 10);
56
57 auto subset = images[i]->makeSubset(dContext, SkIRect::MakeXYWH(64, 64, 128, 128));
58 SkASSERTF(subset, "subset was null");
59 canvas->drawImage(subset, 0, 0);
60 canvas->translate(128, 0);
61
62 canvas->drawImageRect(images[i], SkRect::MakeWH(128, 128),
65
66 canvas->restore();
67 canvas->translate(256 + 10, 0);
68 }
70}
sk_sp< SkData > GetResourceAsData(const char *resource)
Definition Resources.cpp:42
#define SkAssertResult(cond)
Definition SkAssert.h:123
#define SkASSERTF(cond, fmt,...)
Definition SkAssert.h:117
bool peekPixels(SkPixmap *pixmap) const
Definition SkBitmap.cpp:635
std::array< MockImage, 3 > images
SK_API sk_sp< SkImage > DeferredFromEncodedData(sk_sp< SkData > encoded, std::optional< SkAlphaType > alphaType=std::nullopt)
SK_API sk_sp< SkImage > CrossContextTextureFromPixmap(GrDirectContext *context, const SkPixmap &pixmap, bool buildMips, bool limitToMaxTextureSize=false)
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
Definition SkRect.h:104
static constexpr SkRect MakeWH(float w, float h)
Definition SkRect.h:609