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

Unified Diff: skia/sgl/SkMask.cpp

Issue 93093: Implement canvas's globalCompositeOperation lighter properly.... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 11 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
« no previous file with comments | « skia/sgl/SkDraw.cpp ('k') | skia/sgl/SkXfermode.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: skia/sgl/SkMask.cpp
===================================================================
--- skia/sgl/SkMask.cpp (revision 14480)
+++ skia/sgl/SkMask.cpp (working copy)
@@ -15,41 +15,29 @@
** limitations under the License.
*/
-#include <limits>
-
+#include "Sk64.h"
#include "SkMask.h"
-size_t SkMask::computeImageSize() const
-{
- // Prevent too large a number. There is a better fix for this in Skia
- // trunk where it returns failure.
- long long size = (long long)fBounds.height() * (long long)fRowBytes;
- if (size >= std::numeric_limits<size_t>::max() / 2) {
-#ifdef WIN32
- __debugbreak();
-#else
- abort();
-#endif
+/** returns the product if it is positive and fits in 31 bits. Otherwise this
+ returns 0.
+ */
+static int32_t safeMul32(int32_t a, int32_t b) {
+ Sk64 size;
+ size.setMul(a, b);
+ if (size.is32() && size.isPos()) {
+ return size.get32();
}
+ return 0;
+}
- return size;
+size_t SkMask::computeImageSize() const {
+ return safeMul32(fBounds.height(), fRowBytes);
}
-size_t SkMask::computeTotalImageSize() const
-{
+size_t SkMask::computeTotalImageSize() const {
size_t size = this->computeImageSize();
-
if (fFormat == SkMask::k3D_Format) {
- // See computeImageSize for why we want to stop here.
- if (size > std::numeric_limits<size_t>::max() / 3) {
-#ifdef WIN32
- __debugbreak();
-#else
- abort();
-#endif
- }
-
- size *= 3;
+ size = safeMul32(size, 3);
}
return size;
}
« no previous file with comments | « skia/sgl/SkDraw.cpp ('k') | skia/sgl/SkXfermode.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698