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

Unified Diff: Source/platform/graphics/StaticBitmapImage.cpp

Issue 358893002: Use newImageSnapshot() to get an image from a Canvas (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Correcting bugs and use new cache mechanism from SkImage Created 6 years, 5 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: Source/platform/graphics/StaticBitmapImage.cpp
diff --git a/LICENSE b/Source/platform/graphics/StaticBitmapImage.cpp
similarity index 50%
copy from LICENSE
copy to Source/platform/graphics/StaticBitmapImage.cpp
index 70bcb8ad118978579fa055f7ecc99604930900ce..13c5a17ffb571316898e3ba2aa2e8b8339d4ae47 100644
--- a/LICENSE
+++ b/Source/platform/graphics/StaticBitmapImage.cpp
@@ -28,3 +28,52 @@
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "config.h"
+#include "StaticBitmapImage.h"
+
+#include "platform/graphics/GraphicsContext.h"
+#include "platform/graphics/ImageObserver.h"
+#include "platform/graphics/skia/NativeImageSkia.h"
+#include "third_party/skia/include/core/SkPaint.h"
+#include "third_party/skia/include/core/SkShader.h"
+
+namespace WebCore {
+
+PassRefPtr<Image> StaticBitmapImage::create(PassRefPtr<SkImage> image)
+{
+ return adoptRef(new StaticBitmapImage(image));
+}
+
+StaticBitmapImage::StaticBitmapImage(PassRefPtr<SkImage> image) : m_image(image)
+{
+ m_image->setGpuToCpuCachingMechanism(SkImage::kWholeBitmap_CachingMechanism);
Justin Novosad 2014/07/29 14:56:52 Mechanism -> Mode or Strategy?
Rémi Piotaix 2014/07/29 17:18:23 Strategy :D Done
+}
+
+void StaticBitmapImage::draw(GraphicsContext* ctx, const FloatRect& dstRect, const FloatRect& srcRect, CompositeOperator compositeOp, blink::WebBlendMode blendMode)
+{
+ FloatRect normDstRect = adjustForNegativeSize(dstRect);
+ FloatRect normSrcRect = adjustForNegativeSize(srcRect);
+
+ normSrcRect.intersect(FloatRect(0, 0, m_image->width(), m_image->height()));
+
+ if (normSrcRect.isEmpty() || normDstRect.isEmpty())
+ return; // Nothing to draw.
+
+ ASSERT(normSrcRect.width() <= m_image->width() && normSrcRect.height() <= m_image->height());
+
+ SkPaint paint;
+ ctx->preparePaintForDrawRectToRect(&paint, srcRect, dstRect, compositeOp, blendMode);
+
+ SkRect srcSkRect = WebCoreFloatRectToSKRect(normSrcRect);
+ SkRect dstSkRect = WebCoreFloatRectToSKRect(normDstRect);
+
+ SkCanvas* canvas = ctx->canvas();
+
+ m_image->draw(canvas, &srcSkRect, dstSkRect, &paint);
+
+ if (ImageObserver* observer = imageObserver())
+ observer->didDraw(this);
+}
+
+}

Powered by Google App Engine
This is Rietveld 408576698