Add arc support to gpu Obj c++ code

This is mainly for getting ready to start adding lots of metal backend code.
I've also update the "gpu tools" target to require ARC with involved updating
one IOS file in there.

Bug: skia:
Change-Id: Ied22e8fe7532445cc274efb529e3450654a6614b
Reviewed-on: https://skia-review.googlesource.com/22484
Commit-Queue: Greg Daniel <egdaniel@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
diff --git a/BUILD.gn b/BUILD.gn
index 7be16ef..26eeb95 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -531,10 +531,12 @@
     public_defines += [ "SK_ENABLE_SPIRV_VALIDATION" ]
   }
 
+  cflags_objcc = []
   if (skia_use_metal) {
     public_defines += [ "SK_METAL" ]
     sources += skia_metal_sources
     libs += [ "Metal.framework" ]
+    cflags_objcc += [ "-fobjc-arc" ]
   }
 }
 
@@ -973,6 +975,8 @@
         ]
       }
 
+      cflags_objcc = [ "-fobjc-arc" ]
+
       if (skia_use_angle) {
         deps += [ "//third_party/angle2" ]
         sources += [ "tools/gpu/gl/angle/GLTestContext_angle.cpp" ]
diff --git a/gn/BUILD.gn b/gn/BUILD.gn
index d275bd6..71475a8 100644
--- a/gn/BUILD.gn
+++ b/gn/BUILD.gn
@@ -263,6 +263,7 @@
   cflags = []
   cflags_cc = []
   cflags_objc = []
+  cflags_objcc = []
   if (is_win) {
     cflags += [
       "/W3",  # Turn on lots of warnings.
@@ -356,6 +357,10 @@
         "-Wno-direct-ivar-access",
         "-Wno-objc-interface-ivars",
       ]
+      cflags_objcc += [
+        "-Wno-direct-ivar-access",
+        "-Wno-objcc-interface-ivars",
+      ]
     }
   }
 }
diff --git a/gn/toolchain/BUILD.gn b/gn/toolchain/BUILD.gn
index a4c13a7..55778ef 100644
--- a/gn/toolchain/BUILD.gn
+++ b/gn/toolchain/BUILD.gn
@@ -210,7 +210,7 @@
 
     tool("objcxx") {
       depfile = "{{output}}.d"
-      command = "$cc_wrapper $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} {{cflags_objc}} -c {{source}} -o {{output}}"
+      command = "$cc_wrapper $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} {{cflags_objcc}} -c {{source}} -o {{output}}"
       depsformat = "gcc"
       outputs = [
         "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
diff --git a/src/gpu/mtl/GrMtlGpu.mm b/src/gpu/mtl/GrMtlGpu.mm
index c19dcdf..7d9339c 100644
--- a/src/gpu/mtl/GrMtlGpu.mm
+++ b/src/gpu/mtl/GrMtlGpu.mm
@@ -7,6 +7,10 @@
 
 #include "GrMtlGpu.h"
 
+#if !__has_feature(objc_arc)
+#error This file must be compiled with Arc. Use -fobjc-arc flag
+#endif
+
 GrGpu* GrMtlGpu::Create(GrBackendContext backendContext, const GrContextOptions& options,
                         GrContext* context) {
     return nullptr;
diff --git a/tools/gpu/gl/iOS/CreatePlatformGLTestContext_iOS.mm b/tools/gpu/gl/iOS/CreatePlatformGLTestContext_iOS.mm
index 954e88e..1fd50d1 100644
--- a/tools/gpu/gl/iOS/CreatePlatformGLTestContext_iOS.mm
+++ b/tools/gpu/gl/iOS/CreatePlatformGLTestContext_iOS.mm
@@ -26,7 +26,7 @@
     void onPlatformSwapBuffers() const override;
     GrGLFuncPtr onPlatformGetProcAddress(const char*) const override;
 
-    void* fEAGLContext;
+    EAGLContext* fEAGLContext;
     void* fGLLibrary;
 };
 
@@ -35,13 +35,13 @@
     , fGLLibrary(RTLD_DEFAULT) {
 
     if (shareContext) {
-        EAGLContext* iosShareContext = (EAGLContext*)(shareContext->fEAGLContext);
+        EAGLContext* iosShareContext = shareContext->fEAGLContext;
         fEAGLContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2
                                             sharegroup: [iosShareContext sharegroup]];
     } else {
         fEAGLContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
     }
-    [EAGLContext setCurrentContext:EAGLCTX];
+    [EAGLContext setCurrentContext:fEAGLContext];
 
     sk_sp<const GrGLInterface> gl(GrGLCreateNativeInterface());
     if (NULL == gl.get()) {
@@ -69,11 +69,10 @@
 
 void IOSGLTestContext::destroyGLContext() {
     if (fEAGLContext) {
-        if ([EAGLContext currentContext] == EAGLCTX) {
+        if ([EAGLContext currentContext] == fEAGLContext) {
             [EAGLContext setCurrentContext:nil];
         }
-        [EAGLCTX release];
-        fEAGLContext = NULL;
+        fEAGLContext = nil;
     }
     if (RTLD_DEFAULT != fGLLibrary) {
         dlclose(fGLLibrary);
@@ -82,7 +81,7 @@
 
 
 void IOSGLTestContext::onPlatformMakeCurrent() const {
-    if (![EAGLContext setCurrentContext:EAGLCTX]) {
+    if (![EAGLContext setCurrentContext:fEAGLContext]) {
         SkDebugf("Could not set the context.\n");
     }
 }