• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2021 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef JetSki_Surface_DEFINED
9 #define JetSki_Surface_DEFINED
10 
11 #include "include/core/SkRefCnt.h"
12 #include "include/core/SkSurface.h"
13 
14 #include <jni.h>
15 #include <android/native_window_jni.h>
16 #include <android/native_window.h>
17 
18 #include "tools/window/SkWindowContext.h"
19 
20 #include "include/core/SkImage.h"
21 #include "include/core/SkPictureRecorder.h"
22 #include "include/core/SkRefCnt.h"
23 #include "include/core/SkSurface.h"
24 #include "include/core/SkTypes.h"
25 
26 class SurfaceThread;
27 #include "modules/jetski/src/SurfaceThread.h"
28 
29 class Surface : public SkRefCnt {
30 public:
31     virtual void release(JNIEnv*) = 0;
32     virtual void flushAndSubmit() = 0;
33     virtual SkCanvas* getCanvas() = 0;
34 
width()35     int width()  const { return fSurface ? fSurface->width()  : 0; }
height()36     int height() const { return fSurface ? fSurface->height() : 0; }
37 
makeImageSnapshot()38     sk_sp<SkImage> makeImageSnapshot() const {
39         return fSurface ? fSurface->makeImageSnapshot() : nullptr;
40     }
41 
42 protected:
43     sk_sp<SkSurface> fSurface;
44 };
45 
46 class WindowSurface final : public Surface {
47 public:
48     WindowSurface(ANativeWindow* win, std::unique_ptr<SkWindowContext> wctx);
49 
50 private:
51     void release(JNIEnv* env) override;
52     SkCanvas* getCanvas() override;
53     void flushAndSubmit() override;
54 
55     ANativeWindow*                         fWindow;
56     std::unique_ptr<SkWindowContext> fWindowContext;
57 };
58 
59 class ThreadedSurface final : public Surface {
60 public:
61     ThreadedSurface(JNIEnv* env, jobject surface);
62 
63 private:
64     void release(JNIEnv* env) override;
65     SkCanvas* getCanvas() override;
66     void flushAndSubmit() override;
67 
68     WindowSurface* fWindowSurface = nullptr;
69     SkPictureRecorder fRecorder;
70     std::unique_ptr<SurfaceThread> fThread;
71     int fWidth;
72     int fHeight;
73 };
74 
75 #endif
76