blob: 70241b5ff663ea8861fb5c0bbb430c9c49b4c4a3 [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
11#include "SkView.h"
12#include "SkBitmap.h"
reed@android.comf2b98d62010-12-20 18:26:13 +000013#include "SkMatrix.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000014#include "SkRegion.h"
15#include "SkEvent.h"
16#include "SkKey.h"
reed4302ae92014-10-06 12:29:56 -070017#include "SkSurfaceProps.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000018#include "SkTDArray.h"
19
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 {
35 int fSampleCount;
36 int fStencilBits;
37 };
38
reed4302ae92014-10-06 12:29:56 -070039 SkSurfaceProps getSurfaceProps() const { return fSurfaceProps; }
40 void setSurfaceProps(const SkSurfaceProps& props) {
41 fSurfaceProps = props;
42 }
43
reed@android.com8a1c16f2008-12-17 15:59:43 +000044 const SkBitmap& getBitmap() const { return fBitmap; }
45
commit-bot@chromium.orge24ad232014-02-16 22:03:38 +000046 void setColorType(SkColorType);
commit-bot@chromium.orgb45c56e2014-02-18 23:32:05 +000047 void resize(int width, int height, SkColorType = kUnknown_SkColorType);
reed@android.com8a1c16f2008-12-17 15:59:43 +000048
49 bool isDirty() const { return !fDirtyRgn.isEmpty(); }
reed@google.comaa400ee2012-09-27 21:03:49 +000050 bool update(SkIRect* updateArea);
reed@android.comf2b98d62010-12-20 18:26:13 +000051 // does not call through to onHandleInval(), but does force the fDirtyRgn
52 // to be wide open. Call before update() to ensure we redraw everything.
53 void forceInvalAll();
54 // return the bounds of the dirty/inval rgn, or [0,0,0,0] if none
55 const SkIRect& getDirtyBounds() const { return fDirtyRgn.getBounds(); }
56
reed@google.com4d5c26d2013-01-08 16:17:50 +000057 bool handleClick(int x, int y, Click::State, void* owner, unsigned modi = 0);
reed@android.com8a1c16f2008-12-17 15:59:43 +000058 bool handleChar(SkUnichar);
59 bool handleKey(SkKey);
60 bool handleKeyUp(SkKey);
reed@android.com8a1c16f2008-12-17 15:59:43 +000061
62 void addMenu(SkOSMenu*);
yangsu@google.com654d72f2011-08-01 17:27:33 +000063 const SkTDArray<SkOSMenu*>* getMenus() { return &fMenus; }
rmistry@google.comfbfcd562012-08-23 18:09:54 +000064
reed@android.com0ae6b242008-12-23 16:49:54 +000065 const char* getTitle() const { return fTitle.c_str(); }
reed@android.com8a1c16f2008-12-17 15:59:43 +000066 void setTitle(const char title[]);
67
reed@android.comf2b98d62010-12-20 18:26:13 +000068 const SkMatrix& getMatrix() const { return fMatrix; }
69 void setMatrix(const SkMatrix&);
70 void preConcat(const SkMatrix&);
71 void postConcat(const SkMatrix&);
72
reed0397e9f2014-09-18 11:29:01 -070073 virtual SkSurface* createSurface();
reed@google.com5957f472012-10-01 20:31:56 +000074
Scroggo8ac0d542011-06-21 14:44:57 +000075 virtual void onPDFSaved(const char title[], const char desc[],
76 const char path[]) {}
joshualittda7b8432015-05-27 09:19:03 -070077
reed@android.com8a1c16f2008-12-17 15:59:43 +000078protected:
79 virtual bool onEvent(const SkEvent&);
reed@google.com4d5c26d2013-01-08 16:17:50 +000080 virtual bool onDispatchClick(int x, int y, Click::State, void* owner, unsigned modi);
reed@android.com8a1c16f2008-12-17 15:59:43 +000081 // called if part of our bitmap is invalidated
82 virtual void onHandleInval(const SkIRect&);
83 virtual bool onHandleChar(SkUnichar);
84 virtual bool onHandleKey(SkKey);
85 virtual bool onHandleKeyUp(SkKey);
yangsu@google.com654d72f2011-08-01 17:27:33 +000086 virtual void onAddMenu(const SkOSMenu*) {};
87 virtual void onUpdateMenu(const SkOSMenu*) {};
reed@android.com8a1c16f2008-12-17 15:59:43 +000088 virtual void onSetTitle(const char title[]) {}
89
90 // overrides from SkView
reed@android.comf2b98d62010-12-20 18:26:13 +000091 virtual bool handleInval(const SkRect*);
reed@android.com8a1c16f2008-12-17 15:59:43 +000092 virtual bool onGetFocusView(SkView** focus) const;
93 virtual bool onSetFocusView(SkView* focus);
94
caryclarkc8fcafb2015-01-30 12:37:02 -080095#if SK_SUPPORT_GPU
96 GrRenderTarget* renderTarget(const AttachmentInfo& attachmentInfo,
97 const GrGLInterface* , GrContext* grContext);
98#endif
99
reed@android.com8a1c16f2008-12-17 15:59:43 +0000100private:
reed4302ae92014-10-06 12:29:56 -0700101 SkSurfaceProps fSurfaceProps;
commit-bot@chromium.orge24ad232014-02-16 22:03:38 +0000102 SkColorType fColorType;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000103 SkBitmap fBitmap;
104 SkRegion fDirtyRgn;
Scroggod3aed392011-06-22 13:26:56 +0000105
106 SkTDArray<Click*> fClicks; // to track clicks
reed@android.com8a1c16f2008-12-17 15:59:43 +0000107
108 SkTDArray<SkOSMenu*> fMenus;
109
110 SkView* fFocusView;
111 bool fWaitingOnInval;
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000112
reed@android.com0ae6b242008-12-23 16:49:54 +0000113 SkString fTitle;
reed@android.comf2b98d62010-12-20 18:26:13 +0000114 SkMatrix fMatrix;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000115
116 typedef SkView INHERITED;
117};
118
tfarina@chromium.orge229e922012-09-27 13:44:57 +0000119////////////////////////////////////////////////////////////////////////////////
reed@android.com8a1c16f2008-12-17 15:59:43 +0000120
bungeman3ac6b752015-07-29 13:37:27 -0700121#if defined(SK_USE_SDL)
122 #include "SkOSWindow_SDL.h"
123#elif defined(SK_BUILD_FOR_MAC)
reed@android.com8a1c16f2008-12-17 15:59:43 +0000124 #include "SkOSWindow_Mac.h"
125#elif defined(SK_BUILD_FOR_WIN)
126 #include "SkOSWindow_Win.h"
djsollen@google.com56c69772011-11-08 19:00:26 +0000127#elif defined(SK_BUILD_FOR_ANDROID)
Scroggof33d1532011-05-31 17:10:21 +0000128 #include "SkOSWindow_Android.h"
scroggob7e9aee2011-03-15 15:15:15 +0000129#elif defined(SK_BUILD_FOR_UNIX)
reed@android.com8a1c16f2008-12-17 15:59:43 +0000130 #include "SkOSWindow_Unix.h"
reed@android.comf2b98d62010-12-20 18:26:13 +0000131#elif defined(SK_BUILD_FOR_IOS)
132 #include "SkOSWindow_iOS.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +0000133#endif
134
135#endif