summaryrefslogtreecommitdiffstats
path: root/gfx
diff options
context:
space:
mode:
Diffstat (limited to 'gfx')
-rw-r--r--gfx/skia_util.cc21
-rw-r--r--gfx/skia_util.h10
2 files changed, 27 insertions, 4 deletions
diff --git a/gfx/skia_util.cc b/gfx/skia_util.cc
index 13ef4d9..865f8fda 100644
--- a/gfx/skia_util.cc
+++ b/gfx/skia_util.cc
@@ -5,6 +5,7 @@
#include "gfx/skia_util.h"
#include "gfx/rect.h"
+#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkColorPriv.h"
#include "third_party/skia/include/core/SkShader.h"
#include "third_party/skia/include/effects/SkGradientShader.h"
@@ -38,5 +39,23 @@ SkShader* CreateGradientShader(int start_point,
grad_points, grad_colors, NULL, 2, SkShader::kRepeat_TileMode);
}
-} // namespace gfx
+bool BitmapsAreEqual(const SkBitmap& bitmap1, const SkBitmap& bitmap2) {
+ void* addr1 = NULL;
+ void* addr2 = NULL;
+ size_t size1 = 0;
+ size_t size2 = 0;
+
+ bitmap1.lockPixels();
+ addr1 = bitmap1.getAddr32(0, 0);
+ size1 = bitmap1.getSize();
+ bitmap1.unlockPixels();
+
+ bitmap2.lockPixels();
+ addr2 = bitmap2.getAddr32(0, 0);
+ size2 = bitmap2.getSize();
+ bitmap2.unlockPixels();
+ return (size1 == size2) && (0 == memcmp(addr1, addr2, bitmap1.getSize()));
+}
+
+} // namespace gfx
diff --git a/gfx/skia_util.h b/gfx/skia_util.h
index 4a55c77..26c54bf 100644
--- a/gfx/skia_util.h
+++ b/gfx/skia_util.h
@@ -2,13 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef APP_GFX_SKIA_UTIL_H_
-#define APP_GFX_SKIA_UTIL_H_
+#ifndef GFX_SKIA_UTIL_H_
+#define GFX_SKIA_UTIL_H_
#pragma once
#include "third_party/skia/include/core/SkColor.h"
#include "third_party/skia/include/core/SkRect.h"
+class SkBitmap;
class SkShader;
namespace gfx {
@@ -30,6 +31,9 @@ SkShader* CreateGradientShader(int start_point,
SkColor start_color,
SkColor end_color);
+// Returns true if the two bitmaps contain the same pixels.
+bool BitmapsAreEqual(const SkBitmap& bitmap1, const SkBitmap& bitmap2);
+
} // namespace gfx;
-#endif // APP_GFX_SKIA_UTIL_H_
+#endif // GFX_SKIA_UTIL_H_