diff options
author | caryclark@google.com <caryclark@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-10-16 12:31:48 +0000 |
---|---|---|
committer | caryclark@google.com <caryclark@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-10-16 12:31:48 +0000 |
commit | 90adecd850f1ae2beb7f66b6e7ddbf9cb16d67ac (patch) | |
tree | ef2290919a83404c3c881316f6a375d70da152ce | |
parent | c91dfe417a51f73c28ecf2708df1e0bee942c6ea (diff) |
pixman experiment work in progress
git-svn-id: http://skia.googlecode.com/svn/trunk@5960 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | experimental/pixman/Pixman-version.h | 50 | ||||
-rw-r--r-- | experimental/pixman/config.h | 3 | ||||
-rw-r--r-- | experimental/pixman/junk.cpp | 108 | ||||
-rw-r--r-- | experimental/pixman/pixman.mm | 99 |
4 files changed, 260 insertions, 0 deletions
diff --git a/experimental/pixman/Pixman-version.h b/experimental/pixman/Pixman-version.h new file mode 100644 index 0000000000..d4ea7c7f57 --- /dev/null +++ b/experimental/pixman/Pixman-version.h @@ -0,0 +1,50 @@ +/* + * Copyright © 2008 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * Author: Carl D. Worth <cworth@cworth.org> + */ + +#ifndef PIXMAN_VERSION_H__ +#define PIXMAN_VERSION_H__ + +#ifndef PIXMAN_H__ +# error pixman-version.h should only be included by pixman.h +#endif + +#define PIXMAN_VERSION_MAJOR 0 +#define PIXMAN_VERSION_MINOR 27 +#define PIXMAN_VERSION_MICRO 33 + +#define PIXMAN_VERSION_STRING "@PIXMAN_VERSION_MAJOR@.@PIXMAN_VERSION_MINOR@.@PIXMAN_VERSION_MICRO@" + +#define PIXMAN_VERSION_ENCODE(major, minor, micro) ( \ + ((major) * 10000) \ + + ((minor) * 100) \ + + ((micro) * 1)) + +#define PIXMAN_VERSION PIXMAN_VERSION_ENCODE( \ + PIXMAN_VERSION_MAJOR, \ + PIXMAN_VERSION_MINOR, \ + PIXMAN_VERSION_MICRO) + +#endif /* PIXMAN_VERSION_H__ */ diff --git a/experimental/pixman/config.h b/experimental/pixman/config.h new file mode 100644 index 0000000000..4546edc11c --- /dev/null +++ b/experimental/pixman/config.h @@ -0,0 +1,3 @@ +#define PACKAGE +#define HAVE_PTHREAD_SETSPECIFIC +#define PREFIX(a) a diff --git a/experimental/pixman/junk.cpp b/experimental/pixman/junk.cpp new file mode 100644 index 0000000000..6a93bbd16c --- /dev/null +++ b/experimental/pixman/junk.cpp @@ -0,0 +1,108 @@ + +extern "C" { +#include <stdio.h> +#include <stdlib.h> +#include <config.h> +#include "pixman-private.h" +#include "utils.h" +#include "gtk-utils.h" + +} + +#include "SkBitmap.h" +#include "SkCanvas.h" +#include "SkGraphics.h" +#include "SkPaint.h" +#import "SkWindow.h" + +bool DrawPixman(SkCanvas* canvas, int step, bool useOld); +SkCanvas* canvas; + +extern "C" { + +void* +pixbuf_from_argb32 (uint32_t *bits, + int width, + int height, + int stride) +{ + SkBitmap* bitmap = new SkBitmap; + bitmap->setConfig(SkBitmap::kARGB_8888_Config, width, height); + bitmap->allocPixels(); + + int p_stride = bitmap->rowBytes(); + uint32_t *p_bits = bitmap->getAddr32(0, 0); + int i; + + for (i = 0; i < height; ++i) + { + uint32_t *src_row = &bits[i * (stride / 4)]; + uint32_t *dst_row = p_bits + i * (p_stride / 4); + + a8r8g8b8_to_rgba_np (dst_row, src_row, width); + } + return (void*) bitmap; +} + + +void show_image (pixman_image_t *image) { + int width, height; + pixman_format_code_t format; + pixman_image_t *copy; + + width = pixman_image_get_width (image); + height = pixman_image_get_height (image); + + + format = pixman_image_get_format (image); + + /* Three cases: + * + * - image is a8r8g8b8_sRGB: we will display without modification + * under the assumption that the monitor is sRGB + * + * - image is a8r8g8b8: we will display without modification + * under the assumption that whoever created the image + * probably did it wrong by using sRGB inputs + * + * - other: we will convert to a8r8g8b8 under the assumption that + * whoever created the image probably did it wrong. + */ + switch (format) + { + case PIXMAN_a8r8g8b8_sRGB: + case PIXMAN_a8r8g8b8: + copy = pixman_image_ref (image); + break; + + default: + copy = pixman_image_create_bits (PIXMAN_a8r8g8b8, + width, height, NULL, -1); + pixman_image_composite32 (PIXMAN_OP_SRC, + image, NULL, copy, + 0, 0, 0, 0, 0, 0, + width, height); + break; + } + + SkBitmap* bitmap = (SkBitmap*) pixbuf_from_argb32 (pixman_image_get_data (copy), + width, height, + pixman_image_get_stride (copy)); + canvas->drawBitmap(*bitmap, 0, 0); + delete bitmap; +} + +} + +bool DrawPixman(SkCanvas* c, int step, bool usePixman) { + canvas = c; + switch(step) { + case 0: + checkerboard_main(0, NULL); + break; + default: + alpha_main(0, NULL); + break; + } + return true; +} diff --git a/experimental/pixman/pixman.mm b/experimental/pixman/pixman.mm new file mode 100644 index 0000000000..f4db3df7b2 --- /dev/null +++ b/experimental/pixman/pixman.mm @@ -0,0 +1,99 @@ + +#import "SkCanvas.h" +#import "SkWindow.h" +#include "SkGraphics.h" +#include "SkCGUtils.h" + +#include <time.h> +#include <sys/time.h> + +bool DrawPixman(SkCanvas* canvas, int step, bool usePixman); + +class SkPixmanView : public SkView { +public: + SkPixmanView() { + this->setVisibleP(true); + this->setClipToBounds(false); + usePixman = true; + slide = 0; + step = -1; + }; +protected: + virtual void onDraw(SkCanvas* canvas) { + static int step = 0; // 12752; // 17908 ; // 17904; // drawLetters first error + // drawStars triggers error at 23275 + // error is not easy to debug in its current state + static double seconds; + if (step == -1) { + timeval t; + gettimeofday(&t, NULL); + seconds = t.tv_sec+t.tv_usec/1000000.0; + step = 0; + } + canvas->drawColor(SK_ColorWHITE); + if (DrawPixman(canvas, slide, usePixman)) { + if (step == 100) { + timeval t; + gettimeofday(&t, NULL); + double last = seconds; + seconds = t.tv_sec+t.tv_usec/1000000.0; + SkDebugf("usePixman=%d seconds=%g\n", usePixman, seconds - last); + step = 0; + } + inval(NULL); + } + } + + virtual Click* onFindClickHandler(SkScalar , SkScalar ) { + // usePixman ^= true; + ++slide; + return NULL; + } + +private: + bool usePixman; + int slide; + int step; + typedef SkView INHERITED; +}; + +void application_init(); +void application_term(); + +void application_init() { + SkGraphics::Init(); + SkEvent::Init(); +} + +void application_term() { + SkGraphics::Term(); + SkEvent::Term(); +} + +class FillLayout : public SkView::Layout { +protected: + virtual void onLayoutChildren(SkView* parent) { + SkView* view = SkView::F2BIter(parent).next(); + view->setSize(parent->width(), parent->height()); + } +}; + +#import "SimpleApp.h" + +@implementation SimpleNSView + +- (id)initWithDefaults { + if ((self = [super initWithDefaults])) { + fWind = new SkOSWindow(self); + fWind->setLayout(new FillLayout, false); + fWind->attachChildToFront(new SkPixmanView)->unref(); + } + return self; +} + +- (void)drawRect:(NSRect)dirtyRect { + CGContextRef ctx = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort]; + SkCGDrawBitmap(ctx, fWind->getBitmap(), 0, 0); +} + +@end |