Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Member Functions | List of all members
skiagm::WackyYUVFormatsGM Class Reference
Inheritance diagram for skiagm::WackyYUVFormatsGM:
skiagm::GM

Public Types

using Type = sk_gpu_test::LazyYUVImage::Type
 
- Public Types inherited from skiagm::GM
enum  Mode { kGM_Mode , kSample_Mode , kBench_Mode }
 
using DrawResult = skiagm::DrawResult
 
using GraphiteTestContext = skiatest::graphite::GraphiteTestContext
 

Public Member Functions

 WackyYUVFormatsGM (bool useTargetColorSpace, bool useSubset, bool useCubicSampling, Type type)
 
- Public Member Functions inherited from skiagm::GM
 GM (SkColor backgroundColor=SK_ColorWHITE)
 
virtual ~GM ()
 
void setMode (Mode mode)
 
Mode getMode () const
 
DrawResult gpuSetup (SkCanvas *, SkString *errorMsg, GraphiteTestContext *=nullptr)
 
void gpuTeardown ()
 
void onceBeforeDraw ()
 
DrawResult draw (SkCanvas *canvas)
 
DrawResult draw (SkCanvas *, SkString *errorMsg)
 
void drawBackground (SkCanvas *)
 
DrawResult drawContent (SkCanvas *canvas)
 
DrawResult drawContent (SkCanvas *, SkString *errorMsg)
 
virtual bool runAsBench () const
 
SkScalar width ()
 
SkScalar height ()
 
SkColor getBGColor () const
 
void setBGColor (SkColor)
 
void drawSizeBounds (SkCanvas *, SkColor)
 
bool animate (double)
 
virtual bool onChar (SkUnichar)
 
bool getControls (SkMetaData *controls)
 
void setControls (const SkMetaData &controls)
 
virtual void modifyGrContextOptions (GrContextOptions *)
 
virtual void modifyGraphiteContextOptions (skgpu::graphite::ContextOptions *) const
 
virtual bool isBazelOnly () const
 
virtual std::map< std::string, std::string > getGoldKeys () const
 

Protected Member Functions

SkString getName () const override
 
SkISize getISize () override
 
void createBitmaps ()
 
bool createImages (GrDirectContext *dContext, Recorder *recorder)
 
DrawResult onGpuSetup (SkCanvas *canvas, SkString *errorMsg, GraphiteTestContext *) override
 
void onGpuTeardown () override
 
void onDraw (SkCanvas *canvas) override
 
- Protected Member Functions inherited from skiagm::GM
virtual void onOnceBeforeDraw ()
 
virtual DrawResult onDraw (SkCanvas *, SkString *errorMsg)
 
virtual bool onAnimate (double)
 
virtual bool onGetControls (SkMetaData *)
 
virtual void onSetControls (const SkMetaData &)
 
GraphiteTestContextgraphiteTestContext () const
 

Additional Inherited Members

- Static Public Attributes inherited from skiagm::GM
static constexpr char kErrorMsg_DrawSkippedGpuOnly []
 

Detailed Description

Definition at line 790 of file wacky_yuv_formats.cpp.

Member Typedef Documentation

◆ Type

Definition at line 792 of file wacky_yuv_formats.cpp.

Constructor & Destructor Documentation

◆ WackyYUVFormatsGM()

skiagm::WackyYUVFormatsGM::WackyYUVFormatsGM ( bool  useTargetColorSpace,
bool  useSubset,
bool  useCubicSampling,
Type  type 
)
inline

Definition at line 794 of file wacky_yuv_formats.cpp.

795 : fUseTargetColorSpace(useTargetColorSpace)
796 , fUseSubset(useSubset)
797 , fUseCubicSampling(useCubicSampling)
798 , fImageType(type) {
799 this->setBGColor(0xFFCCCCCC);
800 }
void setBGColor(SkColor)
Definition gm.cpp:159

Member Function Documentation

◆ createBitmaps()

void skiagm::WackyYUVFormatsGM::createBitmaps ( )
inlineprotected

Definition at line 839 of file wacky_yuv_formats.cpp.

