Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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 "modules/imagebitmap/ImageBitmapRenderingContext.h" | |
| 6 | |
| 7 #include "core/frame/ImageBitmap.h" | |
| 8 #include "platform/graphics/GraphicsContext.h" | |
| 9 #include "platform/graphics/StaticBitmapImage.h" | |
| 10 #include "third_party/skia/include/core/SkImage.h" | |
| 11 #include "third_party/skia/include/core/SkSurface.h" | |
| 12 | |
| 13 namespace blink { | |
| 14 | |
| 15 ImageBitmapRenderingContext::ImageBitmapRenderingContext(HTMLCanvasElement* canv as, CanvasContextCreationAttributes attrs, Document& document) | |
| 16 : CanvasRenderingContext(canvas) | |
| 17 , m_hasAlpha(attrs.alpha()) | |
| 18 { } | |
| 19 | |
| 20 ImageBitmapRenderingContext::~ImageBitmapRenderingContext() { } | |
| 21 | |
| 22 void ImageBitmapRenderingContext::transferImageBitmap(ImageBitmap* imageBitmap) | |
| 23 { | |
| 24 m_image = imageBitmap->bitmapImage(); | |
|
Stephen White
2016/02/10 15:34:55
colorPicker->pickColorColorPickPick(). :)
Justin Novosad
2016/02/10 15:50:21
LOL!!! The old days...
| |
| 25 if (!m_image) | |
| 26 return; | |
| 27 | |
| 28 RefPtr<SkImage> skImage = m_image->imageForCurrentFrame(); | |
| 29 if (skImage->isTextureBacked()) { | |
| 30 // TODO(junov): crbug.com/585607 Eliminate this readback and use an Exte rnalTextureLayer | |
|
Stephen White
2016/02/10 15:34:55
Should we do this check only for display-list canv
Justin Novosad
2016/02/10 15:50:21
It is not display list canvas that is the problem,
Stephen White
2016/02/10 15:56:08
Right, but isn't impl-side rasterization only util
Justin Novosad
2016/02/10 16:09:29
There is no "display list mode". The concept of di
Stephen White
2016/02/10 16:11:34
Acknowledged. These are not the nits you're lookin
| |
| 31 RefPtr<SkSurface> surface = SkSurface::NewRasterN32Premul(skImage->width (), skImage->height()); | |
| 32 if (!surface) { | |
| 33 // silent failure | |
|
Stephen White
2016/02/10 15:34:55
Is a silent failure spec-compliant? If not, please
Justin Novosad
2016/02/10 15:50:21
The handling of general OOM failures is not specif
Stephen White
2016/02/10 15:56:08
Acknowledged.
| |
| 34 m_image.clear(); | |
| 35 return; | |
| 36 } | |
| 37 surface->getCanvas()->drawImage(skImage.get(), 0, 0); | |
| 38 m_image = StaticBitmapImage::create(surface->newImageSnapshot()); | |
| 39 } | |
| 40 canvas()->didDraw(FloatRect(FloatPoint(), FloatSize(m_image->width(), m_imag e->height()))); | |
| 41 } | |
| 42 | |
| 43 bool ImageBitmapRenderingContext::paint(GraphicsContext& gc, const IntRect& r) | |
| 44 { | |
| 45 if (!m_image) | |
| 46 return true; | |
| 47 | |
| 48 // With impl-side painting, it is unsafe to use a gpu-backed SkImage | |
| 49 ASSERT(!m_image->imageForCurrentFrame()->isTextureBacked()); | |
| 50 gc.drawImage(m_image.get(), r, m_hasAlpha ? SkXfermode::kSrcOver_Mode : SkXf ermode::kSrc_Mode); | |
| 51 | |
| 52 return true; | |
| 53 } | |
| 54 | |
| 55 PassOwnPtrWillBeRawPtr<CanvasRenderingContext> ImageBitmapRenderingContext::Fact ory::create(HTMLCanvasElement* canvas, const CanvasContextCreationAttributes& at trs, Document& document) | |
| 56 { | |
| 57 if (!RuntimeEnabledFeatures::experimentalCanvasFeaturesEnabled()) | |
| 58 return nullptr; | |
| 59 return adoptPtrWillBeNoop(new ImageBitmapRenderingContext(canvas, attrs, doc ument)); | |
| 60 } | |
| 61 | |
| 62 void ImageBitmapRenderingContext::stop() | |
| 63 { | |
| 64 m_image.clear(); | |
| 65 } | |
| 66 | |
| 67 } // blink | |
| OLD | NEW |