Home | History | Annotate | Download | only in android
      1 /*
      2  * Copyright 2017 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 #include "SkAndroidFrameworkUtils.h"
      9 #include "SkCanvas.h"
     10 #include "SkDevice.h"
     11 #include "SkPaintFilterCanvas.h"
     12 #include "SkSurface_Base.h"
     13 
     14 #if SK_SUPPORT_GPU
     15 #include "GrStyle.h"
     16 #include "GrClip.h"
     17 #include "GrRenderTargetContext.h"
     18 #include "GrUserStencilSettings.h"
     19 #include "effects/GrDisableColorXP.h"
     20 #endif //SK_SUPPORT_GPU
     21 
     22 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
     23 
     24 #include <log/log.h>
     25 
     26 #if SK_SUPPORT_GPU
     27 bool SkAndroidFrameworkUtils::clipWithStencil(SkCanvas* canvas) {
     28     SkRegion clipRegion;
     29     canvas->temporary_internal_getRgnClip(&clipRegion);
     30     if (clipRegion.isEmpty()) {
     31         return false;
     32     }
     33     SkBaseDevice* device = canvas->getDevice();
     34     if (!device) {
     35         return false;
     36     }
     37     GrRenderTargetContext* rtc = device->accessRenderTargetContext();
     38     if (!rtc) {
     39         return false;
     40     }
     41     GrPaint grPaint;
     42     grPaint.setXPFactory(GrDisableColorXPFactory::Get());
     43     GrNoClip noClip;
     44     static constexpr GrUserStencilSettings kDrawToStencil(
     45         GrUserStencilSettings::StaticInit<
     46             0x1,
     47             GrUserStencilTest::kAlways,
     48             0x1,
     49             GrUserStencilOp::kReplace,
     50             GrUserStencilOp::kReplace,
     51             0x1>()
     52     );
     53     rtc->drawRegion(noClip, std::move(grPaint), GrAA::kNo, SkMatrix::I(), clipRegion,
     54                     GrStyle::SimpleFill(), &kDrawToStencil);
     55     return true;
     56 }
     57 #endif //SK_SUPPORT_GPU
     58 
     59 void SkAndroidFrameworkUtils::SafetyNetLog(const char* bugNumber) {
     60     android_errorWriteLog(0x534e4554, bugNumber);
     61 }
     62 
     63 sk_sp<SkSurface> SkAndroidFrameworkUtils::getSurfaceFromCanvas(SkCanvas* canvas) {
     64     sk_sp<SkSurface> surface(SkSafeRef(canvas->getSurfaceBase()));
     65     return surface;
     66 }
     67 
     68 int SkAndroidFrameworkUtils::SaveBehind(SkCanvas* canvas, const SkRect* subset) {
     69     return canvas->only_axis_aligned_saveBehind(subset);
     70 }
     71 
     72 SkCanvas* SkAndroidFrameworkUtils::getBaseWrappedCanvas(SkCanvas* canvas) {
     73     auto pfc = canvas->internal_private_asPaintFilterCanvas();
     74     auto result = canvas;
     75     while (pfc) {
     76         result = pfc->proxy();
     77         pfc = result->internal_private_asPaintFilterCanvas();
     78     }
     79     return result;
     80 }
     81 #endif // SK_BUILD_FOR_ANDROID_FRAMEWORK
     82 
     83