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

Unified Diff: src/image/SkImage_Codec.cpp

Issue 461043002: Revert of SkImage_Codec is Lazy (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 4 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 | « gyp/core.gypi ('k') | src/image/SkImage_Raster.cpp » ('j') | 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
new file mode 100644
index 0000000000000000000000000000000000000000..21c844d01dd331b0f4235f215fc11ad494fb84bf
--- /dev/null
+++ b/src/image/SkImage_Codec.cpp
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2012 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkImageDecoder.h"
+#include "SkImage_Base.h"
+#include "SkBitmap.h"
+#include "SkCanvas.h"
+#include "SkData.h"
+
+class SkImage_Codec : public SkImage_Base {
+public:
+ static SkImage* NewEmpty();
+
+ SkImage_Codec(SkData* encodedData, int width, int height);
+ virtual ~SkImage_Codec();
+
+ virtual void onDraw(SkCanvas*, SkScalar, SkScalar, const SkPaint*) const SK_OVERRIDE;
+ virtual void onDrawRectToRect(SkCanvas*, const SkRect*, const SkRect&,
+ const SkPaint*) const SK_OVERRIDE;
+
+private:
+ SkData* fEncodedData;
+ SkBitmap fBitmap;
+
+ typedef SkImage_Base INHERITED;
+};
+
+///////////////////////////////////////////////////////////////////////////////
+
+SkImage_Codec::SkImage_Codec(SkData* data, int width, int height) : INHERITED(width, height) {
+ fEncodedData = data;
+ fEncodedData->ref();
+}
+
+SkImage_Codec::~SkImage_Codec() {
+ fEncodedData->unref();
+}
+
+void SkImage_Codec::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, 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;
+ }
+ }
+ 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;
+ }
+ }
+ canvas->drawBitmapRectToRect(fBitmap, src, dst, paint);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
+SkImage* SkImage::NewEncodedData(SkData* data) {
+ if (NULL == data) {
+ return NULL;
+ }
+
+ SkBitmap bitmap;
+ if (!SkImageDecoder::DecodeMemory(data->bytes(), data->size(), &bitmap, kUnknown_SkColorType,
+ SkImageDecoder::kDecodeBounds_Mode)) {
+ return NULL;
+ }
+
+ return SkNEW_ARGS(SkImage_Codec, (data, bitmap.width(), bitmap.height()));
+}
« no previous file with comments | « gyp/core.gypi ('k') | src/image/SkImage_Raster.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698