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

Side by Side 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: Corrections Created 6 years, 2 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "config.h"
6 #include "platform/graphics/StaticBitmapImage.h"
7
8 #include "platform/graphics/GraphicsContext.h"
9 #include "platform/graphics/ImageObserver.h"
10 #include "platform/graphics/skia/NativeImageSkia.h"
11 #include "third_party/skia/include/core/SkImage.h"
12 #include "third_party/skia/include/core/SkPaint.h"
13 #include "third_party/skia/include/core/SkShader.h"
14
15 namespace blink {
16
17 PassRefPtr<Image> StaticBitmapImage::create(PassRefPtr<SkImage> image)
18 {
19 return adoptRef(new StaticBitmapImage(image));
20 }
21
22 StaticBitmapImage::StaticBitmapImage(PassRefPtr<SkImage> image) : m_image(image)
23 {
24 }
25
26 StaticBitmapImage::~StaticBitmapImage() { }
27
28 IntSize StaticBitmapImage::size() const
29 {
30 return IntSize(m_image->width(), m_image->height());
31 }
32
33 bool StaticBitmapImage::currentFrameKnownToBeOpaque()
34 {
35 return m_image->isOpaque();
36 }
37
38 void StaticBitmapImage::draw(GraphicsContext* ctx, const FloatRect& dstRect, con st FloatRect& srcRect, CompositeOperator compositeOp, blink::WebBlendMode blendM ode)
39 {
40 FloatRect normDstRect = adjustForNegativeSize(dstRect);
41 FloatRect normSrcRect = adjustForNegativeSize(srcRect);
42
43 normSrcRect.intersect(FloatRect(0, 0, m_image->width(), m_image->height()));
44
45 if (normSrcRect.isEmpty() || normDstRect.isEmpty())
46 return; // Nothing to draw.
47
48 ASSERT(normSrcRect.width() <= m_image->width() && normSrcRect.height() <= m_ image->height());
49
50 SkPaint paint;
51 ctx->preparePaintForDrawRectToRect(&paint, srcRect, dstRect, compositeOp, bl endMode);
52
53 SkRect srcSkRect = WebCoreFloatRectToSKRect(normSrcRect);
54 SkRect dstSkRect = WebCoreFloatRectToSKRect(normDstRect);
55
56 SkCanvas* canvas = ctx->canvas();
57
58 canvas->drawImageRect(m_image.get(), &srcSkRect, dstSkRect, &paint);
59
60 if (ImageObserver* observer = imageObserver())
61 observer->didDraw(this);
62 }
63
64 }
OLDNEW
« no previous file with comments | « Source/platform/graphics/StaticBitmapImage.h ('k') | Source/platform/graphics/StaticBitmapPattern.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698