| Index: samplecode/SampleApp.cpp
|
| diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp
|
| index a3a81d8516843ed18e09555b02db35153a5e0307..e05fe9be9b8486493828c2cacbc6bfee512dd517 100644
|
| --- a/samplecode/SampleApp.cpp
|
| +++ b/samplecode/SampleApp.cpp
|
| @@ -69,14 +69,6 @@ public:
|
| };
|
| #endif // SAMPLE_PDF_FILE_VIEWER
|
|
|
| -#if SK_COMMAND_BUFFER
|
| -#define DEFAULT_TO_COMMAND_BUFFER 1
|
| -#elif SK_ANGLE
|
| -//#define DEFAULT_TO_ANGLE 1
|
| -#else
|
| -#define DEFAULT_TO_GPU 0 // if 1 default rendering is on GPU
|
| -#endif
|
| -
|
| #define ANIMATING_EVENTTYPE "nextSample"
|
| #define ANIMATING_DELAY 250
|
|
|
| @@ -436,9 +428,9 @@ enum FlipAxisEnum {
|
| #include "SkDrawFilter.h"
|
|
|
| struct HintingState {
|
| - SkPaint::Hinting hinting;
|
| - const char* name;
|
| - const char* label;
|
| + SkPaint::Hinting fHinting;
|
| + const char* fMenuLabel;
|
| + const char* fTitleLabel;
|
| };
|
| static HintingState gHintingStates[] = {
|
| {SkPaint::kNo_Hinting, "Mixed", nullptr },
|
| @@ -450,8 +442,8 @@ static HintingState gHintingStates[] = {
|
|
|
| struct FilterQualityState {
|
| SkFilterQuality fQuality;
|
| - const char* fName;
|
| - const char* fLabel;
|
| + const char* fMenuLabel;
|
| + const char* fTitleLabel;
|
| };
|
| static FilterQualityState gFilterQualityStates[] = {
|
| { kNone_SkFilterQuality, "Mixed", nullptr },
|
| @@ -493,7 +485,7 @@ protected:
|
| paint->writable()->setSubpixelText(SkOSMenu::kOnState == fSubpixelState);
|
| }
|
| if (0 != fHintingState && fHintingState < (int)SK_ARRAY_COUNT(gHintingStates)) {
|
| - paint->writable()->setHinting(gHintingStates[fHintingState].hinting);
|
| + paint->writable()->setHinting(gHintingStates[fHintingState].fHinting);
|
| }
|
| return true;
|
| }
|
| @@ -592,7 +584,7 @@ struct TilingInfo {
|
| SkScalar w, h;
|
| };
|
|
|
| -static const struct TilingInfo gTilingInfo[] = {
|
| +static const struct TilingInfo gTilingInfos[] = {
|
| { "No tiling", SK_Scalar1 , SK_Scalar1 }, // kNo_Tiling
|
| { "128x128" , SkIntToScalar(128), SkIntToScalar(128) }, // kAbs_128x128_Tiling
|
| { "256x256" , SkIntToScalar(256), SkIntToScalar(256) }, // kAbs_256x256_Tiling
|
| @@ -600,12 +592,12 @@ static const struct TilingInfo gTilingInfo[] = {
|
| { "1/1x1/16" , SK_Scalar1 , SK_Scalar1 / 16 }, // kRel_1x16_Tiling
|
| { "1/16x1/1" , SK_Scalar1 / 16 , SK_Scalar1 }, // kRel_16x1_Tiling
|
| };
|
| -static_assert((SK_ARRAY_COUNT(gTilingInfo) == kLast_TilingMode_Enum),
|
| +static_assert((SK_ARRAY_COUNT(gTilingInfos) == kLast_TilingMode_Enum),
|
| "Incomplete_tiling_labels");
|
|
|
| SkSize SampleWindow::tileSize() const {
|
| SkASSERT((TilingMode)fTilingMode < kLast_TilingMode_Enum);
|
| - const struct TilingInfo* info = gTilingInfo + fTilingMode;
|
| + const struct TilingInfo* info = &gTilingInfos[fTilingMode];
|
| return SkSize::Make(info->w > SK_Scalar1 ? info->w : this->width() * info->w,
|
| info->h > SK_Scalar1 ? info->h : this->height() * info->h);
|
| }
|
| @@ -664,23 +656,6 @@ void SampleWindow::updatePointer(int x, int y) {
|
| }
|
| }
|
|
|
| -static inline SampleWindow::DeviceType cycle_devicetype(SampleWindow::DeviceType ct) {
|
| - static const SampleWindow::DeviceType gCT[] = {
|
| - SampleWindow::kRaster_DeviceType
|
| -#if SK_SUPPORT_GPU
|
| - , SampleWindow::kGPU_DeviceType
|
| -#if SK_ANGLE
|
| - , SampleWindow::kANGLE_DeviceType
|
| -#endif // SK_ANGLE
|
| -#if SK_COMMAND_BUFFER
|
| - , SampleWindow::kCommandBuffer_DeviceType
|
| -#endif // SK_COMMAND_BUFFER
|
| -#endif // SK_SUPPORT_GPU
|
| - };
|
| - static_assert(SK_ARRAY_COUNT(gCT) == SampleWindow::kDeviceTypeCnt, "array_size_mismatch");
|
| - return gCT[ct];
|
| -}
|
| -
|
| static SkString getSampleTitle(const SkViewFactory* sampleFactory) {
|
| SkView* view = (*sampleFactory)();
|
| SkString title;
|
| @@ -724,12 +699,47 @@ DEFINE_string(picture, "", "Path to single picture.");
|
| DEFINE_string(sequence, "", "Path to file containing the desired samples/gms to show.");
|
| DEFINE_bool(sort, false, "Sort samples by title.");
|
| DEFINE_bool(list, false, "List samples?");
|
| -DEFINE_bool(gpu, false, "Start up with gpu?");
|
| DEFINE_string(key, "", ""); // dummy to enable gm tests that have platform-specific names
|
| #ifdef SAMPLE_PDF_FILE_VIEWER
|
| DEFINE_string(pdfPath, "", "Path to direcotry of pdf files.");
|
| #endif
|
|
|
| +static const char startWithHelp[] = "Start with backend. Options: raster"
|
| +#if SK_SUPPORT_GPU
|
| + " gpu"
|
| +#if SK_ANGLE
|
| +#ifdef SK_BUILD_FOR_WIN
|
| + " angle"
|
| +#endif
|
| +#endif
|
| +#if SK_COMMAND_BUFFER
|
| + " commandbuffer"
|
| +#endif
|
| +#endif
|
| + "";
|
| +DEFINE_string(startWith, "raster", startWithHelp);
|
| +
|
| +
|
| +struct DeviceInfo {
|
| + const char* fName;
|
| + const char* fMenuLabel;
|
| + SampleWindow::DeviceType fType;
|
| +};
|
| +static const DeviceInfo gDeviceInfos[] = {
|
| + { "raster", "Raster", SampleWindow::kRaster_DeviceType }
|
| +#if SK_SUPPORT_GPU
|
| + , { "gpu", "GPU", SampleWindow::kGPU_DeviceType }
|
| +#if SK_ANGLE
|
| +#ifdef SK_BUILD_FOR_WIN
|
| + , { "angle", "ANGLE DirectX", SampleWindow::kANGLE_DeviceType }
|
| +#endif
|
| +#endif
|
| +#if SK_COMMAND_BUFFER
|
| + , { "commandbuffer", "Command Buffer", kCommandBuffer_DeviceType }
|
| +#endif
|
| +#endif
|
| +};
|
| +
|
| #include "SkTaskGroup.h"
|
|
|
| SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* devManager)
|
| @@ -737,6 +747,16 @@ SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* dev
|
| , fDevManager(nullptr) {
|
|
|
| SkCommandLineFlags::Parse(argc, argv);
|
| + for (fDeviceIndex = 0; fDeviceIndex < SK_ARRAY_COUNT(gDeviceInfos); ++fDeviceIndex) {
|
| + SkString name(gDeviceInfos[fDeviceIndex].fName);
|
| + if (name.equals(FLAGS_startWith[0])) {
|
| + break;
|
| + }
|
| + }
|
| + if (fDeviceIndex == SK_ARRAY_COUNT(gDeviceInfos)) {
|
| + SkDebugf("WARNING: can not start with unknown device %s\n", FLAGS_startWith[0]);
|
| + fDeviceIndex = 0;
|
| + }
|
|
|
| fCurrIndex = -1;
|
|
|
| @@ -805,8 +825,6 @@ SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* dev
|
| }
|
| }
|
|
|
| - fMSAASampleCount = FLAGS_msaa;
|
| -
|
| if (FLAGS_list) {
|
| listTitles();
|
| }
|
| @@ -825,23 +843,6 @@ SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* dev
|
| static SkTaskGroup::Enabler enabled(-1);
|
| gSampleWindow = this;
|
|
|
| - fDeviceType = kRaster_DeviceType;
|
| -#if SK_SUPPORT_GPU
|
| - if (FLAGS_gpu) {
|
| - fDeviceType = kGPU_DeviceType;
|
| - }
|
| -#endif
|
| -
|
| -#if DEFAULT_TO_GPU
|
| - fDeviceType = kGPU_DeviceType;
|
| -#endif
|
| -#if SK_ANGLE && DEFAULT_TO_ANGLE
|
| - fDeviceType = kANGLE_DeviceType;
|
| -#endif
|
| -#if SK_COMMAND_BUFFER && DEFAULT_TO_COMMAND_BUFFER
|
| - fDeviceType = kCommandBuffer_DeviceType;
|
| -#endif
|
| -
|
| fUseClip = false;
|
| fUsePicture = false;
|
| fAnimating = false;
|
| @@ -876,48 +877,37 @@ SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* dev
|
| fAppMenu->setTitle("Global Settings");
|
| int itemID;
|
|
|
| - itemID = fAppMenu->appendList("Device Type", "Device Type", sinkID, 0,
|
| - "Raster",
|
| - "OpenGL",
|
| -#if SK_ANGLE
|
| - "ANGLE",
|
| -#endif
|
| -#if SK_COMMAND_BUFFER
|
| - "Command Buffer",
|
| -#endif
|
| - nullptr);
|
| + SkTArray<const char*> deviceLabels;
|
| + for (auto& deviceInfo : gDeviceInfos) {
|
| + deviceLabels.push_back(deviceInfo.fMenuLabel);
|
| + }
|
| + itemID = fAppMenu->appendList("Device Type", "Device Type", sinkID, 0, deviceLabels);
|
| fAppMenu->assignKeyEquivalentToItem(itemID, 'd');
|
| itemID = fAppMenu->appendTriState("AA", "AA", sinkID, fAAState);
|
| fAppMenu->assignKeyEquivalentToItem(itemID, 'b');
|
| itemID = fAppMenu->appendTriState("LCD", "LCD", sinkID, fLCDState);
|
| fAppMenu->assignKeyEquivalentToItem(itemID, 'l');
|
| + SkTArray<const char*> filterQualityLabels;
|
| + for (auto& state : gFilterQualityStates) {
|
| + filterQualityLabels.push_back(state.fMenuLabel);
|
| + }
|
| itemID = fAppMenu->appendList("FilterQuality", "FilterQuality", sinkID, fFilterQualityIndex,
|
| - gFilterQualityStates[0].fName,
|
| - gFilterQualityStates[1].fName,
|
| - gFilterQualityStates[2].fName,
|
| - gFilterQualityStates[3].fName,
|
| - gFilterQualityStates[4].fName,
|
| - nullptr);
|
| + filterQualityLabels);
|
| fAppMenu->assignKeyEquivalentToItem(itemID, 'n');
|
| itemID = fAppMenu->appendTriState("Subpixel", "Subpixel", sinkID, fSubpixelState);
|
| fAppMenu->assignKeyEquivalentToItem(itemID, 's');
|
| - itemID = fAppMenu->appendList("Hinting", "Hinting", sinkID, fHintingState,
|
| - gHintingStates[0].name,
|
| - gHintingStates[1].name,
|
| - gHintingStates[2].name,
|
| - gHintingStates[3].name,
|
| - gHintingStates[4].name,
|
| - nullptr);
|
| + SkTArray<const char*> hintingStates;
|
| + for (auto& hintingState : gHintingStates) {
|
| + hintingStates.push_back(hintingState.fMenuLabel);
|
| + }
|
| + itemID = fAppMenu->appendList("Hinting", "Hinting", sinkID, fHintingState, hintingStates);
|
| fAppMenu->assignKeyEquivalentToItem(itemID, 'h');
|
|
|
| - itemID =fAppMenu->appendList("Tiling", "Tiling", sinkID, fTilingMode,
|
| - gTilingInfo[kNo_Tiling].label,
|
| - gTilingInfo[kAbs_128x128_Tiling].label,
|
| - gTilingInfo[kAbs_256x256_Tiling].label,
|
| - gTilingInfo[kRel_4x4_Tiling].label,
|
| - gTilingInfo[kRel_1x16_Tiling].label,
|
| - gTilingInfo[kRel_16x1_Tiling].label,
|
| - nullptr);
|
| + SkTArray<const char*> tilingInfos;
|
| + for (auto& tilingInfo : gTilingInfos) {
|
| + tilingInfos.push_back(tilingInfo.label);
|
| + }
|
| + itemID = fAppMenu->appendList("Tiling", "Tiling", sinkID, fTilingMode, tilingInfos);
|
| fAppMenu->assignKeyEquivalentToItem(itemID, 't');
|
|
|
| itemID = fAppMenu->appendSwitch("Slide Show", "Slide Show" , sinkID, false);
|
| @@ -951,7 +941,8 @@ SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* dev
|
| devManager->ref();
|
| fDevManager = devManager;
|
| }
|
| - fDevManager->setUpBackend(this, fMSAASampleCount);
|
| + fDeviceType = gDeviceInfos[fDeviceIndex].fType;
|
| + fDevManager->setUpBackend(this, FLAGS_msaa);
|
|
|
| // If another constructor set our dimensions, ensure that our
|
| // onSizeChange gets called.
|
| @@ -1554,7 +1545,7 @@ bool SampleWindow::onEvent(const SkEvent& evt) {
|
| }
|
| int selected = -1;
|
| if (SkOSMenu::FindListIndex(evt, "Device Type", &selected)) {
|
| - this->setDeviceType((DeviceType)selected);
|
| + this->setDevice(static_cast<size_t>(selected));
|
| return true;
|
| }
|
| if (SkOSMenu::FindSwitchState(evt, "Slide Show", nullptr)) {
|
| @@ -1758,15 +1749,14 @@ bool SampleWindow::onHandleChar(SkUnichar uni) {
|
| return this->INHERITED::onHandleChar(uni);
|
| }
|
|
|
| -void SampleWindow::setDeviceType(DeviceType type) {
|
| - if (type == fDeviceType)
|
| +void SampleWindow::setDevice(size_t deviceIndex) {
|
| + if (fDeviceIndex == deviceIndex)
|
| return;
|
|
|
| fDevManager->tearDownBackend(this);
|
| -
|
| - fDeviceType = type;
|
| -
|
| - fDevManager->setUpBackend(this, fMSAASampleCount);
|
| + fDeviceIndex = deviceIndex;
|
| + fDeviceType = gDeviceInfos[fDeviceIndex].fType;
|
| + fDevManager->setUpBackend(this, FLAGS_msaa);
|
|
|
| this->updateTitle();
|
| this->inval(nullptr);
|
| @@ -1779,7 +1769,7 @@ void SampleWindow::toggleSlideshow() {
|
| }
|
|
|
| void SampleWindow::toggleRendering() {
|
| - this->setDeviceType(cycle_devicetype(fDeviceType));
|
| + this->setDevice((fDeviceIndex + 1) % SK_ARRAY_COUNT(gDeviceInfos));
|
| this->updateTitle();
|
| this->inval(nullptr);
|
| }
|
| @@ -1793,7 +1783,7 @@ void SampleWindow::toggleFPS() {
|
| void SampleWindow::toggleDistanceFieldFonts() {
|
| // reset backend
|
| fDevManager->tearDownBackend(this);
|
| - fDevManager->setUpBackend(this, fMSAASampleCount);
|
| + fDevManager->setUpBackend(this, FLAGS_msaa);
|
|
|
| SkSurfaceProps props = this->getSurfaceProps();
|
| uint32_t flags = props.flags() ^ SkSurfaceProps::kUseDeviceIndependentFonts_Flag;
|
| @@ -1945,21 +1935,6 @@ void SampleWindow::loadView(SkView* view) {
|
| this->updateTitle();
|
| }
|
|
|
| -static const char* gDeviceTypePrefix[] = {
|
| - "raster: ",
|
| -#if SK_SUPPORT_GPU
|
| - "opengl: ",
|
| -#if SK_ANGLE
|
| - "angle: ",
|
| -#endif // SK_ANGLE
|
| -#if SK_COMMAND_BUFFER
|
| - "command buffer: ",
|
| -#endif // SK_COMMAND_BUFFER
|
| -#endif // SK_SUPPORT_GPU
|
| -};
|
| -static_assert(SK_ARRAY_COUNT(gDeviceTypePrefix) == SampleWindow::kDeviceTypeCnt,
|
| - "array_size_mismatch");
|
| -
|
| static const char* trystate_str(SkOSMenu::TriState state,
|
| const char trueStr[], const char falseStr[]) {
|
| if (SkOSMenu::kOnState == state) {
|
| @@ -1979,14 +1954,12 @@ void SampleWindow::updateTitle() {
|
| if (!this->getRawTitle(&title)) {
|
| title.set("<unknown>");
|
| }
|
| + title.prependf(" %s: ", gDeviceInfos[fDeviceIndex].fName);
|
|
|
| - title.prepend(gDeviceTypePrefix[fDeviceType]);
|
| -
|
| - title.prepend(" ");
|
| title.prepend(sk_tool_utils::colortype_name(this->getBitmap().colorType()));
|
|
|
| if (fTilingMode != kNo_Tiling) {
|
| - title.prependf("<T: %s> ", gTilingInfo[fTilingMode].label);
|
| + title.prependf("<T: %s> ", gTilingInfos[fTilingMode].label);
|
| }
|
| if (fAnimating) {
|
| title.prepend("<A> ");
|
| @@ -2006,11 +1979,11 @@ void SampleWindow::updateTitle() {
|
|
|
| title.prepend(trystate_str(fLCDState, "LCD ", "lcd "));
|
| title.prepend(trystate_str(fAAState, "AA ", "aa "));
|
| - title.prepend(gFilterQualityStates[fFilterQualityIndex].fLabel);
|
| + title.prepend(gFilterQualityStates[fFilterQualityIndex].fTitleLabel);
|
| title.prepend(trystate_str(fSubpixelState, "S ", "s "));
|
| title.prepend(fFlipAxis & kFlipAxis_X ? "X " : nullptr);
|
| title.prepend(fFlipAxis & kFlipAxis_Y ? "Y " : nullptr);
|
| - title.prepend(gHintingStates[fHintingState].label);
|
| + title.prepend(gHintingStates[fHintingState].fTitleLabel);
|
|
|
| if (fZoomLevel) {
|
| title.prependf("{%.2f} ", SkScalarToFloat(fZoomLevel));
|
|
|