SampleApp: remove Picture_DeviceType
Remove Picture_DeviceType from SampleApp SampleWindow DeviceType
enumeration.
Use a bool variable to control whether the drawing happens via
MultiPictureDraw.
The MultiPictureDraw mode can be activated by 'M', and title
is updated to contain "<MPD>". Previously the MPD mode was
inaccessible.
This works towards removing backend specific code from
SampleApp and VisualBench with the aim to move the code
to the common SkView framework (SkWindow in particular).
The grand goal is to be able to use command buffer GPU
API and NVPR in these apps.
BUG=skia:4733
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1538343002
Review URL: https://codereview.chromium.org/1538343002
diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp
index f9865dc..d200e29 100644
--- a/samplecode/SampleApp.cpp
+++ b/samplecode/SampleApp.cpp
@@ -189,7 +189,6 @@
#if SK_SUPPORT_GPU
switch (win->getDeviceType()) {
case kRaster_DeviceType: // fallthrough
- case kPicture_DeviceType: // fallthrough
case kGPU_DeviceType:
// all these guys use the native backend
fBackend = kNativeGL_BackEndType;
@@ -222,7 +221,6 @@
SkAutoTUnref<const GrGLInterface> glInterface;
switch (win->getDeviceType()) {
case kRaster_DeviceType: // fallthrough
- case kPicture_DeviceType: // fallthrough
case kGPU_DeviceType:
// all these guys use the native interface
glInterface.reset(GrGLCreateNativeInterface());
@@ -678,17 +676,16 @@
static inline SampleWindow::DeviceType cycle_devicetype(SampleWindow::DeviceType ct) {
static const SampleWindow::DeviceType gCT[] = {
- SampleWindow::kPicture_DeviceType,
+ SampleWindow::kRaster_DeviceType
#if SK_SUPPORT_GPU
- SampleWindow::kGPU_DeviceType,
+ , SampleWindow::kGPU_DeviceType
#if SK_ANGLE
- SampleWindow::kANGLE_DeviceType,
+ , SampleWindow::kANGLE_DeviceType
#endif // SK_ANGLE
#if SK_COMMAND_BUFFER
- SampleWindow::kCommandBuffer_DeviceType,
+ , SampleWindow::kCommandBuffer_DeviceType
#endif // SK_COMMAND_BUFFER
#endif // SK_SUPPORT_GPU
- SampleWindow::kRaster_DeviceType,
};
static_assert(SK_ARRAY_COUNT(gCT) == SampleWindow::kDeviceTypeCnt, "array_size_mismatch");
return gCT[ct];
@@ -862,6 +859,7 @@
#endif
fUseClip = false;
+ fUseMPD = false;
fAnimating = false;
fRotate = false;
fPerspAnim = false;
@@ -895,15 +893,16 @@
fAppMenu->setTitle("Global Settings");
int itemID;
- itemID =fAppMenu->appendList("Device Type", "Device Type", sinkID, 0,
- "Raster", "Picture", "OpenGL",
+ itemID = fAppMenu->appendList("Device Type", "Device Type", sinkID, 0,
+ "Raster",
+ "OpenGL",
#if SK_ANGLE
- "ANGLE",
+ "ANGLE",
#endif
#if SK_COMMAND_BUFFER
- "Command Buffer",
+ "Command Buffer",
#endif
- nullptr);
+ nullptr);
fAppMenu->assignKeyEquivalentToItem(itemID, 'd');
itemID = fAppMenu->appendTriState("AA", "AA", sinkID, fAAState);
fAppMenu->assignKeyEquivalentToItem(itemID, 'b');
@@ -1331,7 +1330,9 @@
#endif
fPDFDocument.reset(SkDocument::CreatePDF(name.c_str()));
canvas = fPDFDocument->beginPage(this->width(), this->height());
- } else if (kPicture_DeviceType == fDeviceType) {
+ } else if (fSaveToSKP) {
+ canvas = fRecorder.beginRecording(9999, 9999, nullptr, 0);
+ } else if (fUseMPD) {
canvas = fRecorder.beginRecording(9999, 9999, nullptr, 0);
} else {
canvas = this->INHERITED::beforeChildren(canvas);
@@ -1380,17 +1381,21 @@
SkImageEncoder::EncodeFile(name.c_str(), bmp,
SkImageEncoder::kPNG_Type, 100);
}
+ this->inval(nullptr);
+ return;
}
- if (kPicture_DeviceType == fDeviceType) {
+ if (fSaveToSKP) {
SkAutoTUnref<const SkPicture> picture(fRecorder.endRecording());
+ SkFILEWStream stream("sample_app.skp");
+ picture->serialize(&stream);
+ fSaveToSKP = false;
+ this->inval(nullptr);
+ return;
+ }
- if (fSaveToSKP) {
- SkFILEWStream stream("sample_app.skp");
- picture->serialize(&stream);
- fSaveToSKP = false;
- }
-
+ if (fUseMPD) {
+ SkAutoTUnref<const SkPicture> picture(fRecorder.endRecording());
if (true) {
if (true) {
SkImageInfo info;
@@ -1791,6 +1796,11 @@
fSaveToSKP = true;
this->inval(nullptr);
return true;
+ case 'M':
+ fUseMPD = !fUseMPD;
+ this->inval(nullptr);
+ this->updateTitle();
+ return true;
#if SK_SUPPORT_GPU
case 'p':
{
@@ -2011,7 +2021,6 @@
static const char* gDeviceTypePrefix[] = {
"raster: ",
- "picture: ",
#if SK_SUPPORT_GPU
"opengl: ",
#if SK_ANGLE
@@ -2065,6 +2074,9 @@
if (this->getSurfaceProps().flags() & SkSurfaceProps::kUseDeviceIndependentFonts_Flag) {
title.prepend("<DIF> ");
}
+ if (fUseMPD) {
+ title.prepend("<MPD> ");
+ }
title.prepend(trystate_str(fLCDState, "LCD ", "lcd "));
title.prepend(trystate_str(fAAState, "AA ", "aa "));