143f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com/* 243f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com * Copyright 2013 Google Inc. 343f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com * 443f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com * 543f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com * Use of this source code is governed by a BSD-style license that can be 643f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com * found in the LICENSE file. 743f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com * 843f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com */ 943f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com 1043f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com#ifndef SkExample_DEFINED 1143f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com#define SkExample_DEFINED 1243f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com 1343f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com#include "SkWindow.h" 1443f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com#include "SkTRegistry.h" 1543f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com 1643f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.comclass GrContext; 1743f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.comstruct GrGLInterface; 1843f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.comclass GrRenderTarget; 1943f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.comclass SkCanvas; 2043f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.comclass SkExampleWindow; 2143f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com 22e3beb6bd7de7fa211681abbb0be58e80b19885e0commit-bot@chromium.orgclass SkExample : SkNoncopyable { 2343f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.compublic: 2443f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com SkExample(SkExampleWindow* window) : fWindow(window) {} 2543f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com 26b09bfcb7b1c755c996ed76bba377201048e454afcommit-bot@chromium.org virtual ~SkExample() {} 27b09bfcb7b1c755c996ed76bba377201048e454afcommit-bot@chromium.org 2843f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com // Your class should override this method to do its thing. 2943f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com virtual void draw(SkCanvas* canvas) = 0; 3043f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com 3143f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com SkString getName() { return fName; }; 3243f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com // Use this public registry to tell the world about your sample. 33bd6343b1d60d2a85e930f33f4b06b4502b3e8caamtklein@google.com typedef SkTRegistry<SkExample*(*)(SkExampleWindow*)> Registry; 3443f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com 3543f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.comprotected: 3643f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com SkExampleWindow* fWindow; 3743f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com SkString fName; 3843f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com}; 3943f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com 4043f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.comclass SkExampleWindow : public SkOSWindow { 4143f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.compublic: 4243f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com enum DeviceType { 4343f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com kRaster_DeviceType, 4443f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com kGPU_DeviceType, 4543f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com }; 4643f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com SkExampleWindow(void* hwnd); 4743f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com 4843f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com // Changes the device type of the object. 4943f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com bool setupBackend(DeviceType type); 5043f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com void tearDownBackend(); 5143f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com 5243f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com DeviceType getDeviceType() const { return fType; } 5343f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com 5443f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.comprotected: 5543f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com virtual void draw(SkCanvas* canvas) SK_OVERRIDE; 5643f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com 5743f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com virtual void onSizeChange() SK_OVERRIDE; 5843f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com 5943f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com#ifdef SK_BUILD_FOR_WIN 6043f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com virtual void onHandleInval(const SkIRect&) SK_OVERRIDE; 6143f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com#endif 6243f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com 6343f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com SkCanvas* createCanvas() SK_OVERRIDE; 6443f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com 6543f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.comprivate: 6643f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com bool findNextMatch(); // Set example to the first one that matches FLAGS_match. 6743f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com void setupRenderTarget(); 6843f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com bool onHandleChar(SkUnichar unichar) SK_OVERRIDE; 6943f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com 7043f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com DeviceType fType; 7143f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com 7243f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com SkExample* fCurrExample; 7343f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com const SkExample::Registry* fRegistry; 7443f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com GrContext* fContext; 7543f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com GrRenderTarget* fRenderTarget; 7643f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com AttachmentInfo fAttachmentInfo; 7743f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com const GrGLInterface* fInterface; 7843f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com 7943f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com typedef SkOSWindow INHERITED; 8043f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com}; 8143f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com 8243f2b2c833d7c7db200dd02077f0d47d5d7f209asglez@google.com#endif 83