Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(235)

Side by Side Diff: skia/ext/vector_platform_device_win.cc

Issue 259047: Move classes depending on Skia out of base/gfx and into app/gfx. Rename... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « skia/ext/vector_canvas_unittest.cc ('k') | views/controls/combobox/native_combobox_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <windows.h> 5 #include <windows.h>
6 6
7 #include "skia/ext/vector_platform_device_win.h" 7 #include "skia/ext/vector_platform_device_win.h"
8 8
9 #include "base/gfx/gdi_util.h"
10 #include "skia/ext/skia_utils_win.h" 9 #include "skia/ext/skia_utils_win.h"
11 #include "third_party/skia/include/core/SkUtils.h" 10 #include "third_party/skia/include/core/SkUtils.h"
12 11
13 namespace skia { 12 namespace skia {
14 13
14 static void FillBitmapInfoHeader(int width, int height, BITMAPINFOHEADER* hdr) {
15 hdr->biSize = sizeof(BITMAPINFOHEADER);
16 hdr->biWidth = width;
17 hdr->biHeight = -height; // Minus means top-down bitmap.
18 hdr->biPlanes = 1;
19 hdr->biBitCount = 32;
20 hdr->biCompression = BI_RGB; // no compression
21 hdr->biSizeImage = 0;
22 hdr->biXPelsPerMeter = 1;
23 hdr->biYPelsPerMeter = 1;
24 hdr->biClrUsed = 0;
25 hdr->biClrImportant = 0;
26 }
27
15 VectorPlatformDevice* VectorPlatformDevice::create(HDC dc, 28 VectorPlatformDevice* VectorPlatformDevice::create(HDC dc,
16 int width, int height) { 29 int width, int height) {
17 InitializeDC(dc); 30 InitializeDC(dc);
18 31
19 // Link the SkBitmap to the current selected bitmap in the device context. 32 // Link the SkBitmap to the current selected bitmap in the device context.
20 SkBitmap bitmap; 33 SkBitmap bitmap;
21 HGDIOBJ selected_bitmap = GetCurrentObject(dc, OBJ_BITMAP); 34 HGDIOBJ selected_bitmap = GetCurrentObject(dc, OBJ_BITMAP);
22 bool succeeded = false; 35 bool succeeded = false;
23 if (selected_bitmap != NULL) { 36 if (selected_bitmap != NULL) {
24 BITMAP bitmap_data; 37 BITMAP bitmap_data;
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 } else { 568 } else {
556 if (!ApplyPaint(paint)) 569 if (!ApplyPaint(paint))
557 return; 570 return;
558 is_translucent = false; 571 is_translucent = false;
559 } 572 }
560 int src_size_x = bitmap.width(); 573 int src_size_x = bitmap.width();
561 int src_size_y = bitmap.height(); 574 int src_size_y = bitmap.height();
562 if (!src_size_x || !src_size_y) 575 if (!src_size_x || !src_size_y)
563 return; 576 return;
564 577
565 // Create a BMP v4 header that we can serialize. 578 // Create a BMP v4 header that we can serialize. We use the shared "V3"
579 // fillter to fill the stardard items, then add in the "V4" stuff we want.
566 BITMAPV4HEADER bitmap_header; 580 BITMAPV4HEADER bitmap_header;
567 gfx::CreateBitmapV4Header(src_size_x, src_size_y, &bitmap_header); 581 memset(&bitmap_header, 0, sizeof(BITMAPV4HEADER));
582 FillBitmapInfoHeader(src_size_x, src_size_y,
583 reinterpret_cast<BITMAPINFOHEADER*>(&bitmap_header));
584 bitmap_header.bV4Size = sizeof(BITMAPV4HEADER);
585 bitmap_header.bV4RedMask = 0x00ff0000;
586 bitmap_header.bV4GreenMask = 0x0000ff00;
587 bitmap_header.bV4BlueMask = 0x000000ff;
588 bitmap_header.bV4AlphaMask = 0xff000000;
589
568 HDC dc = getBitmapDC(); 590 HDC dc = getBitmapDC();
569 SkAutoLockPixels lock(bitmap); 591 SkAutoLockPixels lock(bitmap);
570 SkASSERT(bitmap.getConfig() == SkBitmap::kARGB_8888_Config); 592 SkASSERT(bitmap.getConfig() == SkBitmap::kARGB_8888_Config);
571 const uint32_t* pixels = static_cast<const uint32_t*>(bitmap.getPixels()); 593 const uint32_t* pixels = static_cast<const uint32_t*>(bitmap.getPixels());
572 if (pixels == NULL) { 594 if (pixels == NULL) {
573 SkASSERT(false); 595 SkASSERT(false);
574 return; 596 return;
575 } 597 }
576 598
577 if (!is_translucent) { 599 if (!is_translucent) {
578 int row_length = bitmap.rowBytesAsPixels(); 600 int row_length = bitmap.rowBytesAsPixels();
579 // There is no quick way to determine if an image is opaque. 601 // There is no quick way to determine if an image is opaque.
580 for (int y2 = 0; y2 < src_size_y; ++y2) { 602 for (int y2 = 0; y2 < src_size_y; ++y2) {
581 for (int x2 = 0; x2 < src_size_x; ++x2) { 603 for (int x2 = 0; x2 < src_size_x; ++x2) {
582 if (SkColorGetA(pixels[(y2 * row_length) + x2]) != 255) { 604 if (SkColorGetA(pixels[(y2 * row_length) + x2]) != 255) {
583 is_translucent = true; 605 is_translucent = true;
584 y2 = src_size_y; 606 y2 = src_size_y;
585 break; 607 break;
586 } 608 }
587 } 609 }
588 } 610 }
589 } 611 }
590 612
591 BITMAPINFOHEADER hdr; 613 BITMAPINFOHEADER hdr;
592 gfx::CreateBitmapHeader(src_size_x, src_size_y, &hdr); 614 FillBitmapInfoHeader(src_size_x, src_size_y, &hdr);
593 if (is_translucent) { 615 if (is_translucent) {
594 // The image must be loaded as a bitmap inside a device context. 616 // The image must be loaded as a bitmap inside a device context.
595 HDC bitmap_dc = ::CreateCompatibleDC(dc); 617 HDC bitmap_dc = ::CreateCompatibleDC(dc);
596 void* bits = NULL; 618 void* bits = NULL;
597 HBITMAP hbitmap = ::CreateDIBSection( 619 HBITMAP hbitmap = ::CreateDIBSection(
598 bitmap_dc, reinterpret_cast<const BITMAPINFO*>(&hdr), 620 bitmap_dc, reinterpret_cast<const BITMAPINFO*>(&hdr),
599 DIB_RGB_COLORS, &bits, NULL, 0); 621 DIB_RGB_COLORS, &bits, NULL, 0);
600 memcpy(bits, pixels, bitmap.getSize()); 622 memcpy(bits, pixels, bitmap.getSize());
601 SkASSERT(hbitmap); 623 SkASSERT(hbitmap);
602 HGDIOBJ old_bitmap = ::SelectObject(bitmap_dc, hbitmap); 624 HGDIOBJ old_bitmap = ::SelectObject(bitmap_dc, hbitmap);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 reinterpret_cast<const BITMAPINFO*>(&hdr), 658 reinterpret_cast<const BITMAPINFO*>(&hdr),
637 DIB_RGB_COLORS, 659 DIB_RGB_COLORS,
638 SRCCOPY); 660 SRCCOPY);
639 SkASSERT(result); 661 SkASSERT(result);
640 } 662 }
641 Cleanup(); 663 Cleanup();
642 } 664 }
643 665
644 } // namespace skia 666 } // namespace skia
645 667
OLDNEW
« no previous file with comments | « skia/ext/vector_canvas_unittest.cc ('k') | views/controls/combobox/native_combobox_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698