Hello noel,

I'd like you to do a code review.  Please execute
        g4 diff -c 12969673

or point your web browser to
        http://mondrian/12969673

to review the following code:

Change 12969673 by nigel...@nigeltao-srcgears1 on 2009/10/01 16:41:09 *pending*

        Introduce rotateCW, rotate180, and rotateCCW methods on the Gears
        Canvas.
        
        PRESUBMIT=passed
        R=noel
        [email protected]
        DELTA=62  (62 added, 0 deleted, 0 changed)
        OCL=12969673

Affected files ...

... //depot/googleclient/gears/opensource/gears/canvas/canvas.cc#35 edit
... //depot/googleclient/gears/opensource/gears/canvas/canvas.h#27 edit

62 delta lines: 62 added, 0 deleted, 0 changed

Also consider running:
        g4 lint -c 12969673

which verifies that the changelist doesn't introduce new style violations.

If you can't do the review, please let me know as soon as possible.  During
your review, please ensure that all new code has corresponding unit tests and
that existing unit tests are updated appropriately.  Visit
http://www/eng/code_review.html for more information.

This is a semiautomated message from "g4 mail".  Complaints or suggestions?
Mail [email protected].
Change 12969673 by nigel...@nigeltao-srcgears1 on 2009/10/01 16:41:09 *pending*

        Introduce rotateCW, rotate180, and rotateCCW methods on the Gears
        Canvas.

Affected files ...

... //depot/googleclient/gears/opensource/gears/canvas/canvas.cc#35 edit
... //depot/googleclient/gears/opensource/gears/canvas/canvas.h#27 edit

==== //depot/googleclient/gears/opensource/gears/canvas/canvas.cc#35 - 
/home/nigeltao/srcgears1/googleclient/gears/opensource/gears/canvas/canvas.cc 
====
# action=edit type=text
--- googleclient/gears/opensource/gears/canvas/canvas.cc        2009-10-01 
16:36:13.000000000 +1000
+++ googleclient/gears/opensource/gears/canvas/canvas.cc        2009-10-01 
16:40:35.000000000 +1000
@@ -143,6 +143,9 @@
   RegisterMethod("decode", &GearsCanvas::Decode);
   RegisterMethod("encode", &GearsCanvas::Encode);
   RegisterMethod("resize", &GearsCanvas::Resize);
+  RegisterMethod("rotateCW", &GearsCanvas::RotateCW);
+  RegisterMethod("rotate180", &GearsCanvas::Rotate180);
+  RegisterMethod("rotateCCW", &GearsCanvas::RotateCCW);
   RegisterProperty("height", &GearsCanvas::GetHeight, &GearsCanvas::SetHeight);
   RegisterProperty("width", &GearsCanvas::GetWidth, &GearsCanvas::SetWidth);
 #if defined(OFFICIAL_BUILD)
@@ -589,6 +592,46 @@
   new_bitmap.swap(*skia_bitmap_);
 }
 
+void GearsCanvas::RotateCW(JsCallContext *context) {
+  Rotate(1);
+}
+
+void GearsCanvas::Rotate180(JsCallContext *context) {
+  Rotate(2);
+}
+
+void GearsCanvas::RotateCCW(JsCallContext *context) {
+  Rotate(3);
+}
+
+void GearsCanvas::Rotate(int clockwiseTurns) {
+  int new_width = clockwiseTurns == 2 ? GetWidth() : GetHeight();
+  int new_height = clockwiseTurns == 2 ? GetHeight() : GetWidth();
+
+  EnsureBitmapPixelsAreAllocated();
+  SkBitmap new_bitmap;
+  new_bitmap.setConfig(skia_config, new_width, new_height);
+  new_bitmap.allocPixels();
+  new_bitmap.eraseARGB(0, 0, 0, 0);
+
+  SkCanvas new_canvas(new_bitmap);
+  switch (clockwiseTurns) {
+    case 1:
+      new_canvas.rotate(SkIntToScalar(90));
+      new_canvas.drawBitmap(*skia_bitmap_, SkIntToScalar(0), 
SkIntToScalar(-new_width));
+      break;
+    case 2:
+      new_canvas.rotate(SkIntToScalar(180));
+      new_canvas.drawBitmap(*skia_bitmap_, SkIntToScalar(-new_width), 
SkIntToScalar(-new_height));
+      break;
+    case 3:
+      new_canvas.rotate(SkIntToScalar(270));
+      new_canvas.drawBitmap(*skia_bitmap_, SkIntToScalar(-new_height), 
SkIntToScalar(0));
+      break;
+  }
+  new_bitmap.swap(*skia_bitmap_);
+}
+
 void GearsCanvas::GetWidth(JsCallContext *context) {
   int its_width = GetWidth();
   context->SetReturnValue(JSPARAM_INT, &its_width);
==== //depot/googleclient/gears/opensource/gears/canvas/canvas.h#27 - 
/home/nigeltao/srcgears1/googleclient/gears/opensource/gears/canvas/canvas.h 
====
# action=edit type=text
--- googleclient/gears/opensource/gears/canvas/canvas.h 2009-10-01 
16:36:14.000000000 +1000
+++ googleclient/gears/opensource/gears/canvas/canvas.h 2009-10-01 
16:40:25.000000000 +1000
@@ -90,6 +90,21 @@
   // OUT: -
   void Resize(JsCallContext *context);
 
+  // Rotates the canvas by 90 degrees clockwise, in-place.
+  // IN: -
+  // OUT: -
+  void RotateCW(JsCallContext *context);
+
+  // Rotates the canvas by 180 degrees, in-place.
+  // IN: -
+  // OUT: -
+  void Rotate180(JsCallContext *context);
+
+  // Rotates the canvas by 90 degrees counter-clockwise, in-place.
+  // IN: -
+  // OUT: -
+  void RotateCCW(JsCallContext *context);
+
   // Accessors for the state of the canvas. Setting any of these causes the
   // canvas to be reset to transparent black, and invalidates any contexts.
   void GetWidth(JsCallContext *context);
@@ -137,6 +152,10 @@
   // requires this when the user sets the canvas's width or height.
   void ResetCanvas(int width, int height);
 
+  // Rotates the Canvas, in-place, by the specified number of 90-degree
+  // clockwise turns.
+  void Rotate(int clockwiseTurns);
+
   // We lazily allocate the SkBitmap's pixels. This method ensures that those
   // pixels have been allocated.
   void EnsureBitmapPixelsAreAllocated();

Reply via email to