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

Unified Diff: src/image/SkImage_Codec.cpp

Issue 579773003: Small refactoring in SkImage_Codec (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 3 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/image/SkImage_Codec.cpp
diff --git a/src/image/SkImage_Codec.cpp b/src/image/SkImage_Codec.cpp
index 0b14216a064d9c6d81670f418b25692b58a9c8bf..4e00e267f8f100f26a5cbffa3e72a9b7d7965bea 100644
--- a/src/image/SkImage_Codec.cpp
+++ b/src/image/SkImage_Codec.cpp
@@ -25,6 +25,8 @@ public:
virtual bool isOpaque() const SK_OVERRIDE;
private:
+ bool ensureBitmapDecoded() const;
+
SkData* fEncodedData;
SkBitmap fBitmap;
@@ -42,26 +44,31 @@ SkImage_Codec::~SkImage_Codec() {
fEncodedData->unref();
}
-void SkImage_Codec::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint) const {
+bool SkImage_Codec::ensureBitmapDecoded() const {
if (!fBitmap.pixelRef()) {
// todo: this needs to be thread-safe
SkBitmap* bitmap = const_cast<SkBitmap*>(&fBitmap);
if (!SkImageDecoder::DecodeMemory(fEncodedData->bytes(), fEncodedData->size(), bitmap)) {
- return;
+ return false;
}
}
+ return true;
+}
+
+void SkImage_Codec::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint) const {
+ if(!this->ensureBitmapDecoded()) {
+ return;
+ }
+
canvas->drawBitmap(fBitmap, x, y, paint);
}
void SkImage_Codec::onDrawRectToRect(SkCanvas* canvas, const SkRect* src, const SkRect& dst,
const SkPaint* paint) const {
- if (!fBitmap.pixelRef()) {
- // todo: this needs to be thread-safe
- SkBitmap* bitmap = const_cast<SkBitmap*>(&fBitmap);
- if (!SkImageDecoder::DecodeMemory(fEncodedData->bytes(), fEncodedData->size(), bitmap)) {
- return;
- }
+ if(!this->ensureBitmapDecoded()) {
+ return;
}
+
canvas->drawBitmapRectToRect(fBitmap, src, dst, paint);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698