Reland image storage with fixes.

Revert "Revert "Initial OpenGL Image support.""

This reverts commit 59dc41175d99d0a31c046aec0c26c4d82a3a3574.

BUG=skia:

Change-Id: Ibe3c87ce7f746f065fdbcc5a518388cc291112f5
Reviewed-on: https://skia-review.googlesource.com/5131
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
diff --git a/src/gpu/GrProcessor.cpp b/src/gpu/GrProcessor.cpp
index 1e100e4..f4f7ccb 100644
--- a/src/gpu/GrProcessor.cpp
+++ b/src/gpu/GrProcessor.cpp
@@ -122,7 +122,12 @@
 
 void GrProcessor::addBufferAccess(const BufferAccess* access) {
     fBufferAccesses.push_back(access);
-    this->addGpuResource(access->getProgramBuffer());
+    this->addGpuResource(access->programBuffer());
+}
+
+void GrProcessor::addImageStorageAccess(const ImageStorageAccess* access) {
+    fImageStorageAccesses.push_back(access);
+    this->addGpuResource(access->programTexture());
 }
 
 void* GrProcessor::operator new(size_t size) {
@@ -133,9 +138,10 @@
     return MemoryPoolAccessor().pool()->release(target);
 }
 
-bool GrProcessor::hasSameSamplers(const GrProcessor& that) const {
+bool GrProcessor::hasSameSamplersAndAccesses(const GrProcessor &that) const {
     if (this->numTextureSamplers() != that.numTextureSamplers() ||
-        this->numBuffers() != that.numBuffers()) {
+        this->numBuffers() != that.numBuffers() ||
+        this->numImageStorages() != that.numImageStorages()) {
         return false;
     }
     for (int i = 0; i < this->numTextureSamplers(); ++i) {
@@ -148,6 +154,11 @@
             return false;
         }
     }
+    for (int i = 0; i < this->numImageStorages(); ++i) {
+        if (this->imageStorageAccess(i) != that.imageStorageAccess(i)) {
+            return false;
+        }
+    }
     return true;
 }
 
@@ -189,6 +200,37 @@
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
+GrProcessor::ImageStorageAccess::ImageStorageAccess(sk_sp<GrTexture> texture, GrIOType ioType,
+                                                    GrSLMemoryModel memoryModel,
+                                                    GrSLRestrict restrict,
+                                                    GrShaderFlags visibility) {
+    SkASSERT(texture);
+    fTexture.set(texture.release(), ioType);
+    fMemoryModel = memoryModel;
+    fRestrict = restrict;
+    fVisibility = visibility;
+    // We currently infer this from the config. However, we could allow the client to specify
+    // a format that is different but compatible with the config.
+    switch (fTexture.get()->config()) {
+        case kRGBA_8888_GrPixelConfig:
+            fFormat = GrImageStorageFormat::kRGBA8;
+            break;
+        case kRGBA_8888_sint_GrPixelConfig:
+            fFormat = GrImageStorageFormat::kRGBA8i;
+            break;
+        case kRGBA_half_GrPixelConfig:
+            fFormat = GrImageStorageFormat::kRGBA16f;
+            break;
+        case kRGBA_float_GrPixelConfig:
+            fFormat = GrImageStorageFormat::kRGBA32f;
+            break;
+        default:
+            SkFAIL("Config is not (yet) supported as image storage.");
+            break;
+    }
+}
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
 // Initial static variable from GrXPFactory
-int32_t GrXPFactory::gCurrXPFClassID =
-        GrXPFactory::kIllegalXPFClassID;
+int32_t GrXPFactory::gCurrXPFClassID = GrXPFactory::kIllegalXPFClassID;