Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
bitmaptiled.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/SkRect.h"
#include "include/core/SkTiledImageUtils.h"
#include "include/core/SkTypes.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/GrRecordingContext.h"

Go to the source code of this file.

Functions

static void draw_tile_bitmap_with_fractional_offset (SkCanvas *canvas, bool vertical, bool manual)
 
 DEF_SIMPLE_GM_BG (bitmaptiled_fractional_horizontal, canvas, 1124, 365, SK_ColorBLACK)
 
 DEF_SIMPLE_GM_BG (bitmaptiled_fractional_horizontal_manual, canvas, 1124, 365, SK_ColorBLACK)
 
 DEF_SIMPLE_GM_BG (bitmaptiled_fractional_vertical, canvas, 365, 1124, SK_ColorBLACK)
 
 DEF_SIMPLE_GM_BG (bitmaptiled_fractional_vertical_manual, canvas, 365, 1124, SK_ColorBLACK)
 

Function Documentation

◆ DEF_SIMPLE_GM_BG() [1/4]

DEF_SIMPLE_GM_BG ( bitmaptiled_fractional_horizontal  ,
canvas  ,
1124  ,
365  ,
SK_ColorBLACK   
)

Definition at line 68 of file bitmaptiled.cpp.

68 {
69 draw_tile_bitmap_with_fractional_offset(canvas, /* vertical= */ false, /* manual= */ false);
70}
static void draw_tile_bitmap_with_fractional_offset(SkCanvas *canvas, bool vertical, bool manual)

◆ DEF_SIMPLE_GM_BG() [2/4]

DEF_SIMPLE_GM_BG ( bitmaptiled_fractional_horizontal_manual  ,
canvas  ,
1124  ,
365  ,
SK_ColorBLACK   
)

Definition at line 72 of file bitmaptiled.cpp.

72 {
73 draw_tile_bitmap_with_fractional_offset(canvas, /* vertical= */ false, /* manual= */ true);
74}

◆ DEF_SIMPLE_GM_BG() [3/4]

DEF_SIMPLE_GM_BG ( bitmaptiled_fractional_vertical  ,
canvas  ,
365  ,
1124  ,
SK_ColorBLACK   
)

Definition at line 76 of file bitmaptiled.cpp.

76 {
77 draw_tile_bitmap_with_fractional_offset(canvas, /* vertical= */ true, /* manual= */ false);
78}

◆ DEF_SIMPLE_GM_BG() [4/4]

DEF_SIMPLE_GM_BG ( bitmaptiled_fractional_vertical_manual  ,
canvas  ,
365  ,
1124  ,
SK_ColorBLACK   
)

Definition at line 80 of file bitmaptiled.cpp.

80 {
81 draw_tile_bitmap_with_fractional_offset(canvas, /* vertical= */ true, /* manual= */ true);
82}

◆ draw_tile_bitmap_with_fractional_offset()

static void draw_tile_bitmap_with_fractional_offset ( SkCanvas canvas,
bool  vertical,
bool  manual 
)
static

Definition at line 21 of file bitmaptiled.cpp.

21 {
22 // This should match kBmpSmallTileSize in SkGpuDevice.cpp. Note that our canvas size is tuned
23 // to this constant as well.
24 const int kTileSize = 1 << 10;
25
26 // We're going to draw a section of the bitmap that intersects 3 tiles (3x1 or 1x3).
27 // We need that to be < 50% of the total image, so our image is 7 tiles (7x1 or 1x7).
28 const int kBitmapLongEdge = 7 * kTileSize;
29 const int kBitmapShortEdge = 1 * kTileSize;
30
31 if (auto dContext = GrAsDirectContext(canvas->recordingContext())) {
32 // To trigger tiling, we also need the image to be more than 50% of the cache, so we
33 // ensure the cache is sized to make that true.
34 const int kBitmapArea = kBitmapLongEdge * kBitmapShortEdge;
35 const size_t kBitmapBytes = kBitmapArea * sizeof(SkPMColor);
36
37 const size_t newMaxResourceBytes = kBitmapBytes + (kBitmapBytes / 2);
38 dContext->setResourceCacheLimit(newMaxResourceBytes);
39 }
40
41 // Construct our bitmap as either very wide or very tall
42 SkBitmap bmp;
43 bmp.allocN32Pixels(vertical ? kBitmapShortEdge : kBitmapLongEdge,
44 vertical ? kBitmapLongEdge : kBitmapShortEdge, true);
46
47 // Draw ten strips with varying fractional offset to catch any rasterization issues with tiling
48 for (int i = 0; i < 10; ++i) {
49 float offset = i * 0.1f;
50
51 SkRect src = vertical ? SkRect::MakeXYWH(0, (kTileSize - 50) + offset, 32, 1124.0f)
52 : SkRect::MakeXYWH((kTileSize - 50) + offset, 0, 1124, 32);
53 SkRect dst = vertical ? SkRect::MakeXYWH(37.0f * i, 0.0f, 32.0f, 1124.0f)
54 : SkRect::MakeXYWH(0.0f, 37.0f * i, 1124.0f, 32.0f);
55
56 if (manual) {
58 /* paint= */ nullptr,
60 } else {
61 canvas->drawImageRect(bmp.asImage(), src, dst, SkSamplingOptions(),
62 /* paint= */ nullptr,
64 }
65 }
66}
static GrDirectContext * GrAsDirectContext(GrContext_Base *base)
uint32_t SkPMColor
Definition SkColor.h:205
constexpr SkColor SK_ColorWHITE
Definition SkColor.h:122
sk_sp< SkImage > asImage() const
Definition SkBitmap.cpp:645
void allocN32Pixels(int width, int height, bool isOpaque=false)
Definition SkBitmap.cpp:232
void eraseColor(SkColor4f) const
Definition SkBitmap.cpp:442
virtual GrRecordingContext * recordingContext() const
@ kStrict_SrcRectConstraint
sample only inside bounds; slower
Definition SkCanvas.h:1542
void drawImageRect(const SkImage *, const SkRect &src, const SkRect &dst, const SkSamplingOptions &, const SkPaint *, SrcRectConstraint)
SK_API void DrawImageRect(SkCanvas *canvas, const SkImage *image, const SkRect &src, const SkRect &dst, const SkSamplingOptions &sampling={}, const SkPaint *paint=nullptr, SkCanvas::SrcRectConstraint constraint=SkCanvas::kFast_SrcRectConstraint)
dst
Definition cp.py:12
Point offset
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition SkRect.h:659