Chromium Code Reviews| 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); |
| +} |
| + |
| +} |