skia2/example/HelloWorld.h
reed e8f3062a36 switch surface to sk_sp
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1817383002
CQ_EXTRA_TRYBOTS=client.skia.compile:Build-Ubuntu-GCC-x86_64-Release-CMake-Trybot,Build-Mac-Clang-x86_64-Release-CMake-Trybot

Review URL: https://codereview.chromium.org/1817383002
2016-03-23 18:59:25 -07:00

73 lines
1.8 KiB
C++

/*
* Copyright 2015 Google Inc.
*
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
*/
#ifndef HelloWorld_DEFINED
#define HelloWorld_DEFINED
#include "SkSurface.h"
#include "SkWindow.h"
class GrContext;
struct GrGLInterface;
class GrRenderTarget;
class SkCanvas;
class HelloWorldWindow : public SkOSWindow {
public:
enum DeviceType {
kRaster_DeviceType,
kGPU_DeviceType,
};
HelloWorldWindow(void* hwnd);
virtual ~HelloWorldWindow() override;
// Changes the device type of the object.
bool setUpBackend();
DeviceType getDeviceType() const { return fType; }
protected:
SkSurface* createSurface() override {
SkSurfaceProps props(INHERITED::getSurfaceProps());
if (kGPU_DeviceType == fType) {
return SkSurface::MakeRenderTargetDirect(fRenderTarget, &props).release();
}
static const SkImageInfo info = SkImageInfo::MakeN32Premul(
SkScalarRoundToInt(this->width()), SkScalarRoundToInt(this->height()));
return fSurface = SkSurface::MakeRaster(info, &props).release();
}
void draw(SkCanvas* canvas) override;
void drawContents(SkCanvas* canvas);
void onSizeChange() override;
private:
bool findNextMatch(); // Set example to the first one that matches FLAGS_match.
void setTitle();
void setUpRenderTarget();
bool onHandleChar(SkUnichar unichar) override;
void tearDownBackend();
// draw contents
SkScalar fRotationAngle;
// support framework
DeviceType fType;
SkSurface* fSurface;
GrContext* fContext;
GrRenderTarget* fRenderTarget;
AttachmentInfo fAttachmentInfo;
const GrGLInterface* fInterface;
typedef SkOSWindow INHERITED;
};
#endif