Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
MallocPixelRefTest.cpp File Reference
#include "include/core/SkData.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkMallocPixelRef.h"
#include "include/core/SkPixelRef.h"
#include "include/core/SkRefCnt.h"
#include "src/base/SkAutoMalloc.h"
#include "src/core/SkPixelRefPriv.h"
#include "tests/Test.h"
#include <cstddef>
#include <cstdint>

Go to the source code of this file.

Functions

static void delete_uint8_proc (void *ptr, void *)
 
static void set_to_one_proc (void *, void *context)
 
 DEF_TEST (MallocPixelRef, reporter)
 

Function Documentation

◆ DEF_TEST()

DEF_TEST ( MallocPixelRef  ,
reporter   
)

Definition at line 28 of file MallocPixelRefTest.cpp.

28 {
31 {
33 SkMallocPixelRef::MakeAllocate(info, info.minRowBytes() - 1));
34 // rowbytes too small.
35 REPORTER_ASSERT(reporter, nullptr == pr.get());
36 }
37 {
38 size_t rowBytes = info.minRowBytes() - 1;
39 size_t size = info.computeByteSize(rowBytes);
42 SkMallocPixelRef::MakeWithData(info, rowBytes, data));
43 // rowbytes too small.
44 REPORTER_ASSERT(reporter, nullptr == pr.get());
45 }
46 {
47 size_t rowBytes = info.minRowBytes() + info.bytesPerPixel();
48 size_t size = info.computeByteSize(rowBytes) - 1;
51 SkMallocPixelRef::MakeWithData(info, rowBytes, data));
52 // data too small.
53 REPORTER_ASSERT(reporter, nullptr == pr.get());
54 }
55 size_t rowBytes = info.minRowBytes() + info.bytesPerPixel();
56 size_t size = info.computeByteSize(rowBytes) + 9;
57 {
58 SkAutoMalloc memory(size);
59 auto pr = sk_make_sp<SkPixelRef>(info.width(), info.height(), memory.get(), rowBytes);
60 REPORTER_ASSERT(reporter, pr.get() != nullptr);
61 REPORTER_ASSERT(reporter, memory.get() == pr->pixels());
62 }
63 {
66 REPORTER_ASSERT(reporter, pr.get() != nullptr);
67 REPORTER_ASSERT(reporter, pr->pixels());
68 }
69 {
70 void* addr = static_cast<void*>(new uint8_t[size]);
72 SkMakePixelRefWithProc(info.width(), info.height(), rowBytes, addr, delete_uint8_proc,
73 nullptr));
74 REPORTER_ASSERT(reporter, pr.get() != nullptr);
75 REPORTER_ASSERT(reporter, addr == pr->pixels());
76 }
77 {
78 int x = 0;
79 SkAutoMalloc memory(size);
81 SkMakePixelRefWithProc(info.width(), info.height(), rowBytes, memory.get(),
82 set_to_one_proc, static_cast<void*>(&x)));
83 REPORTER_ASSERT(reporter, pr.get() != nullptr);
84 REPORTER_ASSERT(reporter, memory.get() == pr->pixels());
86 pr.reset(nullptr);
87 // make sure that set_to_one_proc was called.
89 }
90 {
91 void* addr = static_cast<void*>(new uint8_t[size]);
92 REPORTER_ASSERT(reporter, addr != nullptr);
94 SkMakePixelRefWithProc(info.width(), info.height(), rowBytes, addr, delete_uint8_proc,
95 nullptr));
96 REPORTER_ASSERT(reporter, addr == pr->pixels());
97 }
98 {
100 SkData* dataPtr = data.get();
101 REPORTER_ASSERT(reporter, dataPtr->unique());
103 REPORTER_ASSERT(reporter, !(dataPtr->unique()));
104 data.reset(nullptr);
105 REPORTER_ASSERT(reporter, dataPtr->unique());
106 REPORTER_ASSERT(reporter, dataPtr->data() == pr->pixels());
107 }
108}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
reporter
static void delete_uint8_proc(void *ptr, void *)
static void set_to_one_proc(void *, void *context)
sk_sp< SkPixelRef > SkMakePixelRefWithProc(int width, int height, size_t rowBytes, void *addr, void(*releaseProc)(void *addr, void *ctx), void *ctx)
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
static sk_sp< SkData > MakeUninitialized(size_t length)
Definition SkData.cpp:116
const void * data() const
Definition SkData.h:37
bool unique() const
Definition SkRefCnt.h:175
double x
SK_API sk_sp< SkPixelRef > MakeWithData(const SkImageInfo &, size_t rowBytes, sk_sp< SkData > data)
SK_API sk_sp< SkPixelRef > MakeAllocate(const SkImageInfo &, size_t rowBytes)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switches.h:41
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition switches.h:259
static SkImageInfo MakeN32Premul(int width, int height)

◆ delete_uint8_proc()

static void delete_uint8_proc ( void *  ptr,
void *   
)
static

Definition at line 20 of file MallocPixelRefTest.cpp.

20 {
21 delete[] static_cast<uint8_t*>(ptr);
22}

◆ set_to_one_proc()

static void set_to_one_proc ( void *  ,
void *  context 
)
static

Definition at line 24 of file MallocPixelRefTest.cpp.

24 {
25 *(static_cast<int*>(context)) = 1;
26}