2011-06-15 16:49:08 +00:00
|
|
|
/*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Copyright 2011 Skia
|
2011-06-15 16:49:08 +00:00
|
|
|
*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
2011-06-15 16:49:08 +00:00
|
|
|
*/
|
|
|
|
|
2012-09-29 12:40:30 +00:00
|
|
|
#ifndef SampleApp_DEFINED
|
|
|
|
#define SampleApp_DEFINED
|
2011-07-28 14:26:00 +00:00
|
|
|
|
2017-09-01 18:24:40 +00:00
|
|
|
#include "SkExecutor.h"
|
2012-09-29 12:40:30 +00:00
|
|
|
#include "SkOSMenu.h"
|
2011-06-15 16:49:08 +00:00
|
|
|
#include "SkPath.h"
|
2014-04-13 19:09:42 +00:00
|
|
|
#include "SkPicture.h"
|
2014-04-18 18:04:41 +00:00
|
|
|
#include "SkPictureRecorder.h"
|
2011-06-15 16:49:08 +00:00
|
|
|
#include "SkScalar.h"
|
2016-09-13 15:09:45 +00:00
|
|
|
#include "SkStream.h"
|
2016-10-10 14:39:38 +00:00
|
|
|
#include "SkSurface.h"
|
2011-06-15 16:49:08 +00:00
|
|
|
#include "SkTDArray.h"
|
|
|
|
#include "SkTouchGesture.h"
|
|
|
|
#include "SkWindow.h"
|
2015-08-11 18:07:07 +00:00
|
|
|
#include "timer/Timer.h"
|
2011-06-15 16:49:08 +00:00
|
|
|
|
2016-09-13 15:09:45 +00:00
|
|
|
#include "SkPipe.h"
|
|
|
|
|
2017-02-22 19:00:42 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
#include "GrContextOptions.h"
|
|
|
|
#endif
|
|
|
|
|
2011-06-15 16:49:08 +00:00
|
|
|
class GrContext;
|
2011-07-06 17:56:47 +00:00
|
|
|
class GrRenderTarget;
|
2011-06-15 16:49:08 +00:00
|
|
|
|
|
|
|
class SkCanvas;
|
2012-09-29 12:40:30 +00:00
|
|
|
class SkData;
|
2014-10-08 18:10:51 +00:00
|
|
|
class SkDocument;
|
2012-09-29 12:40:30 +00:00
|
|
|
class SkEvent;
|
2011-06-15 16:49:08 +00:00
|
|
|
class SkTypeface;
|
2012-09-29 12:40:30 +00:00
|
|
|
class SkViewFactory;
|
2011-06-15 16:49:08 +00:00
|
|
|
|
|
|
|
class SampleWindow : public SkOSWindow {
|
2011-10-31 14:18:20 +00:00
|
|
|
SkTDArray<const SkViewFactory*> fSamples;
|
2011-06-15 16:49:08 +00:00
|
|
|
public:
|
2011-07-14 14:30:46 +00:00
|
|
|
enum DeviceType {
|
|
|
|
kRaster_DeviceType,
|
2012-08-02 14:03:32 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2011-10-27 20:44:19 +00:00
|
|
|
kGPU_DeviceType,
|
2012-04-02 19:24:21 +00:00
|
|
|
#if SK_ANGLE
|
|
|
|
kANGLE_DeviceType,
|
2012-08-02 14:03:32 +00:00
|
|
|
#endif // SK_ANGLE
|
|
|
|
#endif // SK_SUPPORT_GPU
|
|
|
|
kDeviceTypeCnt
|
2011-07-14 14:30:46 +00:00
|
|
|
};
|
2013-01-24 20:47:18 +00:00
|
|
|
|
|
|
|
static bool IsGpuDeviceType(DeviceType devType) {
|
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
switch (devType) {
|
|
|
|
case kGPU_DeviceType:
|
|
|
|
#if SK_ANGLE
|
|
|
|
case kANGLE_DeviceType:
|
|
|
|
#endif // SK_ANGLE
|
|
|
|
return true;
|
2013-01-24 22:09:06 +00:00
|
|
|
default:
|
|
|
|
return false;
|
2013-01-24 20:47:18 +00:00
|
|
|
}
|
|
|
|
#endif // SK_SUPPORT_GPU
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-07-14 14:30:46 +00:00
|
|
|
/**
|
|
|
|
* SampleApp ports can subclass this manager class if they want to:
|
|
|
|
* * filter the types of devices supported
|
2013-08-29 11:54:56 +00:00
|
|
|
* * customize plugging of SkBaseDevice objects into an SkCanvas
|
2011-07-14 14:30:46 +00:00
|
|
|
* * customize publishing the results of draw to the OS window
|
|
|
|
* * manage GrContext / GrRenderTarget lifetimes
|
|
|
|
*/
|
|
|
|
class DeviceManager : public SkRefCnt {
|
|
|
|
public:
|
2017-02-22 19:00:42 +00:00
|
|
|
struct BackendOptions {
|
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
GrContextOptions fGrContextOptions;
|
|
|
|
int fMSAASampleCount;
|
|
|
|
bool fDeepColor;
|
|
|
|
#endif
|
|
|
|
};
|
2016-03-29 16:03:52 +00:00
|
|
|
|
2017-02-22 19:00:42 +00:00
|
|
|
virtual void setUpBackend(SampleWindow* win, const BackendOptions&) = 0;
|
2011-07-14 14:30:46 +00:00
|
|
|
|
2012-04-02 19:24:21 +00:00
|
|
|
virtual void tearDownBackend(SampleWindow* win) = 0;
|
2011-07-14 14:30:46 +00:00
|
|
|
|
|
|
|
// called before drawing. should install correct device
|
|
|
|
// type on the canvas. Will skip drawing if returns false.
|
2016-07-28 22:17:34 +00:00
|
|
|
virtual sk_sp<SkSurface> makeSurface(DeviceType dType, SampleWindow* win) = 0;
|
2011-07-14 14:30:46 +00:00
|
|
|
|
|
|
|
// called after drawing, should get the results onto the
|
|
|
|
// screen.
|
2017-07-24 15:00:35 +00:00
|
|
|
virtual void publishCanvas(DeviceType dType,
|
|
|
|
SkCanvas* canvas,
|
|
|
|
SampleWindow* win) = 0;
|
2011-07-14 14:30:46 +00:00
|
|
|
|
|
|
|
// called when window changes size, guaranteed to be called
|
|
|
|
// at least once before first draw (after init)
|
|
|
|
virtual void windowSizeChanged(SampleWindow* win) = 0;
|
|
|
|
|
2015-08-27 14:41:13 +00:00
|
|
|
// return the GrContext backing gpu devices (nullptr if not built with GPU support)
|
2012-04-02 19:24:21 +00:00
|
|
|
virtual GrContext* getGrContext() = 0;
|
2012-04-06 20:13:38 +00:00
|
|
|
|
2015-08-27 14:41:13 +00:00
|
|
|
// return the GrRenderTarget backing gpu devices (nullptr if not built with GPU support)
|
2016-07-28 22:17:34 +00:00
|
|
|
virtual int numColorSamples() const = 0;
|
2016-05-05 19:24:31 +00:00
|
|
|
|
|
|
|
// return the color depth of the output device
|
|
|
|
virtual int getColorBits() = 0;
|
|
|
|
|
2012-08-16 14:58:06 +00:00
|
|
|
private:
|
|
|
|
typedef SkRefCnt INHERITED;
|
2011-07-14 14:30:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
SampleWindow(void* hwnd, int argc, char** argv, DeviceManager*);
|
2017-03-22 16:05:03 +00:00
|
|
|
~SampleWindow() override;
|
2011-06-15 16:49:08 +00:00
|
|
|
|
2016-07-28 22:17:34 +00:00
|
|
|
sk_sp<SkSurface> makeSurface() override {
|
|
|
|
sk_sp<SkSurface> surface;
|
2012-10-01 20:31:56 +00:00
|
|
|
if (fDevManager) {
|
2016-07-28 22:17:34 +00:00
|
|
|
surface = fDevManager->makeSurface(fDeviceType, this);
|
2012-10-01 20:31:56 +00:00
|
|
|
}
|
2016-07-28 22:17:34 +00:00
|
|
|
if (!surface) {
|
|
|
|
surface = this->INHERITED::makeSurface();
|
2012-10-01 20:31:56 +00:00
|
|
|
}
|
2014-09-18 18:29:01 +00:00
|
|
|
return surface;
|
2012-10-01 20:31:56 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void draw(SkCanvas*) override;
|
2011-06-15 16:49:08 +00:00
|
|
|
|
2011-08-02 13:39:12 +00:00
|
|
|
void setDeviceType(DeviceType type);
|
2016-06-16 20:03:24 +00:00
|
|
|
void setDeviceColorType(SkColorType, sk_sp<SkColorSpace>);
|
2011-06-15 16:49:08 +00:00
|
|
|
void toggleRendering();
|
|
|
|
void toggleSlideshow();
|
|
|
|
void toggleFPS();
|
2017-05-24 13:58:07 +00:00
|
|
|
void resetFPS();
|
2011-08-08 15:37:23 +00:00
|
|
|
void showOverview();
|
2014-10-06 19:29:56 +00:00
|
|
|
void toggleDistanceFieldFonts();
|
2016-03-31 15:30:38 +00:00
|
|
|
void setPixelGeometry(int pixelGeometryIndex);
|
2011-07-14 14:30:46 +00:00
|
|
|
|
2012-04-02 19:24:21 +00:00
|
|
|
GrContext* getGrContext() const { return fDevManager->getGrContext(); }
|
2011-07-14 14:30:46 +00:00
|
|
|
|
2011-06-15 16:49:08 +00:00
|
|
|
void setZoomCenter(float x, float y);
|
|
|
|
void changeZoomLevel(float delta);
|
2016-03-03 21:32:38 +00:00
|
|
|
void changeOffset(SkVector delta);
|
2011-06-15 16:49:08 +00:00
|
|
|
bool nextSample();
|
|
|
|
bool previousSample();
|
2011-06-24 16:04:50 +00:00
|
|
|
bool goToSample(int i);
|
|
|
|
SkString getSampleTitle(int i);
|
|
|
|
int sampleCount();
|
2011-06-17 12:46:17 +00:00
|
|
|
bool handleTouch(int ownerId, float x, float y,
|
|
|
|
SkView::Click::State state);
|
2011-06-21 14:44:57 +00:00
|
|
|
void saveToPdf();
|
2011-06-21 16:01:26 +00:00
|
|
|
void postInvalDelay();
|
2011-06-15 16:49:08 +00:00
|
|
|
|
2012-04-02 19:24:21 +00:00
|
|
|
DeviceType getDeviceType() const { return fDeviceType; }
|
2016-09-29 21:37:02 +00:00
|
|
|
int getColorConfigIndex() const { return fColorConfigIndex; }
|
2012-04-02 19:24:21 +00:00
|
|
|
|
2017-06-05 17:36:32 +00:00
|
|
|
int getTiles() const { return fTiles; }
|
2017-09-01 18:24:40 +00:00
|
|
|
void setTiles(int tiles) { fTiles = tiles; this->resetExecutor(); }
|
2017-04-03 14:52:48 +00:00
|
|
|
int getThreads() const { return fThreads; }
|
2017-09-01 18:24:40 +00:00
|
|
|
void setThreads(int threads) { fThreads = threads; this->resetExecutor(); }
|
|
|
|
|
2017-04-03 14:52:48 +00:00
|
|
|
|
2011-06-15 16:49:08 +00:00
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override;
|
|
|
|
bool onHandleKey(SkKey key) override;
|
|
|
|
bool onHandleChar(SkUnichar) override;
|
|
|
|
void onSizeChange() override;
|
2013-01-08 16:17:50 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkCanvas* beforeChildren(SkCanvas*) override;
|
|
|
|
void afterChildren(SkCanvas*) override;
|
|
|
|
void beforeChild(SkView* child, SkCanvas* canvas) override;
|
2013-01-08 16:17:50 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
bool onEvent(const SkEvent& evt) override;
|
|
|
|
bool onQuery(SkEvent* evt) override;
|
2013-01-08 16:17:50 +00:00
|
|
|
|
|
|
|
virtual bool onDispatchClick(int x, int y, Click::State, void* owner,
|
2015-03-26 01:17:31 +00:00
|
|
|
unsigned modi) override;
|
|
|
|
bool onClick(Click* click) override;
|
2013-01-08 16:17:50 +00:00
|
|
|
virtual Click* onFindClickHandler(SkScalar x, SkScalar y,
|
2015-03-26 01:17:31 +00:00
|
|
|
unsigned modi) override;
|
2011-06-15 16:49:08 +00:00
|
|
|
|
|
|
|
private:
|
2011-07-14 14:30:46 +00:00
|
|
|
class DefaultDeviceManager;
|
|
|
|
|
2011-06-15 16:49:08 +00:00
|
|
|
int fCurrIndex;
|
|
|
|
|
2016-09-13 15:09:45 +00:00
|
|
|
std::unique_ptr<SkDynamicMemoryWStream> fPipeStream;
|
|
|
|
SkPipeSerializer fPipeSerializer;
|
|
|
|
SkPipeDeserializer fPipeDeserializer;
|
|
|
|
|
2014-04-13 19:09:42 +00:00
|
|
|
SkPictureRecorder fRecorder;
|
2016-11-03 18:40:50 +00:00
|
|
|
std::unique_ptr<SkCanvas> fFlagsFilterCanvas;
|
2011-06-15 16:49:08 +00:00
|
|
|
SkPath fClipPath;
|
|
|
|
|
|
|
|
SkTouchGesture fGesture;
|
|
|
|
SkScalar fZoomLevel;
|
|
|
|
SkScalar fZoomScale;
|
2016-03-03 21:32:38 +00:00
|
|
|
SkVector fOffset;
|
2011-06-15 16:49:08 +00:00
|
|
|
|
2011-07-14 14:30:46 +00:00
|
|
|
DeviceType fDeviceType;
|
|
|
|
DeviceManager* fDevManager;
|
2011-06-15 16:49:08 +00:00
|
|
|
|
2011-06-21 14:44:57 +00:00
|
|
|
bool fSaveToPdf;
|
2015-08-05 01:46:38 +00:00
|
|
|
bool fSaveToSKP;
|
2016-05-03 19:10:04 +00:00
|
|
|
sk_sp<SkDocument> fPDFDocument;
|
2011-06-21 14:44:57 +00:00
|
|
|
|
2011-06-15 16:49:08 +00:00
|
|
|
bool fUseClip;
|
2016-01-08 16:23:19 +00:00
|
|
|
bool fUsePicture;
|
2011-06-15 16:49:08 +00:00
|
|
|
bool fAnimating;
|
|
|
|
bool fRotate;
|
2011-09-08 18:48:12 +00:00
|
|
|
bool fPerspAnim;
|
2011-06-15 16:49:08 +00:00
|
|
|
bool fRequestGrabImage;
|
|
|
|
bool fMeasureFPS;
|
2016-07-08 15:43:27 +00:00
|
|
|
bool fUseDeferredCanvas;
|
2015-08-11 18:07:07 +00:00
|
|
|
WallTimer fTimer;
|
|
|
|
double fMeasureFPS_Time;
|
2017-05-24 13:58:07 +00:00
|
|
|
double fCumulativeFPS_Time;
|
|
|
|
int fCumulativeFPS_Count;
|
2011-08-08 15:37:23 +00:00
|
|
|
bool fMagnify;
|
2013-12-06 20:14:55 +00:00
|
|
|
int fTilingMode;
|
2012-08-01 17:58:01 +00:00
|
|
|
|
2011-06-15 16:49:08 +00:00
|
|
|
// The following are for the 'fatbits' drawing
|
|
|
|
// Latest position of the mouse.
|
|
|
|
int fMouseX, fMouseY;
|
|
|
|
int fFatBitsScale;
|
|
|
|
// Used by the text showing position and color values.
|
2016-05-12 17:09:30 +00:00
|
|
|
sk_sp<SkTypeface> fTypeface;
|
2011-06-15 16:49:08 +00:00
|
|
|
bool fShowZoomer;
|
2012-08-01 17:58:01 +00:00
|
|
|
|
2011-08-08 15:37:23 +00:00
|
|
|
SkOSMenu::TriState fLCDState;
|
|
|
|
SkOSMenu::TriState fAAState;
|
2013-06-03 21:26:34 +00:00
|
|
|
SkOSMenu::TriState fSubpixelState;
|
|
|
|
int fHintingState;
|
2016-03-31 15:30:38 +00:00
|
|
|
int fPixelGeometryIndex;
|
2015-03-16 17:08:34 +00:00
|
|
|
int fFilterQualityIndex;
|
2011-06-15 16:49:08 +00:00
|
|
|
unsigned fFlipAxis;
|
|
|
|
|
2017-02-22 19:00:42 +00:00
|
|
|
DeviceManager::BackendOptions fBackendOptions;
|
|
|
|
|
2016-09-29 21:37:02 +00:00
|
|
|
int fColorConfigIndex;
|
2012-04-06 20:13:38 +00:00
|
|
|
|
2011-06-15 16:49:08 +00:00
|
|
|
SkScalar fZoomCenterX, fZoomCenterY;
|
|
|
|
|
2011-08-02 13:39:12 +00:00
|
|
|
//Stores global settings
|
2012-04-18 14:07:57 +00:00
|
|
|
SkOSMenu* fAppMenu; // We pass ownership to SkWindow, when we call addMenu
|
2011-08-02 13:39:12 +00:00
|
|
|
//Stores slide specific settings
|
2012-04-18 14:07:57 +00:00
|
|
|
SkOSMenu* fSlideMenu; // We pass ownership to SkWindow, when we call addMenu
|
|
|
|
|
2017-06-05 17:36:32 +00:00
|
|
|
int fTiles = 0;
|
2017-04-03 14:52:48 +00:00
|
|
|
int fThreads = 0;
|
2017-09-01 18:24:40 +00:00
|
|
|
std::unique_ptr<SkExecutor> fExecutor;
|
2017-04-03 14:52:48 +00:00
|
|
|
|
2017-09-25 18:45:25 +00:00
|
|
|
int fMeasureMS; // the number of milliseconds to measure the FPS before we close the SampleApp
|
|
|
|
|
2011-06-15 16:49:08 +00:00
|
|
|
void loadView(SkView*);
|
|
|
|
void updateTitle();
|
2014-10-08 18:10:51 +00:00
|
|
|
bool getRawTitle(SkString*);
|
2011-06-15 16:49:08 +00:00
|
|
|
|
|
|
|
bool zoomIn();
|
|
|
|
bool zoomOut();
|
|
|
|
void updatePointer(int x, int y);
|
2011-08-08 15:37:23 +00:00
|
|
|
void magnify(SkCanvas* canvas);
|
2011-06-15 16:49:08 +00:00
|
|
|
void showZoomer(SkCanvas* canvas);
|
2011-11-11 21:42:12 +00:00
|
|
|
void updateMatrix();
|
2011-06-15 16:49:08 +00:00
|
|
|
void postAnimatingEvent();
|
2011-12-27 22:33:50 +00:00
|
|
|
int findByTitle(const char*);
|
2012-05-03 18:22:28 +00:00
|
|
|
void listTitles();
|
2013-12-10 21:51:06 +00:00
|
|
|
SkSize tileSize() const;
|
2015-02-02 03:01:04 +00:00
|
|
|
bool sendAnimatePulse();
|
2011-06-15 16:49:08 +00:00
|
|
|
|
2017-09-01 18:24:40 +00:00
|
|
|
void resetExecutor() {
|
|
|
|
fExecutor = SkExecutor::MakeFIFOThreadPool(fThreads == 0 ? fTiles : fThreads);
|
|
|
|
}
|
|
|
|
|
2011-06-15 16:49:08 +00:00
|
|
|
typedef SkOSWindow INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|