2013-06-18 15:37:27 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2013-07-24 17:48:03 +00:00
|
|
|
#ifndef SkExample_DEFINED
|
|
|
|
#define SkExample_DEFINED
|
2013-06-18 15:37:27 +00:00
|
|
|
|
|
|
|
#include "SkWindow.h"
|
2013-07-24 17:48:03 +00:00
|
|
|
#include "SkTRegistry.h"
|
2013-06-18 15:37:27 +00:00
|
|
|
|
|
|
|
class GrContext;
|
|
|
|
struct GrGLInterface;
|
|
|
|
class GrRenderTarget;
|
|
|
|
class SkCanvas;
|
2013-07-24 17:48:03 +00:00
|
|
|
class SkExampleWindow;
|
2013-06-18 15:37:27 +00:00
|
|
|
|
2013-07-24 17:48:03 +00:00
|
|
|
class SkExample : public SkNoncopyable {
|
|
|
|
public:
|
|
|
|
SkExample(SkExampleWindow* window) : fWindow(window) {}
|
|
|
|
|
2013-12-17 23:37:38 +00:00
|
|
|
virtual ~SkExample() {}
|
|
|
|
|
2013-07-24 17:48:03 +00:00
|
|
|
// Your class should override this method to do its thing.
|
|
|
|
virtual void draw(SkCanvas* canvas) = 0;
|
|
|
|
|
|
|
|
SkString getName() { return fName; };
|
|
|
|
// Use this public registry to tell the world about your sample.
|
2013-09-04 17:20:18 +00:00
|
|
|
typedef SkTRegistry<SkExample*(*)(SkExampleWindow*)> Registry;
|
2013-07-24 17:48:03 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
SkExampleWindow* fWindow;
|
|
|
|
SkString fName;
|
|
|
|
};
|
|
|
|
|
|
|
|
class SkExampleWindow : public SkOSWindow {
|
2013-06-18 15:37:27 +00:00
|
|
|
public:
|
|
|
|
enum DeviceType {
|
|
|
|
kRaster_DeviceType,
|
|
|
|
kGPU_DeviceType,
|
|
|
|
};
|
2013-07-24 17:48:03 +00:00
|
|
|
SkExampleWindow(void* hwnd);
|
2013-06-18 15:37:27 +00:00
|
|
|
|
|
|
|
// Changes the device type of the object.
|
|
|
|
bool setupBackend(DeviceType type);
|
|
|
|
void tearDownBackend();
|
|
|
|
|
|
|
|
DeviceType getDeviceType() const { return fType; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void draw(SkCanvas* canvas) SK_OVERRIDE;
|
|
|
|
|
|
|
|
virtual void onSizeChange() SK_OVERRIDE;
|
|
|
|
|
|
|
|
#ifdef SK_BUILD_FOR_WIN
|
|
|
|
virtual void onHandleInval(const SkIRect&) SK_OVERRIDE;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
SkCanvas* createCanvas() SK_OVERRIDE;
|
|
|
|
|
|
|
|
private:
|
2013-07-24 17:48:03 +00:00
|
|
|
bool findNextMatch(); // Set example to the first one that matches FLAGS_match.
|
2013-06-18 15:37:27 +00:00
|
|
|
void setupRenderTarget();
|
2013-07-24 17:48:03 +00:00
|
|
|
bool onHandleChar(SkUnichar unichar) SK_OVERRIDE;
|
2013-06-18 15:37:27 +00:00
|
|
|
|
|
|
|
DeviceType fType;
|
|
|
|
|
2013-07-24 17:48:03 +00:00
|
|
|
SkExample* fCurrExample;
|
|
|
|
const SkExample::Registry* fRegistry;
|
2013-06-18 15:37:27 +00:00
|
|
|
GrContext* fContext;
|
|
|
|
GrRenderTarget* fRenderTarget;
|
|
|
|
AttachmentInfo fAttachmentInfo;
|
|
|
|
const GrGLInterface* fInterface;
|
2013-07-24 17:48:03 +00:00
|
|
|
|
2013-06-18 15:37:27 +00:00
|
|
|
typedef SkOSWindow INHERITED;
|
|
|
|
};
|
2013-07-24 17:48:03 +00:00
|
|
|
|
2013-06-18 15:37:27 +00:00
|
|
|
#endif
|