Flutter Engine
The Flutter Engine
Classes | Namespaces | Functions | Variables
bc1_transparency.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkImage.h"
#include "include/core/SkTextureCompressionType.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/GrRecordingContext.h"
#include "include/gpu/ganesh/SkImageGanesh.h"
#include "src/core/SkCompressedDataUtils.h"
#include "src/gpu/ganesh/GrCaps.h"
#include "src/gpu/ganesh/GrImageContextPriv.h"
#include "src/gpu/ganesh/image/SkImage_GaneshBase.h"
#include "src/image/SkImage_Base.h"
#include "tools/gpu/ProxyUtils.h"

Go to the source code of this file.

Classes

struct  BC1Block
 
class  skiagm::BC1TransparencyGM
 

Namespaces

namespace  skiagm
 

Functions

static int num_4x4_blocks (int size)
 
static uint16_t to565 (SkColor col)
 
static void create_BC1_block (BC1Block *block, bool transparent)
 
static sk_sp< SkDatamake_compressed_data ()
 
static sk_sp< SkImagedata_to_img (GrDirectContext *direct, sk_sp< SkData > data, SkTextureCompressionType compression)
 
static void draw_image (SkCanvas *canvas, sk_sp< SkImage > image, int x, int y)
 

Variables

constexpr int kImgWidth = 16
 
constexpr int kImgHeight = 8
 
constexpr int kPad = 4
 

Function Documentation

◆ create_BC1_block()

static void create_BC1_block ( BC1Block block,
bool  transparent 
)
static

Definition at line 59 of file bc1_transparency.cpp.

59 {
60 unsigned int byte;
61
62 if (transparent) {
63 block->fColor0 = to565(SK_ColorBLACK);
64 block->fColor1 = to565(SK_ColorWHITE);
65 SkASSERT(block->fColor0 <= block->fColor1); // this signals a transparent block
66 // opaque black (col0), medium grey (col2), transparent black (col3), white (col1).
67 byte = (0x0 << 0) | (0x2 << 2) | (0x3 << 4) | (0x1 << 6);
68 } else {
69 block->fColor0 = to565(SK_ColorWHITE);
70 block->fColor1 = to565(SK_ColorBLACK);
71 SkASSERT(block->fColor0 > block->fColor1); // this signals an opaque block
72 // opaque black (col1), dark grey (col3), light grey (col2), white (col0)
73 byte = (0x1 << 0) | (0x3 << 2) | (0x2 << 4) | (0x0 << 6);
74 }
75
76 block->fIndices = (byte << 24) | (byte << 16) | (byte << 8) | byte;
77}
#define SkASSERT(cond)
Definition: SkAssert.h:116
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
static uint16_t to565(SkColor col)
uint16_t fColor0
uint32_t fIndices
uint16_t fColor1

◆ data_to_img()

static sk_sp< SkImage > data_to_img ( GrDirectContext direct,
sk_sp< SkData data,
SkTextureCompressionType  compression 
)
static

Definition at line 106 of file bc1_transparency.cpp.

107 {
108 if (direct) {
110 direct, std::move(data), kImgWidth, kImgHeight, compression, skgpu::Mipmapped::kNo);
111 } else {
113 std::move(data), kImgWidth, kImgHeight, compression);
114 }
115}
constexpr int kImgWidth
constexpr int kImgHeight
SK_API sk_sp< SkImage > TextureFromCompressedTextureData(GrDirectContext *direct, sk_sp< SkData > data, int width, int height, SkTextureCompressionType type, skgpu::Mipmapped mipmapped=skgpu::Mipmapped::kNo, GrProtected isProtected=GrProtected::kNo)
SK_API sk_sp< SkImage > RasterFromCompressedTextureData(sk_sp< SkData > data, int width, int height, SkTextureCompressionType type)
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63

◆ draw_image()

static void draw_image ( SkCanvas canvas,
sk_sp< SkImage image,
int  x,
int  y 
)
static

Definition at line 117 of file bc1_transparency.cpp.

