blob: 8b6c29186b9cbb77ba084fe44d7c066773b9f10b [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2006 The Android Open Source Project
reed@android.com8a1c16f2008-12-17 15:59:43 +00003 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00004 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
reed@android.com8a1c16f2008-12-17 15:59:43 +00006 */
7
8#ifndef SkWindow_DEFINED
9#define SkWindow_DEFINED
10
bungemana7e9f052016-02-18 08:53:33 -080011#include "../private/SkTDArray.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000012#include "SkView.h"
13#include "SkBitmap.h"
reed@android.comf2b98d62010-12-20 18:26:13 +000014#include "SkMatrix.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000015#include "SkRegion.h"
16#include "SkEvent.h"
17#include "SkKey.h"
reed4302ae92014-10-06 12:29:56 -070018#include "SkSurfaceProps.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000019
reed0397e9f2014-09-18 11:29:01 -070020class SkSurface;
reed@android.com8a1c16f2008-12-17 15:59:43 +000021class SkOSMenu;
22
caryclarkc8fcafb2015-01-30 12:37:02 -080023#if SK_SUPPORT_GPU
24struct GrGLInterface;
25class GrContext;
26class GrRenderTarget;
27#endif
28
reed@android.com8a1c16f2008-12-17 15:59:43 +000029class SkWindow : public SkView {
30public:
31 SkWindow();
32 virtual ~SkWindow();
33
caryclarkc8fcafb2015-01-30 12:37:02 -080034 struct AttachmentInfo {
brianosman2d1ee792016-05-05 12:24:31 -070035 AttachmentInfo()
36 : fSampleCount(0)
37 , fStencilBits(0)
38 , fColorBits(0) {}
39
caryclarkc8fcafb2015-01-30 12:37:02 -080040 int fSampleCount;
41 int fStencilBits;
brianosman2d1ee792016-05-05 12:24:31 -070042 int fColorBits;
caryclarkc8fcafb2015-01-30 12:37:02 -080043 };
44
reed4302ae92014-10-06 12:29:56 -070045 SkSurfaceProps getSurfaceProps() const { return fSurfaceProps; }
46 void setSurfaceProps(const SkSurfaceProps& props) {
47 fSurfaceProps = props;
48 }
49
reeda34be682016-02-15 07:48:35 -080050 SkImageInfo info() const { return fBitmap.info(); }
reed@android.com8a1c16f2008-12-17 15:59:43 +000051 const SkBitmap& getBitmap() const { return fBitmap; }
52
kkinnunen973d92c2016-01-18 01:18:34 -080053 void resize(int width, int height);
reeda34be682016-02-15 07:48:35 -080054 void resize(const SkImageInfo&);
brianosmanb109b8c2016-06-16 13:03:24 -070055 void setColorType(SkColorType, sk_sp<SkColorSpace>);
reed@android.com8a1c16f2008-12-17 15:59:43 +000056
57 bool isDirty() const { return !fDirtyRgn.isEmpty(); }
reed@google.comaa400ee2012-09-27 21:03:49 +000058 bool update(SkIRect* updateArea);
reed@android.comf2b98d62010-12-20 18:26:13 +000059 // does not call through to onHandleInval(), but does force the fDirtyRgn
60 // to be wide open. Call before update() to ensure we redraw everything.
61 void forceInvalAll();
62 // return the bounds of the dirty/inval rgn, or [0,0,0,0] if none
63 const SkIRect& getDirtyBounds() const { return fDirtyRgn.getBounds(); }
64
reed@google.com4d5c26d2013-01-08 16:17:50 +000065 bool handleClick(int x, int y, Click::State, void* owner, unsigned modi = 0);
reed@android.com8a1c16f2008-12-17 15:59:43 +000066 bool handleChar(SkUnichar);
67 bool handleKey(SkKey);
68 bool handleKeyUp(SkKey);
reed@android.com8a1c16f2008-12-17 15:59:43 +000069
70 void addMenu(SkOSMenu*);
yangsu@google.com654d72f2011-08-01 17:27:33 +000071 const SkTDArray<SkOSMenu*>* getMenus() { return &fMenus; }
rmistry@google.comfbfcd562012-08-23 18:09:54 +000072
reed@android.com0ae6b242008-12-23 16:49:54 +000073 const char* getTitle() const { return fTitle.c_str(); }
reed@android.com8a1c16f2008-12-17 15:59:43 +000074 void setTitle(const char title[]);
75
reed@android.comf2b98d62010-12-20 18:26:13 +000076 const SkMatrix& getMatrix() const { return fMatrix; }
77 void setMatrix(const SkMatrix&);
78 void preConcat(const SkMatrix&);
79 void postConcat(const SkMatrix&);
80
robertphillipsecf3dbe2016-07-28 15:17:34 -070081 virtual sk_sp<SkSurface> makeSurface();
reed@google.com5957f472012-10-01 20:31:56 +000082
jvanverth38c72152016-10-10 07:39:38 -070083#if SK_SUPPORT_GPU
84 sk_sp<SkSurface> makeGpuBackedSurface(const AttachmentInfo& attachmentInfo,
85 const GrGLInterface* , GrContext* grContext);
86#endif
87
reed@android.com8a1c16f2008-12-17 15:59:43 +000088protected:
89 virtual bool onEvent(const SkEvent&);
reed@google.com4d5c26d2013-01-08 16:17:50 +000090 virtual bool onDispatchClick(int x, int y, Click::State, void* owner, unsigned modi);
reed@android.com8a1c16f2008-12-17 15:59:43 +000091 // called if part of our bitmap is invalidated
92 virtual void onHandleInval(const SkIRect&);
93 virtual bool onHandleChar(SkUnichar);
94 virtual bool onHandleKey(SkKey);
95 virtual bool onHandleKeyUp(SkKey);
Brian Osman16adfa32016-10-18 14:42:44 -040096 virtual void onAddMenu(const SkOSMenu*) {}
97 virtual void onUpdateMenu(const SkOSMenu*) {}
reed@android.com8a1c16f2008-12-17 15:59:43 +000098 virtual void onSetTitle(const char title[]) {}
99
100 // overrides from SkView
reed@android.comf2b98d62010-12-20 18:26:13 +0000101 virtual bool handleInval(const SkRect*);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000102 virtual bool onGetFocusView(SkView** focus) const;
103 virtual bool onSetFocusView(SkView* focus);
104
105private:
reed4302ae92014-10-06 12:29:56 -0700106 SkSurfaceProps fSurfaceProps;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000107 SkBitmap fBitmap;
108 SkRegion fDirtyRgn;
Scroggod3aed392011-06-22 13:26:56 +0000109
110 SkTDArray<Click*> fClicks; // to track clicks
reed@android.com8a1c16f2008-12-17 15:59:43 +0000111
112 SkTDArray<SkOSMenu*> fMenus;
113
114 SkView* fFocusView;
115 bool fWaitingOnInval;
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000116
reed@android.com0ae6b242008-12-23 16:49:54 +0000117 SkString fTitle;
reed@android.comf2b98d62010-12-20 18:26:13 +0000118 SkMatrix fMatrix;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000119
120 typedef SkView INHERITED;
121};
122
tfarina@chromium.orge229e922012-09-27 13:44:57 +0000123////////////////////////////////////////////////////////////////////////////////
reed@android.com8a1c16f2008-12-17 15:59:43 +0000124
Hal Canary9e2a3192017-02-06 13:03:36 -0500125#if defined(SK_BUILD_FOR_MAC)
reed@android.com8a1c16f2008-12-17 15:59:43 +0000126 #include "SkOSWindow_Mac.h"
127#elif defined(SK_BUILD_FOR_WIN)
128 #include "SkOSWindow_Win.h"
djsollen@google.com56c69772011-11-08 19:00:26 +0000129#elif defined(SK_BUILD_FOR_ANDROID)
liyuqian97a09182016-07-06 07:52:08 -0700130 #error Android does not support SkOSWindow and SampleApp. Please use Viewer instead.
scroggob7e9aee2011-03-15 15:15:15 +0000131#elif defined(SK_BUILD_FOR_UNIX)
joshualitt474a9ea2015-11-05 11:49:35 -0800132 #include "SkOSWindow_Unix.h"
reed@android.comf2b98d62010-12-20 18:26:13 +0000133#elif defined(SK_BUILD_FOR_IOS)
134 #include "SkOSWindow_iOS.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +0000135#endif
136
137#endif