15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/*
251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * Copyright (c) 2013, Google Inc. All rights reserved.
35c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
45c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without
55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * modification, are permitted provided that the following conditions are
65c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * met:
75c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
85c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *     * Redistributions of source code must retain the above copyright
95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * notice, this list of conditions and the following disclaimer.
105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *     * Redistributions in binary form must reproduce the above
115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * copyright notice, this list of conditions and the following disclaimer
125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * in the documentation and/or other materials provided with the
135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * distribution.
145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *     * Neither the name of Google Inc. nor the names of its
155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * contributors may be used to endorse or promote products derived from
165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * this software without specific prior written permission.
175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) */
305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
31a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#include "config.h"
3251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
33a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#include "platform/graphics/ImageBufferSurface.h"
34a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)
35aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch#include "platform/graphics/ImageBuffer.h"
36a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#include "third_party/skia/include/core/SkCanvas.h"
37a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#include "third_party/skia/include/core/SkDevice.h"
38c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)#include "third_party/skia/include/core/SkPicture.h"
395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
40c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)namespace blink {
415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
42aafa69cb17c9d6606c07663ade5f81388a2c5986Ben MurdochImageBufferSurface::ImageBufferSurface(const IntSize& size, OpacityMode opacityMode)
43aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch    : m_opacityMode(opacityMode)
44aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch    , m_size(size)
45aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch{
46aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch    setIsHidden(false);
47aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch}
48aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch
49c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)PassRefPtr<SkPicture> ImageBufferSurface::getPicture()
50c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles){
51c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    return nullptr;
52c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)}
53c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)
54a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)void ImageBufferSurface::clear()
55a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles){
56a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    // Clear the background transparent or opaque, as required. It would be nice if this wasn't
57a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    // required, but the canvas is currently filled with the magic transparency
58a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    // color. Can we have another way to manage this?
59a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    if (isValid()) {
60a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)        if (m_opacityMode == Opaque)
61a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)            canvas()->drawARGB(255, 0, 0, 0, SkXfermode::kSrc_Mode);
62a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)        else
63a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)            canvas()->drawARGB(0, 0, 0, 0, SkXfermode::kClear_Mode);
64c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)        didClearCanvas();
65a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    }
66a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)}
675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
68c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)const SkBitmap& ImageBufferSurface::bitmap()
69a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles){
70a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    ASSERT(canvas());
71e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    willAccessPixels();
72a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    return canvas()->getTopDevice()->accessBitmap(false);
73a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)}
7451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
7509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)const SkBitmap& ImageBufferSurface::cachedBitmap() const
7609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){
7709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    DEFINE_STATIC_LOCAL(SkBitmap, nullBitmap, ());
7809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    return nullBitmap;
7909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)}
80a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)
81c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)} // namespace blink
82