| 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 "RasterWindowContext_android.h" | 
|  10  |  10  | 
| (...skipping 14 matching lines...) Expand all  Loading... | 
|  25 } |  25 } | 
|  26  |  26  | 
|  27 RasterWindowContext_android::RasterWindowContext_android( |  27 RasterWindowContext_android::RasterWindowContext_android( | 
|  28         void* platformData, const DisplayParams& params) { |  28         void* platformData, const DisplayParams& params) { | 
|  29     fDisplayParams = params; |  29     fDisplayParams = params; | 
|  30     ContextPlatformData_android* androidPlatformData = |  30     ContextPlatformData_android* androidPlatformData = | 
|  31             reinterpret_cast<ContextPlatformData_android*>(platformData); |  31             reinterpret_cast<ContextPlatformData_android*>(platformData); | 
|  32     fNativeWindow = androidPlatformData->fNativeWindow; |  32     fNativeWindow = androidPlatformData->fNativeWindow; | 
|  33     fWidth = ANativeWindow_getWidth(fNativeWindow); |  33     fWidth = ANativeWindow_getWidth(fNativeWindow); | 
|  34     fHeight = ANativeWindow_getHeight(fNativeWindow); |  34     fHeight = ANativeWindow_getHeight(fNativeWindow); | 
 |  35     this->setBuffersGeometry(); | 
 |  36 } | 
 |  37  | 
 |  38 void RasterWindowContext_android::setBuffersGeometry() { | 
|  35     int32_t format; |  39     int32_t format; | 
|  36     switch(params.fColorType) { |  40     switch(fDisplayParams.fColorType) { | 
|  37         case kRGBA_8888_SkColorType: |  41         case kRGBA_8888_SkColorType: | 
|  38             format = WINDOW_FORMAT_RGBA_8888; |  42             format = WINDOW_FORMAT_RGBA_8888; | 
|  39             break; |  43             break; | 
|  40         case kRGB_565_SkColorType: |  44         case kRGB_565_SkColorType: | 
|  41             format = WINDOW_FORMAT_RGB_565; |  45             format = WINDOW_FORMAT_RGB_565; | 
|  42             break; |  46             break; | 
|  43         default: |  47         default: | 
|  44             SkDEBUGFAIL("Unsupported Android color type"); |  48             SkDEBUGFAIL("Unsupported Android color type"); | 
|  45     } |  49     } | 
|  46     ANativeWindow_setBuffersGeometry(fNativeWindow, fWidth, fHeight, format); |  50     ANativeWindow_setBuffersGeometry(fNativeWindow, fWidth, fHeight, format); | 
|  47 } |  51 } | 
|  48  |  52  | 
 |  53 void RasterWindowContext_android::setDisplayParams(const DisplayParams& params) 
    { | 
 |  54     fDisplayParams = params; | 
 |  55     this->setBuffersGeometry(); | 
 |  56 } | 
 |  57  | 
 |  58 void RasterWindowContext_android::resize(uint32_t w, uint32_t h) { | 
 |  59     fWidth = w; | 
 |  60     fHeight = h; | 
 |  61     this->setBuffersGeometry(); | 
 |  62 } | 
 |  63  | 
|  49 sk_sp<SkSurface> RasterWindowContext_android::getBackbufferSurface() { |  64 sk_sp<SkSurface> RasterWindowContext_android::getBackbufferSurface() { | 
|  50     if (nullptr == fBackbufferSurface) { |  65     if (nullptr == fBackbufferSurface) { | 
|  51         ANativeWindow_lock(fNativeWindow, &fBuffer, &fBounds); |  66         ANativeWindow_lock(fNativeWindow, &fBuffer, &fBounds); | 
|  52         const int bytePerPixel = fBuffer.format == WINDOW_FORMAT_RGB_565 ? 2 : 4
    ; |  67         const int bytePerPixel = fBuffer.format == WINDOW_FORMAT_RGB_565 ? 2 : 4
    ; | 
|  53         SkImageInfo info = SkImageInfo::Make(fWidth, fHeight, |  68         SkImageInfo info = SkImageInfo::Make(fWidth, fHeight, | 
|  54                                              fDisplayParams.fColorType, |  69                                              fDisplayParams.fColorType, | 
|  55                                              kOpaque_SkAlphaType, |  70                                              kOpaque_SkAlphaType, | 
|  56                                              fDisplayParams.fProfileType); |  71                                              fDisplayParams.fProfileType); | 
|  57         fBackbufferSurface = SkSurface::MakeRasterDirect( |  72         fBackbufferSurface = SkSurface::MakeRasterDirect( | 
|  58                 info, fBuffer.bits, fBuffer.stride * bytePerPixel, nullptr); |  73                 info, fBuffer.bits, fBuffer.stride * bytePerPixel, nullptr); | 
|  59     } |  74     } | 
|  60     return fBackbufferSurface; |  75     return fBackbufferSurface; | 
|  61 } |  76 } | 
|  62  |  77  | 
|  63  |  78  | 
|  64 void RasterWindowContext_android::swapBuffers() { |  79 void RasterWindowContext_android::swapBuffers() { | 
|  65     ANativeWindow_unlockAndPost(fNativeWindow); |  80     ANativeWindow_unlockAndPost(fNativeWindow); | 
|  66     fBackbufferSurface.reset(nullptr); |  81     fBackbufferSurface.reset(nullptr); | 
|  67 } |  82 } | 
|  68  |  83  | 
|  69 }   // namespace sk_app |  84 }   // namespace sk_app | 
| OLD | NEW |