Home | History | Annotate | Download | only in tests
      1 
      2 /*
      3  * Copyright 2012 Google Inc.
      4  *
      5  * Use of this source code is governed by a BSD-style license that can be
      6  * found in the LICENSE file.
      7  */
      8 
      9 #include "SamplePipeControllers.h"
     10 #include "SkBitmap.h"
     11 #include "SkCanvas.h"
     12 #include "SkGPipe.h"
     13 #include "SkPaint.h"
     14 #include "SkShader.h"
     15 #include "Test.h"
     16 
     17 // Ensures that the pipe gracefully handles drawing an invalid bitmap.
     18 static void testDrawingBadBitmap(SkCanvas* pipeCanvas) {
     19     SkBitmap badBitmap;
     20     badBitmap.setConfig(SkBitmap::kNo_Config, 5, 5);
     21     pipeCanvas->drawBitmap(badBitmap, 0, 0);
     22 }
     23 
     24 // Ensure that pipe gracefully handles attempting to draw after endRecording is called on the
     25 // SkGPipeWriter.
     26 static void testDrawingAfterEndRecording(SkCanvas* canvas) {
     27     PipeController pc(canvas);
     28     SkGPipeWriter writer;
     29     SkCanvas* pipeCanvas = writer.startRecording(&pc, SkGPipeWriter::kCrossProcess_Flag);
     30     writer.endRecording();
     31 
     32     SkBitmap bm;
     33     bm.setConfig(SkBitmap::kARGB_8888_Config, 2, 2);
     34     bm.allocPixels();
     35     bm.eraseColor(SK_ColorTRANSPARENT);
     36 
     37     SkShader* shader = SkShader::CreateBitmapShader(bm, SkShader::kClamp_TileMode,
     38                                                     SkShader::kClamp_TileMode);
     39     SkPaint paint;
     40     paint.setShader(shader)->unref();
     41     pipeCanvas->drawPaint(paint);
     42 
     43     pipeCanvas->drawBitmap(bm, 0, 0);
     44 }
     45 
     46 static void test_pipeTests(skiatest::Reporter*) {
     47     SkBitmap bitmap;
     48     bitmap.setConfig(SkBitmap::kARGB_8888_Config, 64, 64);
     49     SkCanvas canvas(bitmap);
     50 
     51     PipeController pipeController(&canvas);
     52     SkGPipeWriter writer;
     53     SkCanvas* pipeCanvas = writer.startRecording(&pipeController);
     54     testDrawingBadBitmap(pipeCanvas);
     55     writer.endRecording();
     56 
     57     testDrawingAfterEndRecording(&canvas);
     58 }
     59 
     60 #include "TestClassDef.h"
     61 DEFINE_TESTCLASS("PipeTest", PipeTestClass, test_pipeTests)
     62