Home | History | Annotate | Download | only in gm
      1 /*
      2  * Copyright 2017 Google Inc.
      3  *
      4  * Use of this source code is governed by a BSD-style license that can be
      5  * found in the LICENSE file.
      6  */
      7 
      8 #include "gm.h"
      9 #include "Resources.h"
     10 
     11 #if SK_SUPPORT_GPU
     12 #include "GrContext.h"
     13 #include "SkImage.h"
     14 
     15 DEF_SIMPLE_GM(cross_context_image, canvas, 512 + 512 + 30, 512 + 128 + 30) {
     16     GrContext* context = canvas->getGrContext();
     17     if (!context) {
     18         skiagm::GM::DrawGpuOnlyMessage(canvas);
     19         return;
     20     }
     21 
     22     sk_sp<SkData> encodedData = GetResourceAsData("mandrill_512.png");
     23 
     24     sk_sp<SkImage> encodedImage = SkImage::MakeFromEncoded(encodedData);
     25     canvas->drawImage(encodedImage, 10, 10);
     26 
     27     sk_sp<SkImage> crossContextImage = SkImage::MakeCrossContextFromEncoded(
     28         context, encodedData, false, canvas->imageInfo().colorSpace());
     29     canvas->drawImage(crossContextImage, 512 + 30, 10);
     30 
     31     SkIRect subset = SkIRect::MakeXYWH(256 - 64, 256 - 64, 128, 128);
     32     sk_sp<SkImage> encodedSubset = encodedImage->makeSubset(subset);
     33     sk_sp<SkImage> crossContextSubset = crossContextImage->makeSubset(subset);
     34 
     35     canvas->drawImage(encodedSubset, 10, 512 + 30);
     36     canvas->drawImage(crossContextSubset, 512 + 30, 512 + 30);
     37 }
     38 
     39 #endif
     40