Skip to content

Commit

Permalink
keep only one typedef for the native drawing context
Browse files Browse the repository at this point in the history
This patch remove the NativeDrawingContext from ui/gfx/native_widget_types.h,
renames the PlatformSurface in skia/ext/platform_surface.h to NativeDrawingContext,
and updates the clients of gfx::NativeDrawingContext to the skia one.

BUG=76105
TEST=skia_unittests,printing_unittests
R=danakj@chromium.org,thestig@chromium.org,fmalita@chromium.org
TBR=sky@chromium.org

Review-Url: https://codereview.chromium.org/2400873002
Cr-Commit-Position: refs/heads/master@{#424585}
  • Loading branch information
tfarina authored and Commit bot committed Oct 11, 2016
1 parent 9236c35 commit 876d1e0
Show file tree
Hide file tree
Showing 39 changed files with 102 additions and 111 deletions.
2 changes: 1 addition & 1 deletion content/browser/compositor/software_output_device_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ void SoftwareOutputDeviceWin::EndPaint() {
SetWindowLong(hwnd_, GWL_EXSTYLE, style);

skia::ScopedPlatformPaint spp(contents_.get());
HDC dib_dc = spp.GetPlatformSurface();
HDC dib_dc = spp.GetNativeDrawingContext();
::UpdateLayeredWindow(hwnd_, NULL, &position, &size, dib_dc, &zero,
RGB(0xFF, 0xFF, 0xFF), &blend, ULW_ALPHA);
} else {
Expand Down
10 changes: 5 additions & 5 deletions printing/metafile.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "base/macros.h"
#include "build/build_config.h"
#include "printing/printing_export.h"
#include "ui/gfx/native_widget_types.h"
#include "skia/ext/native_drawing_context.h"

#if defined(OS_WIN)
#include <windows.h>
Expand Down Expand Up @@ -74,14 +74,14 @@ class PRINTING_EXPORT MetafilePlayer {
// back in the HDC. The trick is that it skip over the records known to have
// issue with some printers. See Emf::Record::SafePlayback implementation for
// details.
virtual bool SafePlayback(gfx::NativeDrawingContext hdc) const = 0;
virtual bool SafePlayback(skia::NativeDrawingContext hdc) const = 0;

#elif defined(OS_MACOSX)
// Renders the given page into |rect| in the given context.
// Pages use a 1-based index. The rendering uses the arguments in
// |params| to determine scaling, translation, and rotation.
virtual bool RenderPage(unsigned int page_number,
gfx::NativeDrawingContext context,
skia::NativeDrawingContext context,
const CGRect rect,
const MacRenderPageParams& params) const = 0;
#endif // if defined(OS_WIN)
Expand Down Expand Up @@ -144,7 +144,7 @@ class PRINTING_EXPORT Metafile : public MetafilePlayer {
virtual gfx::Rect GetPageBounds(unsigned int page_number) const = 0;
virtual unsigned int GetPageCount() const = 0;

virtual gfx::NativeDrawingContext context() const = 0;
virtual skia::NativeDrawingContext context() const = 0;

#if defined(OS_WIN)
// "Plays" the EMF buffer in a HDC. It is the same effect as calling the
Expand All @@ -155,7 +155,7 @@ class PRINTING_EXPORT Metafile : public MetafilePlayer {
// functions, whether used directly or indirectly through precompiled EMF
// data. We have to accept the risk here. Since it is used only for printing,
// it requires user intervention.
virtual bool Playback(gfx::NativeDrawingContext hdc,
virtual bool Playback(skia::NativeDrawingContext hdc,
const RECT* rect) const = 0;
#endif // OS_WIN

Expand Down
2 changes: 1 addition & 1 deletion printing/pdf_metafile_cg_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class PRINTING_EXPORT PdfMetafileCg : public Metafile {
CGContextRef context() const override;

bool RenderPage(unsigned int page_number,
gfx::NativeDrawingContext context,
skia::NativeDrawingContext context,
const CGRect rect,
const MacRenderPageParams& params) const override;

Expand Down
6 changes: 3 additions & 3 deletions printing/pdf_metafile_skia.cc
Original file line number Diff line number Diff line change
Expand Up @@ -228,20 +228,20 @@ unsigned int PdfMetafileSkia::GetPageCount() const {
return base::checked_cast<unsigned int>(data_->pages_.size());
}

gfx::NativeDrawingContext PdfMetafileSkia::context() const {
skia::NativeDrawingContext PdfMetafileSkia::context() const {
NOTREACHED();
return nullptr;
}


#if defined(OS_WIN)
bool PdfMetafileSkia::Playback(gfx::NativeDrawingContext hdc,
bool PdfMetafileSkia::Playback(skia::NativeDrawingContext hdc,
const RECT* rect) const {
NOTREACHED();
return false;
}

bool PdfMetafileSkia::SafePlayback(gfx::NativeDrawingContext hdc) const {
bool PdfMetafileSkia::SafePlayback(skia::NativeDrawingContext hdc) const {
NOTREACHED();
return false;
}
Expand Down
8 changes: 4 additions & 4 deletions printing/pdf_metafile_skia.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ class PRINTING_EXPORT PdfMetafileSkia : public Metafile {
gfx::Rect GetPageBounds(unsigned int page_number) const override;
unsigned int GetPageCount() const override;

gfx::NativeDrawingContext context() const override;
skia::NativeDrawingContext context() const override;

#if defined(OS_WIN)
bool Playback(gfx::NativeDrawingContext hdc,
bool Playback(skia::NativeDrawingContext hdc,
const RECT* rect) const override;
bool SafePlayback(gfx::NativeDrawingContext hdc) const override;
bool SafePlayback(skia::NativeDrawingContext hdc) const override;
#elif defined(OS_MACOSX)
bool RenderPage(unsigned int page_number,
gfx::NativeDrawingContext context,
skia::NativeDrawingContext context,
const CGRect rect,
const MacRenderPageParams& params) const override;
#endif
Expand Down
4 changes: 2 additions & 2 deletions printing/printed_document.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "base/strings/string16.h"
#include "base/synchronization/lock.h"
#include "printing/print_settings.h"
#include "ui/gfx/native_widget_types.h"
#include "skia/ext/native_drawing_context.h"

namespace base {
class RefCountedMemory;
Expand Down Expand Up @@ -63,7 +63,7 @@ class PRINTING_EXPORT PrintedDocument
// Note: locks for a short amount of time in debug only.
#if defined(OS_WIN) || defined(OS_MACOSX) && !defined(USE_AURA)
void RenderPrintedPage(const PrintedPage& page,
gfx::NativeDrawingContext context) const;
skia::NativeDrawingContext context) const;
#elif defined(OS_POSIX)
void RenderPrintedPage(const PrintedPage& page,
PrintingContext* context) const;
Expand Down
3 changes: 2 additions & 1 deletion printing/printed_document_mac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
namespace printing {

void PrintedDocument::RenderPrintedPage(
const PrintedPage& page, gfx::NativeDrawingContext context) const {
const PrintedPage& page,
skia::NativeDrawingContext context) const {
#ifndef NDEBUG
{
// Make sure the page is from our list.
Expand Down
3 changes: 2 additions & 1 deletion printing/printed_document_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ void SimpleModifyWorldTransform(HDC context,
namespace printing {

void PrintedDocument::RenderPrintedPage(
const PrintedPage& page, gfx::NativeDrawingContext context) const {
const PrintedPage& page,
skia::NativeDrawingContext context) const {
#ifndef NDEBUG
{
// Make sure the page is from our list.
Expand Down
3 changes: 2 additions & 1 deletion printing/printing_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "base/macros.h"
#include "base/strings/string16.h"
#include "printing/print_settings.h"
#include "skia/ext/native_drawing_context.h"
#include "ui/gfx/native_widget_types.h"

namespace base {
Expand Down Expand Up @@ -111,7 +112,7 @@ class PRINTING_EXPORT PrintingContext {
virtual void ReleaseContext() = 0;

// Returns the native context used to print.
virtual gfx::NativeDrawingContext context() const = 0;
virtual skia::NativeDrawingContext context() const = 0;

// Creates an instance of this object. Implementers of this interface should
// implement this method to create an object of their implementation.
Expand Down
2 changes: 1 addition & 1 deletion printing/printing_context_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ void PrintingContextAndroid::ReleaseContext() {
// Intentional No-op.
}

gfx::NativeDrawingContext PrintingContextAndroid::context() const {
skia::NativeDrawingContext PrintingContextAndroid::context() const {
// Intentional No-op.
return nullptr;
}
Expand Down
2 changes: 1 addition & 1 deletion printing/printing_context_android.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class PRINTING_EXPORT PrintingContextAndroid : public PrintingContext {
Result DocumentDone() override;
void Cancel() override;
void ReleaseContext() override;
gfx::NativeDrawingContext context() const override;
skia::NativeDrawingContext context() const override;

// Registers JNI bindings for RegisterContext.
static bool RegisterPrintingContext(JNIEnv* env);
Expand Down
2 changes: 1 addition & 1 deletion printing/printing_context_chromeos.cc
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ void PrintingContextChromeos::ReleaseContext() {
printer_.reset();
}

gfx::NativeDrawingContext PrintingContextChromeos::context() const {
skia::NativeDrawingContext PrintingContextChromeos::context() const {
// Intentional No-op.
return nullptr;
}
Expand Down
2 changes: 1 addition & 1 deletion printing/printing_context_chromeos.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class PRINTING_EXPORT PrintingContextChromeos : public PrintingContext {
Result DocumentDone() override;
void Cancel() override;
void ReleaseContext() override;
gfx::NativeDrawingContext context() const override;
skia::NativeDrawingContext context() const override;

Result StreamData(const std::vector<char>& buffer);

Expand Down
2 changes: 1 addition & 1 deletion printing/printing_context_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ void PrintingContextLinux::ReleaseContext() {
// Intentional No-op.
}

gfx::NativeDrawingContext PrintingContextLinux::context() const {
skia::NativeDrawingContext PrintingContextLinux::context() const {
// Intentional No-op.
return NULL;
}
Expand Down
2 changes: 1 addition & 1 deletion printing/printing_context_linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class PRINTING_EXPORT PrintingContextLinux : public PrintingContext {
Result DocumentDone() override;
void Cancel() override;
void ReleaseContext() override;
gfx::NativeDrawingContext context() const override;
skia::NativeDrawingContext context() const override;

private:
base::string16 document_name_;
Expand Down
2 changes: 1 addition & 1 deletion printing/printing_context_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class PRINTING_EXPORT PrintingContextMac : public PrintingContext {
Result DocumentDone() override;
void Cancel() override;
void ReleaseContext() override;
gfx::NativeDrawingContext context() const override;
skia::NativeDrawingContext context() const override;

private:
// Initializes PrintSettings from |print_info_|. This must be called
Expand Down
2 changes: 1 addition & 1 deletion printing/printing_context_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ PMPaper MatchPaper(CFArrayRef paper_list,
context_ = NULL;
}

gfx::NativeDrawingContext PrintingContextMac::context() const {
skia::NativeDrawingContext PrintingContextMac::context() const {
return context_;
}

Expand Down
2 changes: 1 addition & 1 deletion printing/printing_context_no_system_dialog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ void PrintingContextNoSystemDialog::ReleaseContext() {
// Intentional No-op.
}

gfx::NativeDrawingContext PrintingContextNoSystemDialog::context() const {
skia::NativeDrawingContext PrintingContextNoSystemDialog::context() const {
// Intentional No-op.
return nullptr;
}
Expand Down
2 changes: 1 addition & 1 deletion printing/printing_context_no_system_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class PRINTING_EXPORT PrintingContextNoSystemDialog : public PrintingContext {
Result DocumentDone() override;
void Cancel() override;
void ReleaseContext() override;
gfx::NativeDrawingContext context() const override;
skia::NativeDrawingContext context() const override;

private:
DISALLOW_COPY_AND_ASSIGN(PrintingContextNoSystemDialog);
Expand Down
2 changes: 1 addition & 1 deletion printing/printing_context_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ void PrintingContextWin::ReleaseContext() {
}
}

gfx::NativeDrawingContext PrintingContextWin::context() const {
skia::NativeDrawingContext PrintingContextWin::context() const {
return context_;
}

Expand Down
2 changes: 1 addition & 1 deletion printing/printing_context_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class PRINTING_EXPORT PrintingContextWin : public PrintingContext {
Result DocumentDone() override;
void Cancel() override;
void ReleaseContext() override;
gfx::NativeDrawingContext context() const override;
skia::NativeDrawingContext context() const override;

protected:
static HWND GetRootWindow(gfx::NativeView view);
Expand Down
4 changes: 2 additions & 2 deletions skia/ext/bitmap_platform_device_mac_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ TEST_F(BitmapPlatformDeviceMacTest, ClipRectTransformWithTranslate) {
canvas->setMatrix(transform);

ScopedPlatformPaint p(canvas.get());
CGContextRef context = p.GetPlatformSurface();
CGContextRef context = p.GetNativeDrawingContext();

SkRect clip_rect = skia::CGRectToSkRect(CGContextGetClipBoundingBox(context));
transform.mapRect(&clip_rect);
Expand All @@ -54,7 +54,7 @@ TEST_F(BitmapPlatformDeviceMacTest, ClipRectTransformWithScale) {
canvas->setMatrix(transform);

ScopedPlatformPaint p(canvas.get());
CGContextRef context = p.GetPlatformSurface();
CGContextRef context = p.GetNativeDrawingContext();

SkRect clip_rect = skia::CGRectToSkRect(CGContextGetClipBoundingBox(context));
transform.mapRect(&clip_rect);
Expand Down
5 changes: 3 additions & 2 deletions skia/ext/bitmap_platform_device_skia.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ SkBaseDevice* BitmapPlatformDevice::onCreateDevice(const CreateInfo& info,
info.fInfo.isOpaque());
}

PlatformSurface BitmapPlatformDevice::BeginPlatformPaint(const SkMatrix& transform,
const SkIRect& clip_bounds) {
NativeDrawingContext BitmapPlatformDevice::BeginPlatformPaint(
const SkMatrix& transform,
const SkIRect& clip_bounds) {
// TODO(zhenghao): What should we return? The ptr to the address of the
// pixels? Maybe this won't be called at all.
SkPixmap pixmap;
Expand Down
4 changes: 2 additions & 2 deletions skia/ext/bitmap_platform_device_skia.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class BitmapPlatformDevice : public SkBitmapDevice, public PlatformDevice {
SkBaseDevice* onCreateDevice(const CreateInfo&, const SkPaint*) override;

private:
PlatformSurface BeginPlatformPaint(const SkMatrix& transform,
const SkIRect& clip_bounds) override;
NativeDrawingContext BeginPlatformPaint(const SkMatrix& transform,
const SkIRect& clip_bounds) override;

DISALLOW_COPY_AND_ASSIGN(BitmapPlatformDevice);

Expand Down
2 changes: 1 addition & 1 deletion skia/ext/bitmap_platform_device_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void DrawToNativeContext(SkCanvas* canvas, HDC destination_hdc, int x, int y,
temp_rect.bottom = canvas->imageInfo().height();
src_rect = &temp_rect;
}
skia::CopyHDC(p.GetPlatformSurface(), destination_hdc, x, y,
skia::CopyHDC(p.GetNativeDrawingContext(), destination_hdc, x, y,
canvas->imageInfo().isOpaque(), *src_rect,
canvas->getTotalMatrix());
}
Expand Down
4 changes: 2 additions & 2 deletions skia/ext/bitmap_platform_device_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ class SK_API BitmapPlatformDevice : public SkBitmapDevice,
// PlatformDevice override
// Retrieves the bitmap DC, which is the memory DC for our bitmap data. The
// bitmap DC may be lazily created.
PlatformSurface BeginPlatformPaint(const SkMatrix& transform,
const SkIRect& clip_bounds) override;
NativeDrawingContext BeginPlatformPaint(const SkMatrix& transform,
const SkIRect& clip_bounds) override;

// Private constructor.
BitmapPlatformDevice(HBITMAP hbitmap, const SkBitmap& bitmap);
Expand Down
32 changes: 32 additions & 0 deletions skia/ext/native_drawing_context.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) 2015 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.

#ifndef SKIA_EXT_NATIVE_DRAWING_CONTEXT_H_
#define SKIA_EXT_NATIVE_DRAWING_CONTEXT_H_

#include "build/build_config.h"

#if defined(OS_WIN)
#include <windows.h>
#elif defined(USE_CAIRO)
typedef struct _cairo cairo_t;
#elif defined(OS_MACOSX)
typedef struct CGContext* CGContextRef;
#endif

namespace skia {

#if defined(OS_WIN)
typedef HDC NativeDrawingContext;
#elif defined(USE_CAIRO)
typedef cairo_t* NativeDrawingContext;
#elif defined(OS_MACOSX)
typedef CGContextRef NativeDrawingContext;
#else
typedef void* NativeDrawingContext;
#endif

} // namespace skia

#endif // SKIA_EXT_NATIVE_DRAWING_CONTEXT_H_
4 changes: 2 additions & 2 deletions skia/ext/platform_canvas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ CGContextRef GetBitmapContext(const SkCanvas& canvas) {

ScopedPlatformPaint::ScopedPlatformPaint(SkCanvas* canvas) :
canvas_(canvas),
platform_surface_(nullptr) {
native_drawing_context_(nullptr) {
// TODO(tomhudson) we're assuming non-null canvas?
PlatformDevice* platform_device = GetPlatformDevice(canvas->getTopDevice(true));
if (platform_device) {
// Compensate for drawing to a layer rather than the entire canvas
SkMatrix ctm;
SkIRect clip_bounds;
canvas->temporary_internal_describeTopLayer(&ctm, &clip_bounds);
platform_surface_ = platform_device->BeginPlatformPaint(ctm, clip_bounds);
native_drawing_context_ = platform_device->BeginPlatformPaint(ctm, clip_bounds);
}
}

Expand Down
Loading

0 comments on commit 876d1e0

Please sign in to comment.