OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2016 Google Inc. | 3 * Copyright 2016 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "RasterWindowContext_android.h" | 9 #include "WindowContextFactory_android.h" |
10 | 10 #include "../RasterWindowContext.h" |
11 #include "SkSurface.h" | 11 #include "SkSurface.h" |
12 #include "SkTypes.h" | 12 #include "SkTypes.h" |
13 | 13 |
14 #include "Window_android.h" | 14 using sk_app::RasterWindowContext; |
| 15 using sk_app::DisplayParams; |
15 | 16 |
16 namespace sk_app { | 17 namespace { |
| 18 class RasterWindowContext_android : public RasterWindowContext { |
| 19 public: |
| 20 RasterWindowContext_android(ANativeWindow*, const DisplayParams& params); |
17 | 21 |
18 RasterWindowContext* RasterWindowContext::Create(void* platformData, const Displ
ayParams& params) { | 22 sk_sp<SkSurface> getBackbufferSurface() override; |
19 RasterWindowContext* ctx = new RasterWindowContext_android(platformData, par
ams); | 23 void swapBuffers() override; |
20 if (!ctx->isValid()) { | |
21 delete ctx; | |
22 ctx = nullptr; | |
23 } | |
24 return ctx; | |
25 } | |
26 | 24 |
27 RasterWindowContext_android::RasterWindowContext_android( | 25 bool isValid() override { return SkToBool(fNativeWindow); } |
28 void* platformData, const DisplayParams& params) { | 26 void resize(uint32_t w, uint32_t h) override; |
| 27 void setDisplayParams(const DisplayParams& params) override; |
| 28 |
| 29 private: |
| 30 void setBuffersGeometry(); |
| 31 sk_sp<SkSurface> fBackbufferSurface = nullptr; |
| 32 ANativeWindow* fNativeWindow = nullptr; |
| 33 ANativeWindow_Buffer fBuffer; |
| 34 ARect fBounds; |
| 35 }; |
| 36 |
| 37 RasterWindowContext_android::RasterWindowContext_android(ANativeWindow* window, |
| 38 const DisplayParams& pa
rams) { |
29 fDisplayParams = params; | 39 fDisplayParams = params; |
30 ContextPlatformData_android* androidPlatformData = | 40 fNativeWindow = window; |
31 reinterpret_cast<ContextPlatformData_android*>(platformData); | |
32 fNativeWindow = androidPlatformData->fNativeWindow; | |
33 fWidth = ANativeWindow_getWidth(fNativeWindow); | 41 fWidth = ANativeWindow_getWidth(fNativeWindow); |
34 fHeight = ANativeWindow_getHeight(fNativeWindow); | 42 fHeight = ANativeWindow_getHeight(fNativeWindow); |
35 this->setBuffersGeometry(); | 43 this->setBuffersGeometry(); |
36 } | 44 } |
37 | 45 |
38 void RasterWindowContext_android::setBuffersGeometry() { | 46 void RasterWindowContext_android::setBuffersGeometry() { |
39 int32_t format = 0; | 47 int32_t format = 0; |
40 switch(fDisplayParams.fColorType) { | 48 switch(fDisplayParams.fColorType) { |
41 case kRGBA_8888_SkColorType: | 49 case kRGBA_8888_SkColorType: |
42 format = WINDOW_FORMAT_RGBA_8888; | 50 format = WINDOW_FORMAT_RGBA_8888; |
(...skipping 30 matching lines...) Expand all Loading... |
73 info, fBuffer.bits, fBuffer.stride * bytePerPixel, nullptr); | 81 info, fBuffer.bits, fBuffer.stride * bytePerPixel, nullptr); |
74 } | 82 } |
75 return fBackbufferSurface; | 83 return fBackbufferSurface; |
76 } | 84 } |
77 | 85 |
78 | 86 |
79 void RasterWindowContext_android::swapBuffers() { | 87 void RasterWindowContext_android::swapBuffers() { |
80 ANativeWindow_unlockAndPost(fNativeWindow); | 88 ANativeWindow_unlockAndPost(fNativeWindow); |
81 fBackbufferSurface.reset(nullptr); | 89 fBackbufferSurface.reset(nullptr); |
82 } | 90 } |
| 91 } // anonymous namespace |
83 | 92 |
| 93 namespace sk_app { |
| 94 namespace window_context_factory { |
| 95 |
| 96 WindowContext* NewRasterForAndroid(ANativeWindow* window, const DisplayParams& p
arams) { |
| 97 WindowContext* ctx = new RasterWindowContext_android(window, params); |
| 98 if (!ctx->isValid()) { |
| 99 delete ctx; |
| 100 return nullptr; |
| 101 } |
| 102 return ctx; |
| 103 } |
| 104 |
| 105 } |
84 } // namespace sk_app | 106 } // namespace sk_app |
OLD | NEW |