117 {
118
119 bool isCompressed = false;
120 if (image && image->isTextureBacked()) {
121 const GrCaps* caps = as_IB(image)->context()->priv().caps();
123 canvas->recordingContext());
124 isCompressed = caps->isFormatCompressed(proxy->backendFormat());
125 }
126
127 canvas->drawImage(image, x, y);
128
129 if (!isCompressed) {
131 r.outset(1.0f, 1.0f);
132
133 SkPaint redStroke;
134 redStroke.setColor(SK_ColorRED);
136 redStroke.setStrokeWidth(2.0f);
137
138 canvas->drawRect(r, redStroke);
139 }
140}
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
static SkImage_Base * as_IB(SkImage *image)
Definition: SkImage_Base.h:201
const GrCaps * caps() const
Definition: GrCaps.h:57
bool isFormatCompressed(const GrBackendFormat &format) const
Definition: GrCaps.cpp:457
GrImageContextPriv priv()
const GrBackendFormat & backendFormat() const
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
virtual GrRecordingContext * recordingContext() const
Definition: SkCanvas.cpp:1637
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition: SkCanvas.h:1528
virtual GrImageContext * context() const
Definition: SkImage_Base.h:112
virtual bool isTextureBacked() const =0
void setStyle(Style style)
Definition: SkPaint.cpp:105
void setColor(SkColor color)
Definition: SkPaint.cpp:119
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
void setStrokeWidth(SkScalar width)
Definition: SkPaint.cpp:159
T * get() const
Definition: SkRefCnt.h:303
double y
double x
sk_sp< const SkImage > image
Definition: SkRecords.h:269
GrTextureProxy * GetTextureImageProxy(SkImage *image, GrRecordingContext *rContext)
Definition: ProxyUtils.cpp:32
void outset(float dx, float dy)
Definition: SkRect.h:1077
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659

◆ make_compressed_data()

static sk_sp< SkData > make_compressed_data ( )
static

Definition at line 81 of file bc1_transparency.cpp.

81 {
83
85 nullptr, false);
86
88 BC1Block* dstBlocks = reinterpret_cast<BC1Block*>(tmp->writable_data());
89
90 BC1Block transBlock, opaqueBlock;
91 create_BC1_block(&transBlock, true);
92 create_BC1_block(&opaqueBlock, false);
93
94 int numXBlocks = num_4x4_blocks(kImgWidth);
95 int numYBlocks = num_4x4_blocks(kImgHeight);
96
97 for (int y = 0; y < numYBlocks; ++y) {
98 for (int x = 0; x < numXBlocks; ++x) {
99 dstBlocks[y*numXBlocks + x] = (y < numYBlocks/2) ? transBlock : opaqueBlock;
100 }
101 }
102
103 return tmp;
104}
size_t SkCompressedDataSize(SkTextureCompressionType type, SkISize dimensions, TArray< size_t > *individualMipOffsets, bool mipmapped)
static int num_4x4_blocks(int size)
static void create_BC1_block(BC1Block *block, bool transparent)
static sk_sp< SkData > MakeUninitialized(size_t length)
Definition: SkData.cpp:116
void * writable_data()
Definition: SkData.h:52
Definition: SkSize.h:16

◆ num_4x4_blocks()

static int num_4x4_blocks ( int  size)
static

Definition at line 32 of file bc1_transparency.cpp.

32 {
33 return ((size + 3) & ~3) >> 2;
34}
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

◆ to565()

static uint16_t to565 ( SkColor  col)
static

Definition at line 36 of file bc1_transparency.cpp.

36 {
37 int r5 = SkMulDiv255Round(31, SkColorGetR(col));
38 int g6 = SkMulDiv255Round(63, SkColorGetG(col));
39 int b5 = SkMulDiv255Round(31, SkColorGetB(col));
40
41 return (r5 << 11) | (g6 << 5) | b5;
42}
#define SkColorGetR(color)
Definition: SkColor.h:65
#define SkColorGetG(color)
Definition: SkColor.h:69
#define SkColorGetB(color)
Definition: SkColor.h:73
static U8CPU SkMulDiv255Round(U16CPU a, U16CPU b)
Definition: SkMath.h:73

Variable Documentation

◆ kImgHeight

constexpr int kImgHeight = 8
constexpr

Definition at line 23 of file bc1_transparency.cpp.

◆ kImgWidth

constexpr int kImgWidth = 16
constexpr

Definition at line 22 of file bc1_transparency.cpp.

◆ kPad

constexpr int kPad = 4
constexpr

Definition at line 24 of file bc1_transparency.cpp.