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 "build/build_config.h" |
| 6 #include "skia/ext/layer_allocator_win.h" |
| 7 #include "third_party/skia/include/core/SkMatrix.h" |
| 8 #include "third_party/skia/include/core/SkRect.h" |
| 9 |
| 10 namespace { |
| 11 |
| 12 void LoadClippingRegionToDC(HDC context, |
| 13 const SkMatrix& transformation, |
| 14 const SkIRect& clip_bounds) { |
| 15 HRGN hrgn = CreateRectRgnIndirect(&skia::SkIRectToRECT(clip_bounds)); |
| 16 int result = SelectClipRgn(context, hrgn); |
| 17 SkASSERT(result != ERROR); |
| 18 result = DeleteObject(hrgn); |
| 19 SkASSERT(result != 0); |
| 20 } |
| 21 |
| 22 // Old implementation restored the previously-selected bitmap |
| 23 // but it's not clear whether that is necessary. |
| 24 void FreeWindowsBacking(void* context) { |
| 25 if (!context) |
| 26 return; |
| 27 HBITMAP bitmap; |
| 28 bitmap = SelectObject(hbitmap, nullptr); |
| 29 DeleteObject(hbitmap); |
| 30 DeleteObject(context); |
| 31 } |
| 32 |
| 33 } // namespace |
| 34 |
| 35 namespace skia { |
| 36 |
| 37 LayerAllocator::LayerAllocator() { } |
| 38 |
| 39 LayerAllocator::~LayerAllocator() { } |
| 40 |
| 41 void* LayerAllocator::getNativeContext(void* buffer, |
| 42 const SkMatrix& transform, |
| 43 const SkIRect& clip_bounds) { |
| 44 if (!buffer) |
| 45 return nullptr; |
| 46 |
| 47 context_map_t::iterator it = contexts_.find(buffer); |
| 48 if (it == contexts_.end()) |
| 49 return nullptr; |
| 50 |
| 51 skia::LoadTransformToDC(it->second, transform); |
| 52 LoadClippingRegionToDC(it->second, transform, clip_bounds); |
| 53 |
| 54 // This is where we should flush the bitmap & mark it dirty, |
| 55 // but the old implementation didn't seem to do so. |
| 56 |
| 57 return it->second; |
| 58 } |
| 59 |
| 60 void* LayerAllocator::allocateLayer(const SkImageInfo& info, |
| 61 size_t* rowBytes, |
| 62 void (**deallocator)(void*), |
| 63 void** deallocatorPayload, |
| 64 void* initialData) { |
| 65 SkASSERT(info.colorType() == kN32_SkColorType); |
| 66 |
| 67 void* buffer = nullptr; |
| 68 HDC context = nullptr; |
| 69 |
| 70 /* |
| 71 cairo_surface_t* surface; |
| 72 if (initialData) |
| 73 surface = cairo_image_surface_create_for_data( |
| 74 (unsigned char*) initialData, |
| 75 CAIRO_FORMAT_ARGB32, |
| 76 info.width(), |
| 77 info.height(), |
| 78 cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, info.width())); |
| 79 else |
| 80 surface = cairo_image_surface_create( |
| 81 CAIRO_FORMAT_ARGB32, info.width(), info.height()); |
| 82 if (!surface) |
| 83 return nullptr; |
| 84 |
| 85 if (rowBytes) |
| 86 *rowBytes = cairo_image_surface_get_stride(surface); |
| 87 |
| 88 cairo_t* context = cairo_create(surface); |
| 89 if (!context) { |
| 90 cairo_surface_destroy(surface); |
| 91 return nullptr; |
| 92 } |
| 93 void* buffer = cairo_image_surface_get_data(surface); |
| 94 */ |
| 95 |
| 96 contexts_.insert({buffer, context}); |
| 97 |
| 98 *deallocator = FreeWindowsBacking; |
| 99 *deallocatorPayload = context; |
| 100 |
| 101 return buffer; |
| 102 } |
| 103 |
| 104 } // namespace skia |
| 105 |
OLD | NEW |