Obsolete the graphics API in the .rsh files.

Mark the graphics APIs as no longer available starting with version 23.

Modify the generator to change the #ifdef guards around the API to
enable internal code to still access the obsoleted APIs, as we still
neeed to support them at runtime.

Also, include a documentation change in the rs_convert header file that had not
been included previously.

Change-Id: Iaad4833f504da9aa9f5069a977c37b86d1316d3a
diff --git a/api/GenerateDocumentation.cpp b/api/GenerateDocumentation.cpp
index 389eac9..b78edae 100644
--- a/api/GenerateDocumentation.cpp
+++ b/api/GenerateDocumentation.cpp
@@ -322,7 +322,7 @@
         if (info.minVersion <= 1) {
             // No minimum
             if (info.maxVersion > 0) {
-                stream << "Removed from " << mid << info.maxVersion + 1;
+                stream << "Removed from " << mid << info.maxVersion + 1 << " and beyond";
             }
         } else {
             if (info.maxVersion == 0) {
diff --git a/api/GenerateHeaderFiles.cpp b/api/GenerateHeaderFiles.cpp
index 97ccab6..45cdba9 100644
--- a/api/GenerateHeaderFiles.cpp
+++ b/api/GenerateHeaderFiles.cpp
@@ -38,27 +38,37 @@
     return s;
 }
 
-// Write #ifdef's that ensure that the specified version is present
-static void writeVersionGuardStart(GeneratedFile* file, VersionInfo info) {
+/* Write #ifdef's that ensure that the specified version is present.  If we're at the final version,
+ * add a check on a flag that can be set for internal builds.  This enables us to keep supporting
+ * old APIs in the runtime code.
+ */
+static void writeVersionGuardStart(GeneratedFile* file, VersionInfo info, int finalVersion) {
     if (info.intSize == 32) {
         *file << "#ifndef __LP64__\n";
     } else if (info.intSize == 64) {
         *file << "#ifdef __LP64__\n";
     }
 
+    ostringstream checkMaxVersion;
+    if (info.maxVersion > 0) {
+        checkMaxVersion << "(";
+        if (info.maxVersion == finalVersion) {
+            checkMaxVersion << "defined(RS_DECLARE_EXPIRED_APIS) || ";
+        }
+        checkMaxVersion << "RS_VERSION <= " << info.maxVersion << ")";
+    }
+
     if (info.minVersion <= 1) {
         // No minimum
         if (info.maxVersion > 0) {
-            *file << "#if !defined(RS_VERSION) || (RS_VERSION <= " << info.maxVersion << ")\n";
+            *file << "#if !defined(RS_VERSION) || " << checkMaxVersion.str() << "\n";
         }
     } else {
-        if (info.maxVersion == 0) {
-            // No maximum
-            *file << "#if (defined(RS_VERSION) && (RS_VERSION >= " << info.minVersion << "))\n";
-        } else {
-            *file << "#if (defined(RS_VERSION) && (RS_VERSION >= " << info.minVersion
-                  << ") && (RS_VERSION <= " << info.maxVersion << "))\n";
+        *file << "#if (defined(RS_VERSION) && (RS_VERSION >= " << info.minVersion << ")";
+        if (info.maxVersion > 0) {
+            *file << " && " << checkMaxVersion.str();
         }
+        *file << ")\n";
     }
 }
 
@@ -107,16 +117,18 @@
 }
 
 static void writeConstantSpecification(GeneratedFile* file, const ConstantSpecification& spec) {
+    const Constant* constant = spec.getConstant();
     VersionInfo info = spec.getVersionInfo();
-    writeVersionGuardStart(file, info);
-    *file << "#define " << spec.getConstant()->getName() << " " << spec.getValue() << "\n\n";
+    writeVersionGuardStart(file, info, constant->getFinalVersion());
+    *file << "#define " << constant->getName() << " " << spec.getValue() << "\n\n";
     writeVersionGuardEnd(file, info);
 }
 
 static void writeTypeSpecification(GeneratedFile* file, const TypeSpecification& spec) {
-    const string& typeName = spec.getType()->getName();
+    const Type* type = spec.getType();
+    const string& typeName = type->getName();
     const VersionInfo info = spec.getVersionInfo();
-    writeVersionGuardStart(file, info);
+    writeVersionGuardStart(file, info, type->getFinalVersion());
     switch (spec.getKind()) {
         case SIMPLE:
             *file << "typedef " << spec.getSimpleType() << " " << typeName << ";\n";
@@ -182,7 +194,8 @@
 
 static void writeFunctionPermutation(GeneratedFile* file, const FunctionSpecification& spec,
                                      const FunctionPermutation& permutation) {
-    writeVersionGuardStart(file, spec.getVersionInfo());
+    Function* function = spec.getFunction();
+    writeVersionGuardStart(file, spec.getVersionInfo(), function->getFinalVersion());
 
     // Write linkage info.
     const auto inlineCodeLines = permutation.getInline();
diff --git a/api/Specification.cpp b/api/Specification.cpp
index b36acae..a82fd1b 100644
--- a/api/Specification.cpp
+++ b/api/Specification.cpp
@@ -224,7 +224,20 @@
     return minVersion == 0 || minVersion <= maxApiLevel;
 }
 
-Definition::Definition(const std::string& name) : mName(name), mDeprecated(false), mHidden(false) {
+Definition::Definition(const std::string& name)
+    : mName(name), mDeprecated(false), mHidden(false), mFinalVersion(-1) {
+}
+
+void Definition::updateFinalVersion(const VersionInfo& info) {
+    /* We set it if:
+     * - We have never set mFinalVersion before, or
+     * - The max version is 0, which means we have not expired this API, or
+     * - We have a max that's later than what we currently have.
+     */
+    if (mFinalVersion < 0 || info.maxVersion == 0 ||
+        (mFinalVersion > 0 && info.maxVersion > mFinalVersion)) {
+        mFinalVersion = info.maxVersion;
+    }
 }
 
 void Definition::scanDocumentationTags(Scanner* scanner, bool firstOccurence,
@@ -323,6 +336,7 @@
     Constant* constant = systemSpecification.findOrCreateConstant(name, &created);
     ConstantSpecification* spec = new ConstantSpecification(constant);
     constant->addSpecification(spec);
+    constant->updateFinalVersion(info);
     specFile->addConstantSpecification(spec, created);
     spec->mVersionInfo = info;
 
@@ -348,6 +362,7 @@
     Type* type = systemSpecification.findOrCreateType(name, &created);
     TypeSpecification* spec = new TypeSpecification(type);
     type->addSpecification(spec);
+    type->updateFinalVersion(info);
     specFile->addTypeSpecification(spec, created);
     spec->mVersionInfo = info;
 
@@ -529,6 +544,7 @@
     Function* function = systemSpecification.findOrCreateFunction(name, &created);
     FunctionSpecification* spec = new FunctionSpecification(function);
     function->addSpecification(spec);
+    function->updateFinalVersion(info);
     specFile->addFunctionSpecification(spec, created);
 
     spec->mUnexpandedName = unexpandedName;
diff --git a/api/Specification.h b/api/Specification.h
index e808e60..9783310 100644
--- a/api/Specification.h
+++ b/api/Specification.h
@@ -147,6 +147,7 @@
     std::string mSummary;                   // A one-line description
     std::vector<std::string> mDescription;  // The comments to be included in the header
     std::string mUrl;                       // The URL of the detailed documentation
+    int mFinalVersion;  // API level at which this API was removed, 0 if API is still valid
 
 public:
     Definition(const std::string& name);
@@ -158,8 +159,11 @@
     std::string getSummary() const { return mSummary; }
     const std::vector<std::string>& getDescription() const { return mDescription; }
     std::string getUrl() const { return mUrl; }
+    int getFinalVersion() const { return mFinalVersion; }
 
     void scanDocumentationTags(Scanner* scanner, bool firstOccurence, const SpecFile* specFile);
+    // Keep track of the final version of this API, if any.
+    void updateFinalVersion(const VersionInfo& info);
 };
 
 /* Represents a constant, like M_PI.  This is a grouping of the version specific specifications.
@@ -368,7 +372,7 @@
     FunctionSpecification(Function* function) : mFunction(function), mReturn(nullptr) {}
     ~FunctionSpecification();
 
-    Function* getFunction() { return mFunction; }
+    Function* getFunction() const { return mFunction; }
     std::string getAttribute() const { return mAttribute; }
     std::string getTest() const { return mTest; }
     std::string getPrecisionLimit() const { return mPrecisionLimit; }
diff --git a/api/rs_graphics.spec b/api/rs_graphics.spec
index 4f9d971..a932a53 100644
--- a/api/rs_graphics.spec
+++ b/api/rs_graphics.spec
@@ -17,7 +17,7 @@
 header:
 summary: Graphics Functions and Types
 description:
- The graphics subsystem of RenderScript has been deprecated.
+ The graphics subsystem of RenderScript was removed at API level 23.
 include:
  #ifdef __LP64__
  // TODO We need to fix some of the builds before enabling this error:
@@ -29,7 +29,7 @@
 end:
 
 type: rs_blend_src_func
-version: 16
+version: 16 22
 size: 32
 enum:
 value: RS_BLEND_SRC_ZERO = 0
@@ -48,7 +48,7 @@
 end:
 
 type: rs_blend_dst_func
-version: 16
+version: 16 22
 size: 32
 enum:
 value: RS_BLEND_DST_ZERO = 0
@@ -66,7 +66,7 @@
 end:
 
 type: rs_cull_mode
-version: 16
+version: 16 22
 size: 32
 enum:
 value: RS_CULL_BACK = 0
@@ -79,7 +79,7 @@
 end:
 
 type: rs_depth_func
-version: 16
+version: 16 22
 size: 32
 enum:
 value: RS_DEPTH_FUNC_ALWAYS = 0, "Always drawn"
@@ -98,7 +98,7 @@
 end:
 
 type: rs_primitive
-version: 16
+version: 16 22
 size: 32
 enum:
 value: RS_PRIMITIVE_POINT = 0, "Vertex data will be rendered as a series of points"
@@ -115,6 +115,7 @@
 end:
 
 type: rs_font
+version: 9 22
 size: 32
 simple: _RS_HANDLE
 deprecated:
@@ -126,6 +127,7 @@
 
 
 type: rs_mesh
+version: 9 22
 size: 32
 simple: _RS_HANDLE
 deprecated:
@@ -136,6 +138,7 @@
 end:
 
 type: rs_program_fragment
+version: 9 22
 size: 32
 simple: _RS_HANDLE
 deprecated:
@@ -146,6 +149,7 @@
 end:
 
 type: rs_program_vertex
+version: 9 22
 size: 32
 simple: _RS_HANDLE
 deprecated:
@@ -156,6 +160,7 @@
 end:
 
 type: rs_program_raster
+version: 9 22
 size: 32
 simple: _RS_HANDLE
 deprecated:
@@ -166,6 +171,7 @@
 end:
 
 type: rs_program_store
+version: 9 22
 size: 32
 simple: _RS_HANDLE
 deprecated:
@@ -176,6 +182,7 @@
 end:
 
 function: rsClearObject
+version: 9 22
 size: 32
 t: rs_mesh, rs_program_fragment, rs_program_vertex, rs_program_raster, rs_program_store, rs_font
 ret: void
@@ -184,6 +191,7 @@
 end:
 
 function: rsIsObject
+version: 9 22
 size: 32
 t: rs_mesh, rs_program_fragment, rs_program_vertex, rs_program_raster, rs_program_store, rs_font
 ret: bool
@@ -192,6 +200,7 @@
 end:
 
 function: rsSetObject
+version: 9 22
 size: 32
 t: rs_mesh, rs_program_fragment, rs_program_vertex, rs_program_raster, rs_program_store, rs_font
 ret: void
@@ -201,6 +210,7 @@
 end:
 
 function: rsgAllocationSyncAll
+version: 9 22
 size: 32
 ret: void
 arg: rs_allocation alloc
@@ -217,7 +227,7 @@
 end:
 
 function: rsgAllocationSyncAll
-version: 14
+version: 14 22
 size: 32
 ret: void
 arg: rs_allocation alloc
@@ -226,7 +236,7 @@
 end:
 
 function: rsgBindColorTarget
-version: 14
+version: 14 22
 size: 32
 ret: void
 arg: rs_allocation colorTarget
@@ -239,6 +249,7 @@
 end:
 
 function: rsgBindConstant
+version: 9 22
 size: 32
 ret: void
 arg: rs_program_fragment ps, "program fragment object"
@@ -253,6 +264,7 @@
 end:
 
 function: rsgBindConstant
+version: 9 22
 size: 32
 ret: void
 arg: rs_program_vertex pv, "program vertex object"
@@ -262,7 +274,7 @@
 end:
 
 function: rsgBindDepthTarget
-version: 14
+version: 14 22
 size: 32
 ret: void
 arg: rs_allocation depthTarget
@@ -274,6 +286,7 @@
 end:
 
 function: rsgBindFont
+version: 9 22
 size: 32
 ret: void
 arg: rs_font font, "object to bind"
@@ -285,6 +298,7 @@
 end:
 
 function: rsgBindProgramFragment
+version: 9 22
 size: 32
 ret: void
 arg: rs_program_fragment pf
@@ -296,6 +310,7 @@
 end:
 
 function: rsgBindProgramRaster
+version: 9 22
 size: 32
 ret: void
 arg: rs_program_raster pr
@@ -307,6 +322,7 @@
 end:
 
 function: rsgBindProgramStore
+version: 9 22
 size: 32
 ret: void
 arg: rs_program_store ps
@@ -318,6 +334,7 @@
 end:
 
 function: rsgBindProgramVertex
+version: 9 22
 size: 32
 ret: void
 arg: rs_program_vertex pv
@@ -329,6 +346,7 @@
 end:
 
 function: rsgBindSampler
+version: 9 22
 size: 32
 ret: void
 arg: rs_program_fragment fragment
@@ -343,6 +361,7 @@
 end:
 
 function: rsgBindTexture
+version: 9 22
 size: 32
 ret: void
 arg: rs_program_fragment v
@@ -359,7 +378,7 @@
 end:
 
 function: rsgClearAllRenderTargets
-version: 14
+version: 14 22
 size: 32
 ret: void
 deprecated:
@@ -371,6 +390,7 @@
 end:
 
 function: rsgClearColor
+version: 9 22
 size: 32
 ret: void
 arg: float r
@@ -385,7 +405,7 @@
 end:
 
 function: rsgClearColorTarget
-version: 14
+version: 14 22
 size: 32
 ret: void
 arg: uint slot
@@ -397,6 +417,7 @@
 end:
 
 function: rsgClearDepth
+version: 9 22
 size: 32
 ret: void
 arg: float value
@@ -408,7 +429,7 @@
 end:
 
 function: rsgClearDepthTarget
-version: 14
+version: 14 22
 size: 32
 ret: void
 deprecated:
@@ -419,6 +440,7 @@
 end:
 
 function: rsgDrawMesh
+version: 9 22
 size: 32
 ret: void
 arg: rs_mesh ism, "mesh object to render"
@@ -436,6 +458,7 @@
 end:
 
 function: rsgDrawMesh
+version: 9 22
 size: 32
 ret: void
 arg: rs_mesh ism
@@ -444,6 +467,7 @@
 end:
 
 function: rsgDrawMesh
+version: 9 22
 size: 32
 ret: void
 arg: rs_mesh ism
@@ -454,6 +478,7 @@
 end:
 
 function: rsgDrawQuad
+version: 9 22
 size: 32
 ret: void
 arg: float x1
@@ -477,6 +502,7 @@
 end:
 
 function: rsgDrawQuadTexCoords
+version: 9 22
 size: 32
 ret: void
 arg: float x1
@@ -508,6 +534,7 @@
 end:
 
 function: rsgDrawRect
+version: 9 22
 size: 32
 ret: void
 arg: float x1
@@ -524,6 +551,7 @@
 end:
 
 function: rsgDrawSpriteScreenspace
+version: 9 22
 size: 32
 ret: void
 arg: float x
@@ -542,6 +570,7 @@
 end:
 
 function: rsgDrawText
+version: 9 22
 size: 32
 ret: void
 arg: const char* text
@@ -555,6 +584,7 @@
 end:
 
 function: rsgDrawText
+version: 9 22
 size: 32
 ret: void
 arg: rs_allocation alloc
@@ -564,7 +594,7 @@
 end:
 
 function: rsgFinish
-version: 14
+version: 14 22
 size: 32
 ret: uint
 deprecated:
@@ -575,6 +605,7 @@
 end:
 
 function: rsgFontColor
+version: 9 22
 size: 32
 ret: void
 arg: float r, "red component"
@@ -589,6 +620,7 @@
 end:
 
 function: rsgGetHeight
+version: 9 22
 size: 32
 ret: uint
 deprecated:
@@ -599,6 +631,7 @@
 end:
 
 function: rsgGetWidth
+version: 9 22
 size: 32
 ret: uint
 deprecated:
@@ -609,6 +642,7 @@
 end:
 
 function: rsgMeasureText
+version: 9 22
 size: 32
 ret: void
 arg: const char* text
@@ -625,6 +659,7 @@
 end:
 
 function: rsgMeasureText
+version: 9 22
 size: 32
 ret: void
 arg: rs_allocation alloc
@@ -636,6 +671,7 @@
 end:
 
 function: rsgMeshComputeBoundingBox
+version: 9 22
 size: 32
 ret: void
 arg: rs_mesh mesh
@@ -653,6 +689,7 @@
 end:
 
 function: rsgMeshComputeBoundingBox
+version: 9 22
 size: 32
 attrib: always_inline
 ret: void
@@ -672,7 +709,7 @@
 end:
 
 function: rsgMeshGetIndexAllocation
-version: 16
+version: 16 22
 size: 32
 ret: rs_allocation, "allocation containing index data"
 arg: rs_mesh m, "mesh to get data from"
@@ -686,7 +723,7 @@
 end:
 
 function: rsgMeshGetPrimitive
-version: 16
+version: 16 22
 size: 32
 ret: rs_primitive, "primitive describing how the mesh is rendered"
 arg: rs_mesh m, "mesh to get data from"
@@ -700,7 +737,7 @@
 end:
 
 function: rsgMeshGetPrimitiveCount
-version: 16
+version: 16 22
 size: 32
 ret: uint32_t, "number of primitive groups in the mesh. This would include simple primitives as well as allocations containing index data"
 arg: rs_mesh m, "mesh to get data from"
@@ -713,7 +750,7 @@
 end:
 
 function: rsgMeshGetVertexAllocation
-version: 16
+version: 16 22
 size: 32
 ret: rs_allocation, "allocation containing vertex data"
 arg: rs_mesh m, "mesh to get data from"
@@ -727,7 +764,7 @@
 end:
 
 function: rsgMeshGetVertexAllocationCount
-version: 16
+version: 16 22
 size: 32
 ret: uint32_t, "number of allocations in the mesh that contain vertex data"
 arg: rs_mesh m, "mesh to get data from"
@@ -740,6 +777,7 @@
 end:
 
 function: rsgProgramFragmentConstantColor
+version: 9 22
 size: 32
 ret: void
 arg: rs_program_fragment pf
@@ -755,6 +793,7 @@
 end:
 
 function: rsgProgramVertexGetProjectionMatrix
+version: 9 22
 size: 32
 ret: void
 arg: rs_matrix4x4* proj, "matrix to store the current projection matrix into"
@@ -768,6 +807,7 @@
 end:
 
 function: rsgProgramVertexLoadModelMatrix
+version: 9 22
 size: 32
 ret: void
 arg: const rs_matrix4x4* model, "model matrix"
@@ -781,6 +821,7 @@
 end:
 
 function: rsgProgramVertexLoadProjectionMatrix
+version: 9 22
 size: 32
 ret: void
 arg: const rs_matrix4x4* proj, "projection matrix"
@@ -794,6 +835,7 @@
 end:
 
 function: rsgProgramVertexLoadTextureMatrix
+version: 9 22
 size: 32
 ret: void
 arg: const rs_matrix4x4* tex, "texture matrix"
@@ -807,7 +849,7 @@
 end:
 
 function: rsgProgramRasterGetCullMode
-version: 16
+version: 16 22
 size: 32
 ret: rs_cull_mode
 arg: rs_program_raster pr, "program raster to query"
@@ -819,7 +861,7 @@
 end:
 
 function: rsgProgramRasterIsPointSpriteEnabled
-version: 16
+version: 16 22
 size: 32
 ret: bool
 arg: rs_program_raster pr, "program raster to query"
@@ -831,7 +873,7 @@
 end:
 
 function: rsgProgramStoreGetBlendDstFunc
-version: 16
+version: 16 22
 size: 32
 ret: rs_blend_dst_func
 arg: rs_program_store ps, "program store to query"
@@ -843,7 +885,7 @@
 end:
 
 function: rsgProgramStoreGetBlendSrcFunc
-version: 16
+version: 16 22
 size: 32
 ret: rs_blend_src_func
 arg: rs_program_store ps, "program store to query"
@@ -855,7 +897,7 @@
 end:
 
 function: rsgProgramStoreGetDepthFunc
-version: 16
+version: 16 22
 size: 32
 ret: rs_depth_func
 arg: rs_program_store ps, "program store to query"
@@ -867,7 +909,7 @@
 end:
 
 function: rsgProgramStoreIsColorMaskAlphaEnabled
-version: 16
+version: 16 22
 size: 32
 ret: bool
 arg: rs_program_store ps, "program store to query"
@@ -879,7 +921,7 @@
 end:
 
 function: rsgProgramStoreIsColorMaskBlueEnabled
-version: 16
+version: 16 22
 size: 32
 ret: bool
 arg: rs_program_store ps, "program store to query"
@@ -891,7 +933,7 @@
 end:
 
 function: rsgProgramStoreIsColorMaskGreenEnabled
-version: 16
+version: 16 22
 size: 32
 ret: bool
 arg: rs_program_store ps, "program store to query"
@@ -903,7 +945,7 @@
 end:
 
 function: rsgProgramStoreIsColorMaskRedEnabled
-version: 16
+version: 16 22
 size: 32
 ret: bool
 arg: rs_program_store ps, "program store to query"
@@ -915,7 +957,7 @@
 end:
 
 function: rsgProgramStoreIsDepthMaskEnabled
-version: 16
+version: 16 22
 size: 32
 ret: bool
 arg: rs_program_store ps, "program store to query"
@@ -927,7 +969,7 @@
 end:
 
 function: rsgProgramStoreIsDitherEnabled
-version: 16
+version: 16 22
 size: 32
 ret: bool
 arg: rs_program_store ps, "program store to query"