OSDN Git Service

2c5ef098cbc6c1eaac879faaacd49cc5043e6f51
[android-x86/external-drm_hwcomposer.git] / drmdisplaycomposition.cpp
1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #define LOG_TAG "hwc-drm-display-composition"
18
19 #include "drmdisplaycomposition.h"
20 #include "drmcrtc.h"
21 #include "drmplane.h"
22 #include "drmresources.h"
23
24 #include <stdlib.h>
25
26 #include <algorithm>
27 #include <unordered_set>
28
29 #include <cutils/log.h>
30 #include <sw_sync.h>
31 #include <sync/sync.h>
32 #include <xf86drmMode.h>
33
34 namespace android {
35
36 const size_t DrmCompositionPlane::kSourceNone;
37 const size_t DrmCompositionPlane::kSourcePreComp;
38 const size_t DrmCompositionPlane::kSourceSquash;
39 const size_t DrmCompositionPlane::kSourceLayerMax;
40
41 DrmDisplayComposition::~DrmDisplayComposition() {
42   if (timeline_fd_ >= 0) {
43     SignalCompositionDone();
44     close(timeline_fd_);
45   }
46 }
47
48 int DrmDisplayComposition::Init(DrmResources *drm, DrmCrtc *crtc,
49                                 Importer *importer, uint64_t frame_no) {
50   drm_ = drm;
51   crtc_ = crtc;  // Can be NULL if we haven't modeset yet
52   importer_ = importer;
53   frame_no_ = frame_no;
54
55   int ret = sw_sync_timeline_create();
56   if (ret < 0) {
57     ALOGE("Failed to create sw sync timeline %d", ret);
58     return ret;
59   }
60   timeline_fd_ = ret;
61   return 0;
62 }
63
64 bool DrmDisplayComposition::validate_composition_type(DrmCompositionType des) {
65   return type_ == DRM_COMPOSITION_TYPE_EMPTY || type_ == des;
66 }
67
68 int DrmDisplayComposition::CreateNextTimelineFence() {
69   ++timeline_;
70   return sw_sync_fence_create(timeline_fd_, "hwc drm display composition fence",
71                               timeline_);
72 }
73
74 int DrmDisplayComposition::IncreaseTimelineToPoint(int point) {
75   int timeline_increase = point - timeline_current_;
76   if (timeline_increase <= 0)
77     return 0;
78
79   int ret = sw_sync_timeline_inc(timeline_fd_, timeline_increase);
80   if (ret)
81     ALOGE("Failed to increment sync timeline %d", ret);
82   else
83     timeline_current_ = point;
84
85   return ret;
86 }
87
88 int DrmDisplayComposition::SetLayers(DrmHwcLayer *layers, size_t num_layers,
89                                      bool geometry_changed) {
90   if (!validate_composition_type(DRM_COMPOSITION_TYPE_FRAME))
91     return -EINVAL;
92
93   geometry_changed_ = geometry_changed;
94
95   for (size_t layer_index = 0; layer_index < num_layers; layer_index++) {
96     layers_.emplace_back(std::move(layers[layer_index]));
97   }
98
99   type_ = DRM_COMPOSITION_TYPE_FRAME;
100   return 0;
101 }
102
103 int DrmDisplayComposition::SetDpmsMode(uint32_t dpms_mode) {
104   if (!validate_composition_type(DRM_COMPOSITION_TYPE_DPMS))
105     return -EINVAL;
106   dpms_mode_ = dpms_mode;
107   type_ = DRM_COMPOSITION_TYPE_DPMS;
108   return 0;
109 }
110
111 int DrmDisplayComposition::SetDisplayMode(const DrmMode &display_mode) {
112   if (!validate_composition_type(DRM_COMPOSITION_TYPE_MODESET))
113     return -EINVAL;
114   display_mode_ = display_mode;
115   dpms_mode_ = DRM_MODE_DPMS_ON;
116   type_ = DRM_COMPOSITION_TYPE_MODESET;
117   return 0;
118 }
119
120 int DrmDisplayComposition::AddPlaneDisable(DrmPlane *plane) {
121   composition_planes_.emplace_back(
122       DrmCompositionPlane{plane, crtc_, DrmCompositionPlane::kSourceNone});
123   return 0;
124 }
125
126 static size_t CountUsablePlanes(DrmCrtc *crtc,
127                                 std::vector<DrmPlane *> *primary_planes,
128                                 std::vector<DrmPlane *> *overlay_planes) {
129   return std::count_if(
130              primary_planes->begin(), primary_planes->end(),
131              [=](DrmPlane *plane) { return plane->GetCrtcSupported(*crtc); }) +
132          std::count_if(
133              overlay_planes->begin(), overlay_planes->end(),
134              [=](DrmPlane *plane) { return plane->GetCrtcSupported(*crtc); });
135 }
136
137 static DrmPlane *TakePlane(DrmCrtc *crtc, std::vector<DrmPlane *> *planes) {
138   for (auto iter = planes->begin(); iter != planes->end(); ++iter) {
139     if ((*iter)->GetCrtcSupported(*crtc)) {
140       DrmPlane *plane = *iter;
141       planes->erase(iter);
142       return plane;
143     }
144   }
145   return NULL;
146 }
147
148 static DrmPlane *TakePlane(DrmCrtc *crtc,
149                            std::vector<DrmPlane *> *primary_planes,
150                            std::vector<DrmPlane *> *overlay_planes) {
151   DrmPlane *plane = TakePlane(crtc, primary_planes);
152   if (plane)
153     return plane;
154   return TakePlane(crtc, overlay_planes);
155 }
156
157 void DrmDisplayComposition::EmplaceCompositionPlane(
158     size_t source_layer, std::vector<DrmPlane *> *primary_planes,
159     std::vector<DrmPlane *> *overlay_planes) {
160   DrmPlane *plane = TakePlane(crtc_, primary_planes, overlay_planes);
161   if (plane == NULL) {
162     ALOGE(
163         "Failed to add composition plane because there are no planes "
164         "remaining");
165     return;
166   }
167   composition_planes_.emplace_back(
168       DrmCompositionPlane{plane, crtc_, source_layer});
169 }
170
171 static std::vector<size_t> SetBitsToVector(uint64_t in, size_t *index_map) {
172   std::vector<size_t> out;
173   size_t msb = sizeof(in) * 8 - 1;
174   uint64_t mask = (uint64_t)1 << msb;
175   for (size_t i = msb; mask != (uint64_t)0; i--, mask >>= 1)
176     if (in & mask)
177       out.push_back(index_map[i]);
178   return out;
179 }
180
181 static void SeparateLayers(DrmHwcLayer *layers, size_t *used_layers,
182                            size_t num_used_layers,
183                            size_t *protected_layers,
184                            size_t num_protected_layers,
185                            DrmHwcRect<int> *exclude_rects,
186                            size_t num_exclude_rects,
187                            std::vector<DrmCompositionRegion> &regions) {
188   if (num_used_layers > 64) {
189     ALOGE("Failed to separate layers because there are more than 64");
190     return;
191   }
192
193   // Index at which the actual layers begin
194   size_t layer_offset = num_exclude_rects + num_protected_layers;
195
196   if (num_used_layers + layer_offset > 64) {
197     ALOGW(
198         "Exclusion rectangles are being truncated to make the rectangle count "
199         "fit into 64");
200     num_exclude_rects = 64 - num_used_layers - num_protected_layers;
201   }
202
203   // We inject all the exclude rects into the rects list. Any resulting rect
204   // that includes ANY of the first num_exclude_rects is rejected. After the
205   // exclude rects, we add the protected layers. The rects that intersect with
206   // the protected layer will be inspected and only those which are above the
207   // protected layer will be included in the composition regions.
208   std::vector<DrmHwcRect<int>> layer_rects(num_used_layers + layer_offset);
209   std::copy(exclude_rects, exclude_rects + num_exclude_rects,
210             layer_rects.begin());
211   std::transform(
212       protected_layers, protected_layers + num_protected_layers,
213       layer_rects.begin() + num_exclude_rects,
214       [=](size_t layer_index) { return layers[layer_index].display_frame; });
215   std::transform(
216       used_layers, used_layers + num_used_layers,
217       layer_rects.begin() + layer_offset,
218       [=](size_t layer_index) { return layers[layer_index].display_frame; });
219
220   std::vector<separate_rects::RectSet<uint64_t, int>> separate_regions;
221   separate_rects::separate_rects_64(layer_rects, &separate_regions);
222   uint64_t exclude_mask = ((uint64_t)1 << num_exclude_rects) - 1;
223   uint64_t protected_mask = (((uint64_t)1 << num_protected_layers) - 1) <<
224                             num_exclude_rects;
225
226   for (separate_rects::RectSet<uint64_t, int> &region : separate_regions) {
227     if (region.id_set.getBits() & exclude_mask)
228       continue;
229
230     // If a rect intersects a protected layer, we need to remove the layers
231     // from the composition region which appear *below* the protected layer.
232     // This effectively punches a hole through the composition layer such
233     // that the protected layer can be placed below the composition and not
234     // be occluded by things like the background.
235     uint64_t protected_intersect = region.id_set.getBits() & protected_mask;
236     for (size_t i = 0; protected_intersect && i < num_protected_layers; ++i) {
237       // Only exclude layers if they intersect this particular protected layer
238       if (!(protected_intersect & (1 << (i + num_exclude_rects))))
239         continue;
240
241       for (size_t j = 0; j < num_used_layers; ++j) {
242         if (used_layers[j] < protected_layers[i])
243           region.id_set.subtract(j + layer_offset);
244       }
245     }
246     if (!(region.id_set.getBits() >> layer_offset))
247       continue;
248
249     regions.emplace_back(DrmCompositionRegion{
250         region.rect,
251         SetBitsToVector(region.id_set.getBits() >> layer_offset, used_layers)});
252   }
253 }
254
255 int DrmDisplayComposition::CreateAndAssignReleaseFences() {
256   std::unordered_set<DrmHwcLayer *> squash_layers;
257   std::unordered_set<DrmHwcLayer *> pre_comp_layers;
258   std::unordered_set<DrmHwcLayer *> comp_layers;
259
260   for (const DrmCompositionRegion &region : squash_regions_) {
261     for (size_t source_layer_index : region.source_layers) {
262       DrmHwcLayer *source_layer = &layers_[source_layer_index];
263       squash_layers.emplace(source_layer);
264     }
265   }
266
267   for (const DrmCompositionRegion &region : pre_comp_regions_) {
268     for (size_t source_layer_index : region.source_layers) {
269       DrmHwcLayer *source_layer = &layers_[source_layer_index];
270       pre_comp_layers.emplace(source_layer);
271       squash_layers.erase(source_layer);
272     }
273   }
274
275   for (const DrmCompositionPlane &plane : composition_planes_) {
276     if (plane.source_layer <= DrmCompositionPlane::kSourceLayerMax) {
277       DrmHwcLayer *source_layer = &layers_[plane.source_layer];
278       comp_layers.emplace(source_layer);
279       pre_comp_layers.erase(source_layer);
280     }
281   }
282
283   for (DrmHwcLayer *layer : squash_layers) {
284     if (!layer->release_fence)
285       continue;
286     int ret = layer->release_fence.Set(CreateNextTimelineFence());
287     if (ret < 0)
288       return ret;
289   }
290   timeline_squash_done_ = timeline_;
291
292   for (DrmHwcLayer *layer : pre_comp_layers) {
293     if (!layer->release_fence)
294       continue;
295     int ret = layer->release_fence.Set(CreateNextTimelineFence());
296     if (ret < 0)
297       return ret;
298   }
299   timeline_pre_comp_done_ = timeline_;
300
301   for (DrmHwcLayer *layer : comp_layers) {
302     if (!layer->release_fence)
303       continue;
304     int ret = layer->release_fence.Set(CreateNextTimelineFence());
305     if (ret < 0)
306       return ret;
307   }
308
309   return 0;
310 }
311
312 int DrmDisplayComposition::Plan(SquashState *squash,
313                                 std::vector<DrmPlane *> *primary_planes,
314                                 std::vector<DrmPlane *> *overlay_planes) {
315   if (type_ != DRM_COMPOSITION_TYPE_FRAME)
316     return 0;
317
318   size_t planes_can_use =
319       CountUsablePlanes(crtc_, primary_planes, overlay_planes);
320   if (planes_can_use == 0) {
321     ALOGE("Display %d has no usable planes", crtc_->display());
322     return -ENODEV;
323   }
324
325   bool use_squash_framebuffer = false;
326   // Used to determine which layers were entirely squashed
327   std::vector<int> layer_squash_area(layers_.size(), 0);
328   // Used to avoid rerendering regions that were squashed
329   std::vector<DrmHwcRect<int>> exclude_rects;
330   if (squash != NULL && planes_can_use >= 3) {
331     if (geometry_changed_) {
332       squash->Init(layers_.data(), layers_.size());
333     } else {
334       std::vector<bool> changed_regions;
335       squash->GenerateHistory(layers_.data(), layers_.size(), changed_regions);
336
337       std::vector<bool> stable_regions;
338       squash->StableRegionsWithMarginalHistory(changed_regions, stable_regions);
339
340       // Only if SOME region is stable
341       use_squash_framebuffer =
342           std::find(stable_regions.begin(), stable_regions.end(), true) !=
343           stable_regions.end();
344
345       squash->RecordHistory(layers_.data(), layers_.size(), changed_regions);
346
347       // Changes in which regions are squashed triggers a rerender via
348       // squash_regions.
349       bool render_squash = squash->RecordAndCompareSquashed(stable_regions);
350
351       for (size_t region_index = 0; region_index < stable_regions.size();
352            region_index++) {
353         const SquashState::Region &region = squash->regions()[region_index];
354         if (!stable_regions[region_index])
355           continue;
356
357         exclude_rects.emplace_back(region.rect);
358
359         if (render_squash) {
360           squash_regions_.emplace_back();
361           squash_regions_.back().frame = region.rect;
362         }
363
364         int frame_area = region.rect.area();
365         // Source layers are sorted front to back i.e. top layer has lowest
366         // index.
367         for (size_t layer_index = layers_.size();
368              layer_index-- > 0;  // Yes, I double checked this
369              /* See condition */) {
370           if (!region.layer_refs[layer_index])
371             continue;
372           layer_squash_area[layer_index] += frame_area;
373           if (render_squash)
374             squash_regions_.back().source_layers.push_back(layer_index);
375         }
376       }
377     }
378   }
379
380   // All protected layers get first usage of planes
381   std::vector<size_t> layers_remaining;
382   std::vector<size_t> protected_layers;
383   for (size_t layer_index = 0; layer_index < layers_.size(); layer_index++) {
384     if (!layers_[layer_index].protected_usage() || planes_can_use == 0) {
385       layers_remaining.push_back(layer_index);
386       continue;
387     }
388     protected_layers.push_back(layer_index);
389     planes_can_use--;
390   }
391
392   if (planes_can_use == 0 && layers_remaining.size() > 0) {
393     for(auto i : protected_layers)
394       EmplaceCompositionPlane(i, primary_planes, overlay_planes);
395
396     ALOGE("Protected layers consumed all hardware planes");
397     return CreateAndAssignReleaseFences();
398   }
399
400   std::vector<size_t> layers_remaining_if_squash;
401   for (size_t layer_index : layers_remaining) {
402     if (layer_squash_area[layer_index] <
403         layers_[layer_index].display_frame.area())
404       layers_remaining_if_squash.push_back(layer_index);
405   }
406
407   if (use_squash_framebuffer) {
408     if (planes_can_use > 1 || layers_remaining_if_squash.size() == 0) {
409       layers_remaining = std::move(layers_remaining_if_squash);
410       planes_can_use--;  // Reserve plane for squashing
411     } else {
412       use_squash_framebuffer = false;  // The squash buffer is still rendered
413     }
414   }
415
416   if (layers_remaining.size() > planes_can_use)
417     planes_can_use--;  // Reserve one for pre-compositing
418
419   // Whatever planes that are not reserved get assigned a layer
420   size_t last_hw_comp_layer = 0;
421   size_t protected_idx = 0;
422   while(last_hw_comp_layer < layers_remaining.size() && planes_can_use > 0) {
423     size_t idx = layers_remaining[last_hw_comp_layer];
424
425     // Put the protected layers into the composition at the right place. We've
426     // already reserved them by decrementing planes_can_use, so no need to do
427     // that again.
428     if (protected_idx < protected_layers.size() &&
429         idx > protected_layers[protected_idx]) {
430         EmplaceCompositionPlane(protected_layers[protected_idx], primary_planes,
431                                 overlay_planes);
432         protected_idx++;
433         continue;
434     }
435
436     EmplaceCompositionPlane(layers_remaining[last_hw_comp_layer],
437                             primary_planes, overlay_planes);
438     last_hw_comp_layer++;
439     planes_can_use--;
440   }
441
442   layers_remaining.erase(layers_remaining.begin(),
443                          layers_remaining.begin() + last_hw_comp_layer);
444
445   // Enqueue the rest of the protected layers (if any) between the hw composited
446   // overlay layers and the squash/precomp layers.
447   for(int i = protected_idx; i < protected_layers.size(); ++i)
448     EmplaceCompositionPlane(protected_layers[i], primary_planes,
449                             overlay_planes);
450
451   if (layers_remaining.size() > 0) {
452     EmplaceCompositionPlane(DrmCompositionPlane::kSourcePreComp, primary_planes,
453                             overlay_planes);
454     SeparateLayers(layers_.data(), layers_remaining.data(),
455                    layers_remaining.size(), protected_layers.data(),
456                    protected_layers.size(), exclude_rects.data(),
457                    exclude_rects.size(), pre_comp_regions_);
458   }
459
460   if (use_squash_framebuffer) {
461     EmplaceCompositionPlane(DrmCompositionPlane::kSourceSquash, primary_planes,
462                             overlay_planes);
463   }
464
465   return CreateAndAssignReleaseFences();
466 }
467
468 static const char *DrmCompositionTypeToString(DrmCompositionType type) {
469   switch (type) {
470     case DRM_COMPOSITION_TYPE_EMPTY:
471       return "EMPTY";
472     case DRM_COMPOSITION_TYPE_FRAME:
473       return "FRAME";
474     case DRM_COMPOSITION_TYPE_DPMS:
475       return "DPMS";
476     case DRM_COMPOSITION_TYPE_MODESET:
477       return "MODESET";
478     default:
479       return "<invalid>";
480   }
481 }
482
483 static const char *DPMSModeToString(int dpms_mode) {
484   switch (dpms_mode) {
485     case DRM_MODE_DPMS_ON:
486       return "ON";
487     case DRM_MODE_DPMS_OFF:
488       return "OFF";
489     default:
490       return "<invalid>";
491   }
492 }
493
494 static void DumpBuffer(const DrmHwcBuffer &buffer, std::ostringstream *out) {
495   if (!buffer) {
496     *out << "buffer=<invalid>";
497     return;
498   }
499
500   *out << "buffer[w/h/format]=";
501   *out << buffer->width << "/" << buffer->height << "/" << buffer->format;
502 }
503
504 static void DumpTransform(uint32_t transform, std::ostringstream *out) {
505   *out << "[";
506
507   if (transform == 0)
508     *out << "IDENTITY";
509
510   bool separator = false;
511   if (transform & DrmHwcTransform::kFlipH) {
512     *out << "FLIPH";
513     separator = true;
514   }
515   if (transform & DrmHwcTransform::kFlipV) {
516     if (separator)
517       *out << "|";
518     *out << "FLIPV";
519     separator = true;
520   }
521   if (transform & DrmHwcTransform::kRotate90) {
522     if (separator)
523       *out << "|";
524     *out << "ROTATE90";
525     separator = true;
526   }
527   if (transform & DrmHwcTransform::kRotate180) {
528     if (separator)
529       *out << "|";
530     *out << "ROTATE180";
531     separator = true;
532   }
533   if (transform & DrmHwcTransform::kRotate270) {
534     if (separator)
535       *out << "|";
536     *out << "ROTATE270";
537     separator = true;
538   }
539
540   uint32_t valid_bits = DrmHwcTransform::kFlipH | DrmHwcTransform::kFlipH |
541                         DrmHwcTransform::kRotate90 |
542                         DrmHwcTransform::kRotate180 |
543                         DrmHwcTransform::kRotate270;
544   if (transform & ~valid_bits) {
545     if (separator)
546       *out << "|";
547     *out << "INVALID";
548   }
549   *out << "]";
550 }
551
552 static const char *BlendingToString(DrmHwcBlending blending) {
553   switch (blending) {
554     case DrmHwcBlending::kNone:
555       return "NONE";
556     case DrmHwcBlending::kPreMult:
557       return "PREMULT";
558     case DrmHwcBlending::kCoverage:
559       return "COVERAGE";
560     default:
561       return "<invalid>";
562   }
563 }
564
565 static void DumpRegion(const DrmCompositionRegion &region,
566                        std::ostringstream *out) {
567   *out << "frame";
568   region.frame.Dump(out);
569   *out << " source_layers=(";
570
571   const std::vector<size_t> &source_layers = region.source_layers;
572   for (size_t i = 0; i < source_layers.size(); i++) {
573     *out << source_layers[i];
574     if (i < source_layers.size() - 1) {
575       *out << " ";
576     }
577   }
578
579   *out << ")";
580 }
581
582 void DrmDisplayComposition::Dump(std::ostringstream *out) const {
583   *out << "----DrmDisplayComposition"
584        << " crtc=" << (crtc_ ? crtc_->id() : -1)
585        << " type=" << DrmCompositionTypeToString(type_);
586
587   switch (type_) {
588     case DRM_COMPOSITION_TYPE_DPMS:
589       *out << " dpms_mode=" << DPMSModeToString(dpms_mode_);
590       break;
591     case DRM_COMPOSITION_TYPE_MODESET:
592       *out << " display_mode=" << display_mode_.h_display() << "x"
593            << display_mode_.v_display();
594       break;
595     default:
596       break;
597   }
598
599   *out << " timeline[current/squash/pre-comp/done]=" << timeline_current_ << "/"
600        << timeline_squash_done_ << "/" << timeline_pre_comp_done_ << "/"
601        << timeline_ << "\n";
602
603   *out << "    Layers: count=" << layers_.size() << "\n";
604   for (size_t i = 0; i < layers_.size(); i++) {
605     const DrmHwcLayer &layer = layers_[i];
606     *out << "      [" << i << "] ";
607
608     DumpBuffer(layer.buffer, out);
609
610     if (layer.protected_usage())
611       *out << " protected";
612
613     *out << " transform=";
614     DumpTransform(layer.transform, out);
615     *out << " blending[a=" << (int)layer.alpha
616          << "]=" << BlendingToString(layer.blending) << " source_crop";
617     layer.source_crop.Dump(out);
618     *out << " display_frame";
619     layer.display_frame.Dump(out);
620
621     *out << "\n";
622   }
623
624   *out << "    Planes: count=" << composition_planes_.size() << "\n";
625   for (size_t i = 0; i < composition_planes_.size(); i++) {
626     const DrmCompositionPlane &comp_plane = composition_planes_[i];
627     *out << "      [" << i << "]"
628          << " plane=" << (comp_plane.plane ? comp_plane.plane->id() : -1)
629          << " source_layer=";
630     if (comp_plane.source_layer <= DrmCompositionPlane::kSourceLayerMax) {
631       *out << comp_plane.source_layer;
632     } else {
633       switch (comp_plane.source_layer) {
634         case DrmCompositionPlane::kSourceNone:
635           *out << "NONE";
636           break;
637         case DrmCompositionPlane::kSourcePreComp:
638           *out << "PRECOMP";
639           break;
640         case DrmCompositionPlane::kSourceSquash:
641           *out << "SQUASH";
642           break;
643         default:
644           *out << "<invalid>";
645           break;
646       }
647     }
648
649     *out << "\n";
650   }
651
652   *out << "    Squash Regions: count=" << squash_regions_.size() << "\n";
653   for (size_t i = 0; i < squash_regions_.size(); i++) {
654     *out << "      [" << i << "] ";
655     DumpRegion(squash_regions_[i], out);
656     *out << "\n";
657   }
658
659   *out << "    Pre-Comp Regions: count=" << pre_comp_regions_.size() << "\n";
660   for (size_t i = 0; i < pre_comp_regions_.size(); i++) {
661     *out << "      [" << i << "] ";
662     DumpRegion(pre_comp_regions_[i], out);
663     *out << "\n";
664   }
665 }
666 }