| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#pragma once |
| 18 |
|
| 19 |
#include "TestScene.h" |
| 20 |
|
| 21 |
#include <SkBitmap.h> |
| 22 |
#include <string> |
| 23 |
|
| 24 |
namespace android { |
| 25 |
namespace uirenderer { |
| 26 |
namespace test { |
| 27 |
|
| 28 |
class BitmapAllocationTestUtils { |
| 29 |
public: |
| 30 |
static sk_sp<Bitmap> allocateHeapBitmap(int width, int height, SkColorType colorType, |
| 31 |
std::function<void(SkBitmap& bitmap)> setup) { |
| 32 |
sk_sp<Bitmap> bitmap = TestUtils::createBitmap(width, height, colorType); |
| 33 |
SkBitmap skBitmap; |
| 34 |
bitmap->getSkBitmap(&skBitmap); |
| 35 |
setup(skBitmap); |
| 36 |
return bitmap; |
| 37 |
} |
| 38 |
|
| 39 |
static sk_sp<Bitmap> allocateHardwareBitmap(int width, int height, SkColorType colorType, |
| 40 |
std::function<void(SkBitmap& bitmap)> setup) { |
| 41 |
SkBitmap skBitmap; |
| 42 |
SkImageInfo info = SkImageInfo::Make(width, height, colorType, kPremul_SkAlphaType); |
| 43 |
skBitmap.setInfo(info); |
| 44 |
sk_sp<Bitmap> heapBitmap(Bitmap::allocateHeapBitmap(&skBitmap)); |
| 45 |
setup(skBitmap); |
| 46 |
return Bitmap::allocateHardwareBitmap(skBitmap); |
| 47 |
} |
| 48 |
|
| 49 |
typedef sk_sp<Bitmap> (*BitmapAllocator)(int, int, SkColorType, |
| 50 |
std::function<void(SkBitmap& bitmap)> setup); |
| 51 |
|
| 52 |
template <class T, BitmapAllocator allocator> |
| 53 |
static test::TestScene* createBitmapAllocationScene(const TestScene::Options&) { |
| 54 |
return new T(allocator); |
| 55 |
} |
| 56 |
|
| 57 |
template <class BaseScene> |
| 58 |
static bool registerBitmapAllocationScene(std::string name, std::string description) { |
| 59 |
TestScene::registerScene({name + "GlTex", description + " (GlTex version).", |
| 60 |
createBitmapAllocationScene<BaseScene, &allocateHeapBitmap>}); |
| 61 |
|
| 62 |
TestScene::registerScene({name + "EglImage", description + " (EglImage version).", |
| 63 |
createBitmapAllocationScene<BaseScene, &allocateHardwareBitmap>}); |
| 64 |
return true; |
| 65 |
} |
| 66 |
}; |
| 67 |
|
| 68 |
} |
| 69 |
} |
| 70 |
} |