839 {
840 SkPoint origin = { kTileWidthHeight/2.0f, kTileWidthHeight/2.0f };
841 float outerRadius = kTileWidthHeight/2.0f - 20.0f;
842 float innerRadius = 20.0f;
843
844 {
845 // transparent
846 SkTDArray<SkRect> circles;
847 SkPath path = create_splat(origin, innerRadius, outerRadius, 1.0f, 5, &circles);
848 fOriginalBMs[0] = make_bitmap(kRGBA_8888_SkColorType, path, circles, false, fUseSubset);
849 }
850
851 {
852 // opaque
853 SkTDArray<SkRect> circles;
854 SkPath path = create_splat(origin, innerRadius, outerRadius, 1.0f, 7, &circles);
855 fOriginalBMs[1] = make_bitmap(kRGBA_8888_SkColorType, path, circles, true, fUseSubset);
856 }
857
858 if (fUseTargetColorSpace) {
859 fTargetColorSpace = SkColorSpace::MakeSRGB()->makeColorSpin();
860 }
861 }
static sk_sp< SkImage > make_bitmap()
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition SkColorType.h:24
static sk_sp< SkColorSpace > MakeSRGB()
sk_sp< SkColorSpace > makeColorSpin() const
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 const int kTileWidthHeight
static SkPath create_splat(const SkPoint &o, SkScalar innerRadius, SkScalar outerRadius, SkScalar ratio, int numLobes, SkTDArray< SkRect > *circles)

◆ createImages()

bool skiagm::WackyYUVFormatsGM::createImages ( GrDirectContext dContext,
Recorder recorder 
)
inlineprotected

Definition at line 863 of file wacky_yuv_formats.cpp.

863 {
864 int origin = 0;
865 for (bool opaque : { false, true }) {
866 for (size_t cs = 0; cs < std::size(color_space_array); ++cs) {
867 PlaneData planes;
868 extract_planes(fOriginalBMs[opaque],
870 static_cast<SkEncodedOrigin>(origin + 1), // valid origins are 1...8
871 &planes);
872
873 for (int f = kP016_YUVFormat; f <= kLast_YUVFormat; ++f) {
874 auto format = static_cast<YUVFormat>(f);
875 SkBitmap resultBMs[4];
876
877 int numPlanes = create_YUV(planes, format, resultBMs, opaque);
878 const YUVAPlanarConfig planarConfig(format,
879 opaque,
880 static_cast<SkEncodedOrigin>(origin + 1));
881 SkYUVAPixmaps pixmaps =
882 planarConfig.makeYUVAPixmaps(fOriginalBMs[opaque].dimensions(),
884 resultBMs,
885 numPlanes);
886 auto lazyYUV = sk_gpu_test::LazyYUVImage::Make(std::move(pixmaps));
887#if defined(SK_GRAPHITE)
888 if (recorder) {
889 fImages[opaque][cs][format] = lazyYUV->refImage(recorder, fImageType);
890 } else
891#endif
892 {
893 fImages[opaque][cs][format] = lazyYUV->refImage(dContext, fImageType);
894 }
895 }
896 origin = (origin + 1) % 8;
897 }
898 }
899
900 if (dContext) {
901 // Some backends (e.g., Vulkan) require all work be completed for backend textures
902 // before they are deleted. Since we don't know when we'll next have access to a
903 // direct context, flush all the work now.
904 dContext->flush();
905 dContext->submit(GrSyncCpu::kYes);
906 }
907
908 return true;
909 }
SkEncodedOrigin
bool submit(GrSyncCpu sync=GrSyncCpu::kNo)
GrSemaphoresSubmitted flush(const GrFlushInfo &info)
static std::unique_ptr< LazyYUVImage > Make(sk_sp< SkData > data, skgpu::Mipmapped=skgpu::Mipmapped::kNo, sk_sp< SkColorSpace >=nullptr)
Definition YUVUtils.cpp:200
uint32_t uint32_t * format
@ kLast_YUVFormat
@ kP016_YUVFormat
const SkYUVColorSpace color_space_array[]
static int create_YUV(const PlaneData &planes, YUVFormat yuvFormat, SkBitmap resultBMs[], bool opaque)
static void extract_planes(const SkBitmap &origBM, SkYUVColorSpace yuvColorSpace, SkEncodedOrigin origin, PlaneData *planes)

◆ getISize()

SkISize skiagm::WackyYUVFormatsGM::getISize ( )
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 831 of file wacky_yuv_formats.cpp.

