summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa/cocoa_utils.mm
blob: 9c7584d187bcff4d24153465a63c7811c47e2165 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <base/logging.h>
#include "chrome/browser/cocoa/cocoa_utils.h"
#import <QuartzCore/CIImage.h>
#include "third_party/skia/include/utils/mac/SkCGUtils.h"
#include "third_party/skia/include/core/SkColorPriv.h"

namespace {

// Callback passed to CGDataProviderCreateWithData()
void ReleaseData(void* info, const void* pixelData, size_t size) {
  // info is a non-const pixelData
  if (info)
    free(info);
}

}

namespace CocoaUtils {

NSImage* SkBitmapToNSImage(const SkBitmap& skiaBitmap) {
  // First convert SkBitmap to CGImageRef.
  CGImageRef cgimage = SkCreateCGImageRef(skiaBitmap);

  // Now convert to NSImage.
  NSBitmapImageRep* bitmap = [[[NSBitmapImageRep alloc]
                                   initWithCGImage:cgimage] autorelease];
  CFRelease(cgimage);
  NSImage* image = [[[NSImage alloc] init] autorelease];
  [image addRepresentation:bitmap];
  return image;
}

}  // namespace CocoaUtils