| 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 "WindowContextFactory_android.h" | 9 #include "WindowContextFactory_android.h" |
| 10 #include "../RasterWindowContext.h" | 10 #include "../RasterWindowContext.h" |
| 11 #include "SkSurface.h" | 11 #include "SkSurface.h" |
| 12 #include "SkTypes.h" | 12 #include "SkTypes.h" |
| 13 | 13 |
| 14 using sk_app::RasterWindowContext; | 14 using sk_app::RasterWindowContext; |
| 15 using sk_app::DisplayParams; | 15 using sk_app::DisplayParams; |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 class RasterWindowContext_android : public RasterWindowContext { | 18 class RasterWindowContext_android : public RasterWindowContext { |
| 19 public: | 19 public: |
| 20 RasterWindowContext_android(ANativeWindow*, const DisplayParams& params); | 20 RasterWindowContext_android(ANativeWindow*, const DisplayParams& params); |
| 21 | 21 |
| 22 sk_sp<SkSurface> getBackbufferSurface() override; | 22 sk_sp<SkSurface> getBackbufferSurface() override; |
| 23 void swapBuffers() override; | 23 void swapBuffers() override; |
| 24 | 24 |
| 25 bool isValid() override { return SkToBool(fNativeWindow); } | 25 bool isValid() override { return SkToBool(fNativeWindow); } |
| 26 void resize(uint32_t w, uint32_t h) override; | 26 void resize(int w, int h) override; |
| 27 void setDisplayParams(const DisplayParams& params) override; | 27 void setDisplayParams(const DisplayParams& params) override; |
| 28 | 28 |
| 29 private: | 29 private: |
| 30 void setBuffersGeometry(); | 30 void setBuffersGeometry(); |
| 31 sk_sp<SkSurface> fBackbufferSurface = nullptr; | 31 sk_sp<SkSurface> fBackbufferSurface = nullptr; |
| 32 ANativeWindow* fNativeWindow = nullptr; | 32 ANativeWindow* fNativeWindow = nullptr; |
| 33 ANativeWindow_Buffer fBuffer; | 33 ANativeWindow_Buffer fBuffer; |
| 34 ARect fBounds; | 34 ARect fBounds; |
| 35 }; | 35 }; |
| 36 | 36 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 56 SK_ABORT("Unsupported Android color type"); | 56 SK_ABORT("Unsupported Android color type"); |
| 57 } | 57 } |
| 58 ANativeWindow_setBuffersGeometry(fNativeWindow, fWidth, fHeight, format); | 58 ANativeWindow_setBuffersGeometry(fNativeWindow, fWidth, fHeight, format); |
| 59 } | 59 } |
| 60 | 60 |
| 61 void RasterWindowContext_android::setDisplayParams(const DisplayParams& params)
{ | 61 void RasterWindowContext_android::setDisplayParams(const DisplayParams& params)
{ |
| 62 fDisplayParams = params; | 62 fDisplayParams = params; |
| 63 this->setBuffersGeometry(); | 63 this->setBuffersGeometry(); |
| 64 } | 64 } |
| 65 | 65 |
| 66 void RasterWindowContext_android::resize(uint32_t w, uint32_t h) { | 66 void RasterWindowContext_android::resize(int w, int h) { |
| 67 fWidth = w; | 67 fWidth = w; |
| 68 fHeight = h; | 68 fHeight = h; |
| 69 this->setBuffersGeometry(); | 69 this->setBuffersGeometry(); |
| 70 } | 70 } |
| 71 | 71 |
| 72 sk_sp<SkSurface> RasterWindowContext_android::getBackbufferSurface() { | 72 sk_sp<SkSurface> RasterWindowContext_android::getBackbufferSurface() { |
| 73 if (nullptr == fBackbufferSurface) { | 73 if (nullptr == fBackbufferSurface) { |
| 74 ANativeWindow_lock(fNativeWindow, &fBuffer, &fBounds); | 74 ANativeWindow_lock(fNativeWindow, &fBuffer, &fBounds); |
| 75 const int bytePerPixel = fBuffer.format == WINDOW_FORMAT_RGB_565 ? 2 : 4
; | 75 const int bytePerPixel = fBuffer.format == WINDOW_FORMAT_RGB_565 ? 2 : 4
; |
| 76 SkImageInfo info = SkImageInfo::Make(fWidth, fHeight, | 76 SkImageInfo info = SkImageInfo::Make(fWidth, fHeight, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 97 WindowContext* ctx = new RasterWindowContext_android(window, params); | 97 WindowContext* ctx = new RasterWindowContext_android(window, params); |
| 98 if (!ctx->isValid()) { | 98 if (!ctx->isValid()) { |
| 99 delete ctx; | 99 delete ctx; |
| 100 return nullptr; | 100 return nullptr; |
| 101 } | 101 } |
| 102 return ctx; | 102 return ctx; |
| 103 } | 103 } |
| 104 | 104 |
| 105 } | 105 } |
| 106 } // namespace sk_app | 106 } // namespace sk_app |
| OLD | NEW |