Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1486)

Unified Diff: samplecode/SampleApp.cpp

Issue 1834243002: Add 'P' to SampleApp to cycle through pixel geometries. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « samplecode/SampleApp.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: samplecode/SampleApp.cpp
diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp
index 780eabd1e38d2fa7ff162bbe87781612943daf73..5bf28aa38e539cfd3871a95c794c03059412fa84 100644
--- a/samplecode/SampleApp.cpp
+++ b/samplecode/SampleApp.cpp
@@ -471,6 +471,20 @@ static HintingState gHintingStates[] = {
{SkPaint::kFull_Hinting, "Full", "Hf " },
};
+struct PixelGeometryState {
+ SkPixelGeometry pixelGeometry;
+ const char* name;
+ const char* label;
+};
+static PixelGeometryState gPixelGeometryStates[] = {
+ {SkPixelGeometry::kUnknown_SkPixelGeometry, "Mixed", nullptr },
+ {SkPixelGeometry::kUnknown_SkPixelGeometry, "Flat", "{Flat} " },
+ {SkPixelGeometry::kRGB_H_SkPixelGeometry, "RGB H", "{RGB H} " },
+ {SkPixelGeometry::kBGR_H_SkPixelGeometry, "BGR H", "{BGR H} " },
+ {SkPixelGeometry::kRGB_V_SkPixelGeometry, "RGB_V", "{RGB V} " },
+ {SkPixelGeometry::kBGR_V_SkPixelGeometry, "BGR_V", "{BGR V} " },
+};
+
struct FilterQualityState {
SkFilterQuality fQuality;
const char* fName;
@@ -878,6 +892,7 @@ SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* dev
fAAState = SkOSMenu::kMixedState;
fSubpixelState = SkOSMenu::kMixedState;
fHintingState = 0;
+ fPixelGeometryIndex = 0;
fFilterQualityIndex = 0;
fFlipAxis = 0;
@@ -938,6 +953,16 @@ SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* dev
nullptr);
fAppMenu->assignKeyEquivalentToItem(itemID, 'h');
+ itemID = fAppMenu->appendList("Pixel Geometry", "Pixel Geometry", sinkID, fPixelGeometryIndex,
+ gPixelGeometryStates[0].name,
+ gPixelGeometryStates[1].name,
+ gPixelGeometryStates[2].name,
+ gPixelGeometryStates[3].name,
+ gPixelGeometryStates[4].name,
+ gPixelGeometryStates[5].name,
+ nullptr);
+ fAppMenu->assignKeyEquivalentToItem(itemID, 'P');
+
itemID =fAppMenu->appendList("Tiling", "Tiling", sinkID, fTilingMode,
gTilingInfo[kNo_Tiling].label,
gTilingInfo[kAbs_128x128_Tiling].label,
@@ -1614,6 +1639,10 @@ bool SampleWindow::onEvent(const SkEvent& evt) {
this->updateTitle();
return true;
}
+ if (SkOSMenu::FindListIndex(evt, "Pixel Geometry", &fPixelGeometryIndex)) {
+ this->setPixelGeometry(fPixelGeometryIndex);
+ return true;
+ }
if (SkOSMenu::FindListIndex(evt, "Tiling", &fTilingMode)) {
if (SampleView::IsSampleView(curr_view(this))) {
((SampleView*)curr_view(this))->onTileSizeChanged(this->tileSize());
@@ -1797,9 +1826,7 @@ void SampleWindow::setDeviceType(DeviceType type) {
return;
fDevManager->tearDownBackend(this);
-
fDeviceType = type;
-
fDevManager->setUpBackend(this, fMSAASampleCount);
this->updateTitle();
@@ -1810,7 +1837,6 @@ void SampleWindow::setDeviceColorType(SkColorType ct, SkColorProfileType pt) {
this->setColorType(ct, pt);
fDevManager->tearDownBackend(this);
-
fDevManager->setUpBackend(this, fMSAASampleCount);
this->updateTitle();
@@ -1848,6 +1874,23 @@ void SampleWindow::toggleDistanceFieldFonts() {
this->inval(nullptr);
}
+void SampleWindow::setPixelGeometry(int pixelGeometryIndex) {
+ // reset backend
+ fDevManager->tearDownBackend(this);
+ fDevManager->setUpBackend(this, fMSAASampleCount);
+
+ const SkSurfaceProps& oldProps = this->getSurfaceProps();
+ SkSurfaceProps newProps(oldProps.flags(), SkSurfaceProps::kLegacyFontHost_InitType);
+ if (pixelGeometryIndex > 0) {
+ newProps = SkSurfaceProps(oldProps.flags(),
+ gPixelGeometryStates[pixelGeometryIndex].pixelGeometry);
+ }
+ this->setSurfaceProps(newProps);
+
+ this->updateTitle();
+ this->inval(nullptr);
+}
+
#include "SkDumpCanvas.h"
bool SampleWindow::onHandleKey(SkKey key) {
@@ -2074,6 +2117,7 @@ void SampleWindow::updateTitle() {
title.prepend(fFlipAxis & kFlipAxis_X ? "X " : nullptr);
title.prepend(fFlipAxis & kFlipAxis_Y ? "Y " : nullptr);
title.prepend(gHintingStates[fHintingState].label);
+ title.prepend(gPixelGeometryStates[fPixelGeometryIndex].label);
if (fOffset.fX || fOffset.fY) {
title.prependf("(%.2f, %.2f) ", SkScalarToFloat(fOffset.fX), SkScalarToFloat(fOffset.fY));
« no previous file with comments | « samplecode/SampleApp.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698