Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Unified Diff: src/codec/SkJpegAutoClean.h

Issue 1076923002: SkJpegCodec (Closed) Base URL: https://skia.googlesource.com/skia.git@gif-real
Patch Set: SkJpegCodec Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/codec/SkJpegAutoClean.h
diff --git a/src/codec/SkJpegAutoClean.h b/src/codec/SkJpegAutoClean.h
new file mode 100644
index 0000000000000000000000000000000000000000..b9883e93670b1f32a8a1f84fbfe8243d6d0c4f88
--- /dev/null
+++ b/src/codec/SkJpegAutoClean.h
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkJpegAutoClean_DEFINED
+#define SkJpegAutoClean_DEFINED
+
+#include "SkTemplates.h"
+#include <stdio.h>
scroggo 2015/04/10 17:19:05 We should not be using stdio.
msarett 2015/04/13 20:54:04 jpeglib has some sort of odd dependence on stdio.
+extern "C" {
scroggo 2015/04/10 17:19:05 For our other codec headers, we've discovered that
msarett 2015/04/13 20:54:04 Looks like that is the case here.
+ #include "jpeglib.h"
+}
+
+/*
+ * This object automatically cleans up memory after a jpeg decode
+ */
+class JpegAutoClean {
scroggo 2015/04/10 17:19:05 This should inherit from SkNoncopyable.
msarett 2015/04/13 20:54:04 Done.
+public:
+
+ /*
+ * Takes ownership of jpegInfo pointer.
+ */
+ JpegAutoClean(jpeg_decompress_struct* jpegInfo, bool init);
scroggo 2015/04/10 17:19:05 nit: Traditionally, jpeg_decompress_struct is name
msarett 2015/04/13 20:54:04 Maybe for "compress info" and "decompress info"?
+
+ /*
+ * Frees the owned jpeg_decompress_struct pointer as well as any allocated memory
+ * that is referenced in the jpeg_decompress_struct.
+ */
+ ~JpegAutoClean();
+
+ /*
+ * Indicates if the jpeg info struct has been initialized with data.
+ */
+ void setInit(bool init);
+
+ /*
+ * Get the jpeg info pointer.
+ * Retains ownership of the jpeg_decompress_struct pointer.
+ */
+ jpeg_decompress_struct* get();
+
+ /*
+ * Detach the jpeg_decompress_struct pointer.
+ * It is now owned by the caller.
+ */
+ jpeg_decompress_struct* detach();
+
+ /*
+ * Reset the pointer that is owned by this object.
+ * This will free the original pointer and takes ownership of the pointer passed
+ * as an argument.
+ */
+ void reset(jpeg_decompress_struct* jpegInfo);
+
+private:
+
+ /*
+ * Frees the owned jpeg_decompress_struct pointer as well as any allocated memory
+ * that is referenced in the jpeg_decompress_struct.
+ */
+ void free();
+
+ SkAutoTDelete<jpeg_decompress_struct> fJpegInfo;
+ bool fInit;
+};
+
+#endif

Powered by Google App Engine
This is Rietveld 408576698