Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
crosscontextimage.cpp
Go to the documentation of this file.
1/*
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#include "gm/gm.h"
11#include "include/core/SkData.h"
15#include "include/core/SkRect.h"
22#include "tools/Resources.h"
23
24DEF_SIMPLE_GPU_GM_CAN_FAIL(cross_context_image, rContext, canvas, errorMsg,
25 3 * 256 + 40, 256 + 128 + 30) {
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
DEF_SIMPLE_GPU_GM_CAN_FAIL(cross_context_image, rContext, canvas, errorMsg, 3 *256+40, 256+128+30)
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