Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Namespaces | Functions
perspshaders.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkMatrix.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPath.h"
#include "include/core/SkPoint.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkScalar.h"
#include "include/core/SkShader.h"
#include "include/core/SkSize.h"
#include "include/core/SkString.h"
#include "include/core/SkSurface.h"
#include "include/core/SkTileMode.h"
#include "include/core/SkTypes.h"
#include "include/effects/SkGradientShader.h"
#include "tools/DecodeUtils.h"
#include "tools/ToolUtils.h"
#include "tools/Resources.h"

Go to the source code of this file.

Classes

class  skiagm::PerspShadersGM
 

Namespaces

namespace  skiagm
 

Functions

static sk_sp< SkImagemake_image (SkCanvas *origCanvas, int w, int h)
 
static SkPath make_path ()
 
 DEF_SIMPLE_GM (perspective_clip, canvas, 800, 800)
 

Function Documentation

◆ DEF_SIMPLE_GM()

DEF_SIMPLE_GM ( perspective_clip  ,
canvas  ,
800  ,
800   
)

Definition at line 207 of file perspshaders.cpp.

207 {
209 auto shader = ToolUtils::GetResourceAsImage("images/mandrill_128.png")
211
213 paint.setColor({0.75, 0.75, 0.75, 1});
214 canvas->drawPath(path, paint);
215
216 // This is a crazy perspective matrix, derived from halfplanes3, to draw a shape where
217 // part of it is "behind" the viewer, hence showing the need for "half-plane" clipping
218 // when in perspective.
219 SkMatrix mx;
220 const SkScalar array[] = {
221 -1.7866f, 1.3357f, 273.0295f,
222 -1.0820f, 1.3186f, 135.5196f,
223 -0.0047f, -0.0015f, 2.1485f,
224 };
225 mx.set9(array);
226
227 paint.setShader(shader);
228 canvas->concat(mx);
229 canvas->drawPath(path, paint);
230}
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const
Definition SkImage.cpp:179
static SkMatrix Scale(SkScalar sx, SkScalar sy)
Definition SkMatrix.h:75
SkMatrix & set9(const SkScalar buffer[9])
Definition SkMatrix.cpp:51
const Paint & paint
float SkScalar
Definition extension.cpp:12
sk_sp< SkImage > GetResourceAsImage(const char *resource)
Definition DecodeUtils.h:25
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition switches.h:57
static SkPath make_path()

◆ make_image()

static sk_sp< SkImage > make_image ( SkCanvas origCanvas,
int  w,
int  h 
)
static

Definition at line 31 of file perspshaders.cpp.

31 {
33 auto surface(ToolUtils::makeSurface(origCanvas, info));
34 SkCanvas* canvas = surface->getCanvas();
35
37 return surface->makeImageSnapshot();
38}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
constexpr SkColor SK_ColorRED
Definition SkColor.h:126
constexpr SkColor SK_ColorGREEN
Definition SkColor.h:131
VkSurfaceKHR surface
Definition main.cc:49
void draw_checkerboard(SkCanvas *canvas, SkColor c1, SkColor c2, int size)
sk_sp< SkSurface > makeSurface(SkCanvas *canvas, const SkImageInfo &info, const SkSurfaceProps *props)
SkScalar w
SkScalar h
static SkImageInfo MakeN32Premul(int width, int height)

◆ make_path()

static SkPath make_path ( )
static

Definition at line 188 of file perspshaders.cpp.

188 {
189 SkRandom rand;
190 auto rand_pt = [&rand]() {
191 auto x = rand.nextF();
192 auto y = rand.nextF();
193 return SkPoint{x * 400, y * 400};
194 };
195
196 SkPath path;
197 for (int i = 0; i < 4; ++i) {
198 SkPoint pts[6];
199 for (auto& p : pts) {
200 p = rand_pt();
201 }
202 path.moveTo(pts[0]).quadTo(pts[1], pts[2]).quadTo(pts[3], pts[4]).lineTo(pts[5]);
203 }
204 return path;
205}
static SkPoint rand_pt(SkRandom &rand)
float nextF()
Definition SkRandom.h:55
double y
double x