831 {
832 int numCols = 2 * (std::size(color_space_array)); // opacity x #-color-spaces
833 int numRows = 1 + (kLast_YUVFormat + 1); // original + #-yuv-formats
834 int wh = SkScalarCeilToInt(kTileWidthHeight * (fUseSubset ? 1.5f : 1.f));
835 return SkISize::Make(kLabelWidth + numCols * (wh + kPad),
836 kLabelHeight + numRows * (wh + kPad));
837 }
#define SkScalarCeilToInt(x)
Definition SkScalar.h:36
constexpr int kPad
static constexpr int kLabelHeight
static constexpr SkISize Make(int32_t w, int32_t h)
Definition SkSize.h:20
static const int kLabelWidth

◆ getName()

SkString skiagm::WackyYUVFormatsGM::getName ( ) const
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 803 of file wacky_yuv_formats.cpp.

803 {
804 SkString name("wacky_yuv_formats");
805 if (fUseTargetColorSpace) {
806 name += "_cs";
807 }
808 if (fUseSubset) {
809 name += "_domain";
810 }
811 if (fUseCubicSampling) {
812 name += "_cubic";
813 }
814 switch (fImageType) {
815 case Type::kFromPixmaps:
816 name += "_frompixmaps";
817 break;
818 case Type::kFromTextures:
819 break;
820 case Type::kFromGenerator:
821 name += "_imggen";
822 break;
823 case Type::kFromImages:
824 name += "_fromimages";
825 break;
826 }
827
828 return name;
829 }
const char * name
Definition fuchsia.cc:50

◆ onDraw()

void skiagm::WackyYUVFormatsGM::onDraw ( SkCanvas canvas)
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 945 of file wacky_yuv_formats.cpp.

