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