reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2006 The Android Open Source Project |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 3 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #ifndef SkWindow_DEFINED |
| 9 | #define SkWindow_DEFINED |
| 10 | |
bungeman | a7e9f05 | 2016-02-18 08:53:33 -0800 | [diff] [blame] | 11 | #include "../private/SkTDArray.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 12 | #include "SkView.h" |
| 13 | #include "SkBitmap.h" |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 14 | #include "SkMatrix.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 15 | #include "SkRegion.h" |
| 16 | #include "SkEvent.h" |
| 17 | #include "SkKey.h" |
reed | 4302ae9 | 2014-10-06 12:29:56 -0700 | [diff] [blame] | 18 | #include "SkSurfaceProps.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 19 | |
reed | 0397e9f | 2014-09-18 11:29:01 -0700 | [diff] [blame] | 20 | class SkSurface; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 21 | class SkOSMenu; |
| 22 | |
caryclark | c8fcafb | 2015-01-30 12:37:02 -0800 | [diff] [blame] | 23 | #if SK_SUPPORT_GPU |
| 24 | struct GrGLInterface; |
| 25 | class GrContext; |
| 26 | class GrRenderTarget; |
| 27 | #endif |
| 28 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 29 | class SkWindow : public SkView { |
| 30 | public: |
| 31 | SkWindow(); |
| 32 | virtual ~SkWindow(); |
| 33 | |
caryclark | c8fcafb | 2015-01-30 12:37:02 -0800 | [diff] [blame] | 34 | struct AttachmentInfo { |
brianosman | 2d1ee79 | 2016-05-05 12:24:31 -0700 | [diff] [blame] | 35 | AttachmentInfo() |
| 36 | : fSampleCount(0) |
| 37 | , fStencilBits(0) |
| 38 | , fColorBits(0) {} |
| 39 | |
caryclark | c8fcafb | 2015-01-30 12:37:02 -0800 | [diff] [blame] | 40 | int fSampleCount; |
| 41 | int fStencilBits; |
brianosman | 2d1ee79 | 2016-05-05 12:24:31 -0700 | [diff] [blame] | 42 | int fColorBits; |
caryclark | c8fcafb | 2015-01-30 12:37:02 -0800 | [diff] [blame] | 43 | }; |
| 44 | |
reed | 4302ae9 | 2014-10-06 12:29:56 -0700 | [diff] [blame] | 45 | SkSurfaceProps getSurfaceProps() const { return fSurfaceProps; } |
| 46 | void setSurfaceProps(const SkSurfaceProps& props) { |
| 47 | fSurfaceProps = props; |
| 48 | } |
| 49 | |
reed | a34be68 | 2016-02-15 07:48:35 -0800 | [diff] [blame] | 50 | SkImageInfo info() const { return fBitmap.info(); } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 51 | const SkBitmap& getBitmap() const { return fBitmap; } |
| 52 | |
kkinnunen | 973d92c | 2016-01-18 01:18:34 -0800 | [diff] [blame] | 53 | void resize(int width, int height); |
reed | a34be68 | 2016-02-15 07:48:35 -0800 | [diff] [blame] | 54 | void resize(const SkImageInfo&); |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 55 | void setColorType(SkColorType, sk_sp<SkColorSpace>); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 56 | |
| 57 | bool isDirty() const { return !fDirtyRgn.isEmpty(); } |
reed@google.com | aa400ee | 2012-09-27 21:03:49 +0000 | [diff] [blame] | 58 | bool update(SkIRect* updateArea); |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 59 | // 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.com | 4d5c26d | 2013-01-08 16:17:50 +0000 | [diff] [blame] | 65 | bool handleClick(int x, int y, Click::State, void* owner, unsigned modi = 0); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 66 | bool handleChar(SkUnichar); |
| 67 | bool handleKey(SkKey); |
| 68 | bool handleKeyUp(SkKey); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 69 | |
| 70 | void addMenu(SkOSMenu*); |
yangsu@google.com | 654d72f | 2011-08-01 17:27:33 +0000 | [diff] [blame] | 71 | const SkTDArray<SkOSMenu*>* getMenus() { return &fMenus; } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 72 | |
reed@android.com | 0ae6b24 | 2008-12-23 16:49:54 +0000 | [diff] [blame] | 73 | const char* getTitle() const { return fTitle.c_str(); } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 74 | void setTitle(const char title[]); |
| 75 | |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 76 | const SkMatrix& getMatrix() const { return fMatrix; } |
| 77 | void setMatrix(const SkMatrix&); |
| 78 | void preConcat(const SkMatrix&); |
| 79 | void postConcat(const SkMatrix&); |
| 80 | |
robertphillips | ecf3dbe | 2016-07-28 15:17:34 -0700 | [diff] [blame] | 81 | virtual sk_sp<SkSurface> makeSurface(); |
reed@google.com | 5957f47 | 2012-10-01 20:31:56 +0000 | [diff] [blame] | 82 | |
jvanverth | 38c7215 | 2016-10-10 07:39:38 -0700 | [diff] [blame] | 83 | #if SK_SUPPORT_GPU |
| 84 | sk_sp<SkSurface> makeGpuBackedSurface(const AttachmentInfo& attachmentInfo, |
| 85 | const GrGLInterface* , GrContext* grContext); |
| 86 | #endif |
| 87 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 88 | protected: |
| 89 | virtual bool onEvent(const SkEvent&); |
reed@google.com | 4d5c26d | 2013-01-08 16:17:50 +0000 | [diff] [blame] | 90 | virtual bool onDispatchClick(int x, int y, Click::State, void* owner, unsigned modi); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 91 | // 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 Osman | 16adfa3 | 2016-10-18 14:42:44 -0400 | [diff] [blame] | 96 | virtual void onAddMenu(const SkOSMenu*) {} |
| 97 | virtual void onUpdateMenu(const SkOSMenu*) {} |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 98 | virtual void onSetTitle(const char title[]) {} |
| 99 | |
| 100 | // overrides from SkView |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 101 | virtual bool handleInval(const SkRect*); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 102 | virtual bool onGetFocusView(SkView** focus) const; |
| 103 | virtual bool onSetFocusView(SkView* focus); |
| 104 | |
| 105 | private: |
reed | 4302ae9 | 2014-10-06 12:29:56 -0700 | [diff] [blame] | 106 | SkSurfaceProps fSurfaceProps; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 107 | SkBitmap fBitmap; |
| 108 | SkRegion fDirtyRgn; |
Scroggo | d3aed39 | 2011-06-22 13:26:56 +0000 | [diff] [blame] | 109 | |
| 110 | SkTDArray<Click*> fClicks; // to track clicks |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 111 | |
| 112 | SkTDArray<SkOSMenu*> fMenus; |
| 113 | |
| 114 | SkView* fFocusView; |
| 115 | bool fWaitingOnInval; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 116 | |
reed@android.com | 0ae6b24 | 2008-12-23 16:49:54 +0000 | [diff] [blame] | 117 | SkString fTitle; |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 118 | SkMatrix fMatrix; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 119 | |
| 120 | typedef SkView INHERITED; |
| 121 | }; |
| 122 | |
tfarina@chromium.org | e229e92 | 2012-09-27 13:44:57 +0000 | [diff] [blame] | 123 | //////////////////////////////////////////////////////////////////////////////// |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 124 | |
bungeman | 3ac6b75 | 2015-07-29 13:37:27 -0700 | [diff] [blame] | 125 | #if defined(SK_USE_SDL) |
| 126 | #include "SkOSWindow_SDL.h" |
| 127 | #elif defined(SK_BUILD_FOR_MAC) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 128 | #include "SkOSWindow_Mac.h" |
| 129 | #elif defined(SK_BUILD_FOR_WIN) |
| 130 | #include "SkOSWindow_Win.h" |
djsollen@google.com | 56c6977 | 2011-11-08 19:00:26 +0000 | [diff] [blame] | 131 | #elif defined(SK_BUILD_FOR_ANDROID) |
liyuqian | 97a0918 | 2016-07-06 07:52:08 -0700 | [diff] [blame] | 132 | #error Android does not support SkOSWindow and SampleApp. Please use Viewer instead. |
scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 133 | #elif defined(SK_BUILD_FOR_UNIX) |
joshualitt | 474a9ea | 2015-11-05 11:49:35 -0800 | [diff] [blame] | 134 | #include "SkOSWindow_Unix.h" |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 135 | #elif defined(SK_BUILD_FOR_IOS) |
| 136 | #include "SkOSWindow_iOS.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 137 | #endif |
| 138 | |
| 139 | #endif |