945 {
946 auto direct = GrAsDirectContext(canvas->recordingContext());
947#if defined(SK_GRAPHITE)
948 auto recorder = canvas->recorder();
949#endif
950
951 float cellWidth = kTileWidthHeight, cellHeight = kTileWidthHeight;
952 if (fUseSubset) {
953 cellWidth *= 1.5f;
954 cellHeight *= 1.5f;
955 }
956
957 SkRect srcRect = SkRect::Make(fOriginalBMs[0].dimensions());
958 SkRect dstRect = SkRect::MakeXYWH(kLabelWidth, 0.f, srcRect.width(), srcRect.height());
959
961 if (fUseSubset) {
963 // Draw a larger rectangle to ensure bilerp filtering would normally read outside the
964 // srcRect and hit the red pixels, if strict constraint weren't used.
965 dstRect.fRight = kLabelWidth + 1.5f * srcRect.width();
966 dstRect.fBottom = 1.5f * srcRect.height();
968 }
969
970 SkSamplingOptions sampling = fUseCubicSampling
973 for (size_t cs = kJPEG_SkYUVColorSpace; cs < std::size(color_space_array); ++cs) {
976 // The identity color space needs post processing to appear correctly
977 paint.setColorFilter(yuv_to_rgb_colorfilter());
978 }
979
980 for (int opaque : { 0, 1 }) {
981 dstRect.offsetTo(dstRect.fLeft, kLabelHeight);
982
983 draw_col_label(canvas, dstRect.fLeft + cellWidth / 2, cs, opaque);
984
985 canvas->drawImageRect(fOriginalBMs[opaque].asImage(), srcRect, dstRect,
986 SkSamplingOptions(), nullptr, constraint);
987 dstRect.offset(0.f, cellHeight + kPad);
988
990 draw_row_label(canvas, dstRect.fTop, format);
991 if (fUseTargetColorSpace && fImages[opaque][cs][format]) {
992 // Making a CS-specific version of a kIdentity_SkYUVColorSpace YUV image
993 // doesn't make a whole lot of sense. The colorSpace conversion will
994 // operate on the YUV components rather than the RGB components.
995 sk_sp<SkImage> csImage;
996#if defined(SK_GRAPHITE)
997 if (recorder) {
998 csImage = fImages[opaque][cs][format]->makeColorSpace(
999 recorder, fTargetColorSpace, {});
1000 } else
1001#endif
1002 {
1003 csImage = fImages[opaque][cs][format]->makeColorSpace(
1004 direct, fTargetColorSpace);
1005 }
1006 canvas->drawImageRect(csImage, srcRect, dstRect, sampling,
1007 &paint, constraint);
1008 } else {
1009 canvas->drawImageRect(fImages[opaque][cs][format], srcRect, dstRect,
1010 sampling, &paint, constraint);
1011 }
1012 dstRect.offset(0.f, cellHeight + kPad);
1013 }
1014
1015 dstRect.offset(cellWidth + kPad, 0.f);
1016 }
1017 }
1018 }
static GrDirectContext * GrAsDirectContext(GrContext_Base *base)
@ kJPEG_SkYUVColorSpace
Definition SkImageInfo.h:98
@ kIdentity_SkYUVColorSpace
maps Y->R, U->G, V->B
Definition SkImageInfo.h:93
SkFilterMode
virtual GrRecordingContext * recordingContext() const
virtual skgpu::graphite::Recorder * recorder() const
SrcRectConstraint
Definition SkCanvas.h:1541
@ kStrict_SrcRectConstraint
sample only inside bounds; slower
Definition SkCanvas.h:1542
@ kFast_SrcRectConstraint
sample outside bounds; faster
Definition SkCanvas.h:1543
void drawImageRect(const SkImage *, const SkRect &src, const SkRect &dst, const SkSamplingOptions &, const SkPaint *, SrcRectConstraint)
virtual sk_sp< SkImage > makeColorSpace(GrDirectContext *direct, sk_sp< SkColorSpace > target) const =0
const Paint & paint
SkSamplingOptions sampling
Definition SkRecords.h:337
static constexpr SkCubicResampler Mitchell()
static SkRect Make(const SkISize &size)
Definition SkRect.h:669
void offsetTo(float newX, float newY)
Definition SkRect.h:1043
SkScalar fBottom
larger y-axis bounds
Definition extension.cpp:17
void inset(float dx, float dy)
Definition SkRect.h:1060
SkScalar fLeft
smaller x-axis bounds
Definition extension.cpp:14
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition SkRect.h:659
SkScalar fRight
larger x-axis bounds
Definition extension.cpp:16
void offset(float dx, float dy)
Definition SkRect.h:1016
constexpr float height() const
Definition SkRect.h:769
constexpr float width() const
Definition SkRect.h:762
SkScalar fTop
smaller y-axis bounds
Definition extension.cpp:15
static const int kSubsetPadding
static void draw_col_label(SkCanvas *canvas, int x, int yuvColorSpace, bool opaque)
static void draw_row_label(SkCanvas *canvas, int y, int yuvFormat)
static sk_sp< SkColorFilter > yuv_to_rgb_colorfilter()

◆ onGpuSetup()

DrawResult skiagm::WackyYUVFormatsGM::onGpuSetup ( SkCanvas canvas,
SkString errorMsg,
GraphiteTestContext  
)
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 911 of file wacky_yuv_formats.cpp.

911 {
912 auto dContext = GrAsDirectContext(canvas->recordingContext());
913 auto recorder = canvas->recorder();
914 this->createBitmaps();
915
916 if (dContext && dContext->abandoned()) {
917 // This isn't a GpuGM so a null 'context' is okay but an abandoned context
918 // if forbidden.
919 return DrawResult::kSkip;
920 }
921
922 // Only the generator is expected to work with the CPU backend.
923 if (fImageType != Type::kFromGenerator && !dContext && !recorder) {
924 return DrawResult::kSkip;
925 }
926
927 if (!this->createImages(dContext, recorder)) {
928 *errorMsg = "Failed to create YUV images";
929 return DrawResult::kFail;
930 }
931
932 return DrawResult::kOk;
933 }
bool createImages(GrDirectContext *dContext, Recorder *recorder)

◆ onGpuTeardown()

void skiagm::WackyYUVFormatsGM::onGpuTeardown ( )
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 935 of file wacky_yuv_formats.cpp.

935 {
936 for (int i = 0; i < 2; ++i) {
937 for (size_t j = 0; j < std::size(color_space_array); ++j) {
938 for (int k = 0; k <= kLast_YUVFormat; ++k) {
939 fImages[i][j][k] = nullptr;
940 }
941 }
942 }
943 }

The documentation for this class was generated from the following file: