Changeset 207591 in webkit


Ignore:
Timestamp:
Oct 20, 2016 2:03:29 AM (8 years ago)
Author:
pvollan@apple.com
Message:

[Win][Direct2D] Implement ImageBufferData::getData.
https://bugs.webkit.org/show_bug.cgi?id=163668

Reviewed by Brent Fulgham.

Render data to a bitmap in system memory, which data can be read from.

  • platform/graphics/win/ImageBufferDataDirect2D.cpp:

(WebCore::ImageBufferData::getData):

  • platform/graphics/win/ImageBufferDirect2D.cpp:

(WebCore::ImageBuffer::ImageBuffer):

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r207590 r207591  
     12016-10-20  Per Arne Vollan  <pvollan@apple.com>
     2
     3        [Win][Direct2D] Implement ImageBufferData::getData.
     4        https://bugs.webkit.org/show_bug.cgi?id=163668
     5
     6        Reviewed by Brent Fulgham.
     7
     8        Render data to a bitmap in system memory, which data can be read from.
     9
     10        * platform/graphics/win/ImageBufferDataDirect2D.cpp:
     11        (WebCore::ImageBufferData::getData):
     12        * platform/graphics/win/ImageBufferDirect2D.cpp:
     13        (WebCore::ImageBuffer::ImageBuffer):
     14
    1152016-10-20  Carlos Garcia Campos  <cgarcia@igalia.com>
    216
  • trunk/Source/WebCore/platform/graphics/win/ImageBufferDataDirect2D.cpp

    r206742 r207591  
    2929#if USE(DIRECT2D)
    3030
     31#include "BitmapInfo.h"
    3132#include "GraphicsContext.h"
     33#include "HWndDC.h"
    3234#include "IntRect.h"
    3335#include "NotImplemented.h"
     
    4042namespace WebCore {
    4143
    42 RefPtr<Uint8ClampedArray> ImageBufferData::getData(const IntRect&, const IntSize&, bool /* accelerateRendering */, bool /* unmultiplied */, float /* resolutionScale */) const
     44RefPtr<Uint8ClampedArray> ImageBufferData::getData(const IntRect& rect, const IntSize& size, bool /* accelerateRendering */, bool /* unmultiplied */, float /* resolutionScale */) const
    4345{
    44     notImplemented();
    45     return nullptr;
     46    auto platformContext = context->platformContext();
     47
     48    Checked<unsigned, RecordOverflow> area = 4 * rect.area();
     49    if (area.hasOverflowed())
     50        return nullptr;
     51
     52    auto result = Uint8ClampedArray::createUninitialized(area.unsafeGet());
     53    unsigned char* resultData = result ? result->data() : nullptr;
     54    if (!resultData)
     55        return nullptr;
     56
     57    BitmapInfo bitmapInfo = BitmapInfo::createBottomUp(size);
     58
     59    void* pixels = nullptr;
     60    auto bitmap = adoptGDIObject(::CreateDIBSection(0, &bitmapInfo, DIB_RGB_COLORS, &pixels, 0, 0));
     61
     62    HWndDC windowDC(nullptr);
     63    auto bitmapDC = adoptGDIObject(::CreateCompatibleDC(windowDC));
     64    HGDIOBJ oldBitmap = ::SelectObject(bitmapDC.get(), bitmap.get());
     65
     66    HRESULT hr;
     67
     68    COMPtr<ID2D1GdiInteropRenderTarget> gdiRenderTarget;
     69    hr = platformContext->QueryInterface(__uuidof(ID2D1GdiInteropRenderTarget), (void**)&gdiRenderTarget);
     70    if (FAILED(hr))
     71        return nullptr;
     72
     73    platformContext->BeginDraw();
     74
     75    HDC hdc = nullptr;
     76    hr = gdiRenderTarget->GetDC(D2D1_DC_INITIALIZE_MODE_COPY, &hdc);
     77
     78    BOOL ok = ::BitBlt(bitmapDC.get(), 0, 0, rect.width(), rect.height(), hdc, rect.x(), rect.y(), SRCCOPY);
     79
     80    hr = gdiRenderTarget->ReleaseDC(nullptr);
     81
     82    hr = platformContext->EndDraw();
     83
     84    if (!ok)
     85        return nullptr;
     86
     87    memcpy(result->data(), pixels, 4 * rect.area());
     88
     89    return result;
    4690}
    4791
  • trunk/Source/WebCore/platform/graphics/win/ImageBufferDirect2D.cpp

    r207357 r207591  
    108108
    109109    COMPtr<ID2D1BitmapRenderTarget> bitmapContext;
    110     HRESULT hr = renderTarget->CreateCompatibleRenderTarget(FloatSize(m_logicalSize), &bitmapContext);
     110    D2D1_SIZE_F desiredSize = FloatSize(m_logicalSize);
     111    D2D1_SIZE_U pixelSize = IntSize(m_logicalSize);
     112    HRESULT hr = renderTarget->CreateCompatibleRenderTarget(&desiredSize, &pixelSize, nullptr, D2D1_COMPATIBLE_RENDER_TARGET_OPTIONS_GDI_COMPATIBLE, &bitmapContext);
    111113    if (!bitmapContext || !SUCCEEDED(hr))
    112114        return;
Note: See TracChangeset for help on using the changeset viewer.