Store egl::Image size/format information at initialization time.

This avoids potential null-dereferences on the source if it is orphaned.

BUG=angleproject:2668

Change-Id: I5d591a941d114bb231044572a31a8c43cf3a9c4f
Reviewed-on: https://chromium-review.googlesource.com/1155104
Commit-Queue: Geoff Lang <geofflang@chromium.org>
Reviewed-by: Yuly Novikov <ynovikov@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/libANGLE/Image.cpp b/src/libANGLE/Image.cpp
index 24866b9..dc2467b 100644
--- a/src/libANGLE/Image.cpp
+++ b/src/libANGLE/Image.cpp
@@ -118,7 +118,13 @@
 }
 
 ImageState::ImageState(EGLenum target, ImageSibling *buffer, const AttributeMap &attribs)
-    : label(nullptr), imageIndex(GetImageIndex(target, attribs)), source(buffer), targets()
+    : label(nullptr),
+      imageIndex(GetImageIndex(target, attribs)),
+      source(buffer),
+      targets(),
+      format(buffer->getAttachmentFormat(GL_NONE, imageIndex)),
+      size(buffer->getAttachmentSize(imageIndex)),
+      samples(buffer->getAttachmentSamples(imageIndex))
 {
 }
 
@@ -198,24 +204,24 @@
     return gl::NoError();
 }
 
-gl::Format Image::getFormat() const
+const gl::Format &Image::getFormat() const
 {
-    return mState.source->getAttachmentFormat(GL_NONE, mState.imageIndex);
+    return mState.format;
 }
 
 size_t Image::getWidth() const
 {
-    return mState.source->getAttachmentSize(mState.imageIndex).width;
+    return mState.size.width;
 }
 
 size_t Image::getHeight() const
 {
-    return mState.source->getAttachmentSize(mState.imageIndex).height;
+    return mState.size.height;
 }
 
 size_t Image::getSamples() const
 {
-    return mState.source->getAttachmentSamples(mState.imageIndex);
+    return mState.samples;
 }
 
 rx::ImageImpl *Image::getImplementation() const
diff --git a/src/libANGLE/Image.h b/src/libANGLE/Image.h
index 7b7b762..c7ade12 100644
--- a/src/libANGLE/Image.h
+++ b/src/libANGLE/Image.h
@@ -72,6 +72,10 @@
     gl::ImageIndex imageIndex;
     gl::BindingPointer<ImageSibling> source;
     std::set<ImageSibling *> targets;
+
+    gl::Format format;
+    gl::Extents size;
+    size_t samples;
 };
 
 class Image final : public gl::RefCountObject, public LabeledObject
@@ -89,7 +93,7 @@
     void setLabel(EGLLabelKHR label) override;
     EGLLabelKHR getLabel() const override;
 
-    gl::Format getFormat() const;
+    const gl::Format &getFormat() const;
     size_t getWidth() const;
     size_t getHeight() const;
     size_t getSamples() const;